Skip to content

Commit a120c3f

Browse files
Merge pull request #30 from 6E006B/master
Fix PPC64 usage of afl_entry_point and TARGET_LONG_BITS
2 parents ce65a73 + 6a819f3 commit a120c3f

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

linux-user/elfload.c

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,22 +2784,6 @@ static void load_elf_image(const char *image_name, int image_fd,
27842784
info->brk = 0;
27852785
info->elf_flags = ehdr->e_flags;
27862786

2787-
if (!afl_entry_point) {
2788-
char *ptr;
2789-
if ((ptr = getenv("AFL_ENTRYPOINT")) != NULL) {
2790-
afl_entry_point = strtoul(ptr, NULL, 16);
2791-
} else {
2792-
afl_entry_point = info->entry;
2793-
}
2794-
#ifdef TARGET_ARM
2795-
/* The least significant bit indicates Thumb mode. */
2796-
afl_entry_point = afl_entry_point & ~(target_ulong)1;
2797-
#endif
2798-
}
2799-
if (getenv("AFL_DEBUG") != NULL)
2800-
fprintf(stderr, "AFL forkserver entrypoint: 0x%lx\n",
2801-
(unsigned long)afl_entry_point);
2802-
28032787
prot_exec = PROT_EXEC;
28042788
#ifdef TARGET_AARCH64
28052789
/*
@@ -2928,6 +2912,38 @@ static void load_elf_image(const char *image_name, int image_fd,
29282912
load_symbols(ehdr, image_fd, load_bias);
29292913
}
29302914

2915+
if (!afl_entry_point) {
2916+
char *ptr;
2917+
if ((ptr = getenv("AFL_ENTRYPOINT")) != NULL) {
2918+
afl_entry_point = strtoul(ptr, NULL, 16);
2919+
} else {
2920+
// On PowerPC64 the entry point is the _function descriptor_
2921+
// of the entry function. For AFL to properly initialize,
2922+
// afl_entry_point needs to be set to the actual first instruction
2923+
// as opposed executed by the target program. This as opposed to
2924+
// where the function's descriptor sits in memory.
2925+
// copied from PPC init_thread
2926+
#if defined(TARGET_PPC64) && !defined(TARGET_ABI32)
2927+
if (get_ppc64_abi(info) < 2) {
2928+
uint64_t val;
2929+
get_user_u64(val, info->entry);
2930+
afl_entry_point = val + info->load_bias;
2931+
} else {
2932+
afl_entry_point = info->entry;
2933+
}
2934+
#else
2935+
afl_entry_point = info->entry;
2936+
#endif
2937+
}
2938+
#ifdef TARGET_ARM
2939+
/* The least significant bit indicates Thumb mode. */
2940+
afl_entry_point = afl_entry_point & ~(target_ulong)1;
2941+
#endif
2942+
}
2943+
if (getenv("AFL_DEBUG") != NULL)
2944+
fprintf(stderr, "AFL forkserver entrypoint: 0x%lx\n",
2945+
(unsigned long)afl_entry_point);
2946+
29312947
mmap_unlock();
29322948

29332949
close(image_fd);
@@ -3188,22 +3204,6 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)
31883204
change some of these later */
31893205
bprm->p = setup_arg_pages(bprm, info);
31903206

3191-
// On PowerPC64 the entry point is the _function descriptor_
3192-
// of the entry function. For AFL to properly initialize,
3193-
// afl_entry_point needs to be set to the actual first instruction
3194-
// as opposed executed by the target program. This as opposed to
3195-
// where the function's descriptor sits in memory.
3196-
// copied from PPC init_thread
3197-
#if defined(TARGET_PPC64) && !defined(TARGET_ABI32)
3198-
if (get_ppc64_abi(infop) < 2) {
3199-
uint64_t val;
3200-
get_user_u64(val, infop->entry + 8);
3201-
_regs->gpr[2] = val + infop->load_bias;
3202-
get_user_u64(val, infop->entry);
3203-
infop->entry = val + infop->load_bias;
3204-
}
3205-
#endif
3206-
32073207
scratch = g_new0(char, TARGET_PAGE_SIZE);
32083208
if (STACK_GROWS_DOWN) {
32093209
bprm->p = copy_elf_strings(1, &bprm->filename, scratch,

qemuafl/api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include <stdint.h>
55

6-
#if defined(TARGET_MIPS64) || defined(TARGET_AARCH64) || defined(TARGET_X86_64)
6+
#if defined(TARGET_MIPS64) || defined(TARGET_AARCH64) || defined(TARGET_X86_64) || defined(TARGET_PPC64)
77
# define TARGET_LONG_BITS 64
88
#else
99
# define TARGET_LONG_BITS 32

0 commit comments

Comments
 (0)