on_thread hook for libafl

This commit is contained in:
Andrea Fioraldi 2022-02-18 10:31:21 +01:00
parent e2f6827b05
commit 08412ed443

View File

@ -6565,6 +6565,13 @@ typedef struct {
sigset_t sigmask; sigset_t sigmask;
} new_thread_info; } new_thread_info;
//// --- Begin LibAFL code ---
extern __thread CPUArchState *libafl_qemu_env;
void (*libafl_on_thread_hook)(int);
//// --- End LibAFL code ---
static void *clone_func(void *arg) static void *clone_func(void *arg)
{ {
new_thread_info *info = arg; new_thread_info *info = arg;
@ -6594,7 +6601,19 @@ static void *clone_func(void *arg)
/* Wait until the parent has finished initializing the tls state. */ /* Wait until the parent has finished initializing the tls state. */
pthread_mutex_lock(&clone_lock); pthread_mutex_lock(&clone_lock);
pthread_mutex_unlock(&clone_lock); pthread_mutex_unlock(&clone_lock);
cpu_loop(env);
//// --- Begin LibAFL code ---
libafl_qemu_env = env;
if (libafl_on_thread_hook) {
libafl_on_thread_hook(info->tid);
} else {
cpu_loop(env);
}
//// --- End LibAFL code ---
// cpu_loop(env);
/* never exits */ /* never exits */
return NULL; return NULL;
} }