Skip to content

Commit a6758d1

Browse files
less collisions with a robust pc hash
1 parent d73b033 commit a6758d1

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

accel/tcg/translate-all.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
#include "qemuafl/common.h"
6767
#include "tcg/tcg-op.h"
6868

69+
#include <math.h>
70+
6971
__thread int cur_block_is_good;
7072

7173
void HELPER(afl_maybe_log)(target_ulong cur_loc) {
@@ -74,10 +76,19 @@ void HELPER(afl_maybe_log)(target_ulong cur_loc) {
7476

7577
INC_AFL_AREA(afl_idx);
7678

79+
// afl_prev_loc = ((cur_loc & (MAP_SIZE - 1) >> 1)) |
80+
// ((cur_loc & 1) << ((int)ceil(log2(MAP_SIZE)) -1));
7781
afl_prev_loc = cur_loc >> 1;
7882

7983
}
8084

85+
static target_ulong pc_hash(target_ulong x) {
86+
x = ((x >> 16) ^ x) * 0x45d9f3b;
87+
x = ((x >> 16) ^ x) * 0x45d9f3b;
88+
x = (x >> 16) ^ x;
89+
return x;
90+
}
91+
8192
/* Generates TCG code for AFL's tracing instrumentation. */
8293
static void afl_gen_trace(target_ulong cur_loc) {
8394

@@ -93,8 +104,9 @@ static void afl_gen_trace(target_ulong cur_loc) {
93104
concern. Phew. But instruction addresses may be aligned. Let's mangle
94105
the value to get something quasi-uniform. */
95106

96-
cur_loc = (cur_loc >> 4) ^ (cur_loc << 8);
97-
cur_loc &= MAP_SIZE - 1;
107+
// cur_loc = (cur_loc >> 4) ^ (cur_loc << 8);
108+
// cur_loc &= MAP_SIZE - 1;
109+
cur_loc = pc_hash(cur_loc) & (MAP_SIZE -1);
98110

99111
/* Implement probabilistic instrumentation by looking at scrambled block
100112
address. This keeps the instrumented locations stable across runs. */

linux-user/syscall.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8475,7 +8475,7 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
84758475
#endif
84768476
case TARGET_NR_execve:
84778477
{
8478-
char **argp, **envp;
8478+
char **argp = NULL, **envp = NULL;
84798479
int argc, envc;
84808480
abi_ulong gp;
84818481
abi_ulong guest_argp;

0 commit comments

Comments
 (0)