From 08412ed443a3b51467bc9b5aabe28d7da1172ec4 Mon Sep 17 00:00:00 2001 From: Andrea Fioraldi Date: Fri, 18 Feb 2022 10:31:21 +0100 Subject: [PATCH] on_thread hook for libafl --- linux-user/syscall.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index f0cc517b79..6f07769587 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6565,6 +6565,13 @@ typedef struct { sigset_t sigmask; } 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) { 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. */ pthread_mutex_lock(&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 */ return NULL; }