@@ -324,6 +324,8 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
#ifdef DEBUG
gemu_log("freebsd syscall %d\n", num);
#endif
+ instr_guest_user_syscall(cpu, num,
+ arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
if(do_strace)
print_freebsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
@@ -423,6 +425,8 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1,
#ifdef DEBUG
gemu_log("netbsd syscall %d\n", num);
#endif
+ instr_guest_user_syscall(cpu, num,
+ arg1, arg2, arg3, arg4, arg5, arg6, 0, 0);
trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0);
if(do_strace)
print_netbsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
@@ -499,6 +503,8 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1,
#ifdef DEBUG
gemu_log("openbsd syscall %d\n", num);
#endif
+ instr_guest_user_syscall(cpu, num,
+ arg1, arg2, arg3, arg4, arg5, arg6, 0, 0);
trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0);
if(do_strace)
print_openbsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
@@ -192,3 +192,21 @@ SYM_PUBLIC void qi_event_set_guest_mem_before_exec(
ERROR_IF(!tcg_enabled(), "called without TCG");
instr_set_event(guest_mem_before_exec, fn);
}
+
+
+void (*instr_event__guest_user_syscall)(
+ QICPU vcpu, uint64_t num, uint64_t arg1, uint64_t arg2, uint64_t arg3,
+ uint64_t arg4, uint64_t arg5, uint64_t arg6, uint64_t arg7, uint64_t arg8);
+
+SYM_PUBLIC void qi_event_set_guest_user_syscall(
+ void (*fn)(QICPU vcpu, uint64_t num, uint64_t arg1, uint64_t arg2,
+ uint64_t arg3, uint64_t arg4, uint64_t arg5, uint64_t arg6,
+ uint64_t arg7, uint64_t arg8))
+{
+ ERROR_IF(!instr_get_state(), "called outside instrumentation");
+ ERROR_IF(!tcg_enabled(), "called without TCG");
+#if !defined(CONFIG_USER_ONLY)
+ ERROR_IF(true, "called in full-system mode");
+#endif
+ instr_set_event(guest_user_syscall, fn);
+}
@@ -68,6 +68,13 @@ extern void (*instr_event__guest_mem_before_exec)(
static inline void instr_guest_mem_before_exec(
CPUState *vcpu, uint64_t vaddr, TraceMemInfo info);
+extern void (*instr_event__guest_user_syscall)(
+ QICPU vcpu, uint64_t num, uint64_t arg1, uint64_t arg2, uint64_t arg3,
+ uint64_t arg4, uint64_t arg5, uint64_t arg6, uint64_t arg7, uint64_t arg8);
+static inline void instr_guest_user_syscall(
+ CPUState *vcpu, uint64_t num, uint64_t arg1, uint64_t arg2, uint64_t arg3,
+ uint64_t arg4, uint64_t arg5, uint64_t arg6, uint64_t arg7, uint64_t arg8);
+
#include "instrument/events.inc.h"
@@ -78,3 +78,19 @@ static inline void instr_guest_mem_before_exec(
instr_set_state(INSTR_STATE_DISABLE);
}
}
+
+static inline void instr_guest_user_syscall(
+ CPUState *vcpu, uint64_t num, uint64_t arg1, uint64_t arg2, uint64_t arg3,
+ uint64_t arg4, uint64_t arg5, uint64_t arg6, uint64_t arg7, uint64_t arg8)
+{
+ void (*cb)(QICPU vcpu, uint64_t num, uint64_t arg1, uint64_t arg2,
+ uint64_t arg3, uint64_t arg4, uint64_t arg5, uint64_t arg6,
+ uint64_t arg7, uint64_t arg8)
+ = instr_get_event(guest_user_syscall);
+ if (cb) {
+ instr_set_state(INSTR_STATE_ENABLE);
+ QICPU vcpu_ = instr_cpu_to_qicpu(vcpu);
+ (*cb)(vcpu_, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
+ instr_set_state(INSTR_STATE_DISABLE);
+ }
+}
@@ -164,6 +164,7 @@ InstrUnloadError instr_unload(const char *id)
instr_set_event(guest_cpu_reset, NULL);
instr_set_event(guest_mem_before_trans, NULL);
instr_set_event(guest_mem_before_exec, NULL);
+ instr_set_event(guest_user_syscall, NULL);
instr_cpu_stop_all_end(&info);
cpu_list_unlock();
@@ -142,6 +142,21 @@ void qi_event_gen_guest_mem_before_exec(
void qi_event_set_guest_mem_before_exec(
void (*fn)(QICPU vcpu, uint64_t vaddr, QIMemInfo info));
+/*
+ * Start executing a guest system call in syscall emulation mode.
+ *
+ * @num: System call number.
+ * @arg*: System call argument value.
+ *
+ * Mode: user
+ * Targets: TCG(all)
+ * Time: exec
+ */
+void qi_event_set_guest_user_syscall(
+ void (*fn)(QICPU vcpu, uint64_t num, uint64_t arg1, uint64_t arg2,
+ uint64_t arg3, uint64_t arg4, uint64_t arg5, uint64_t arg6,
+ uint64_t arg7, uint64_t arg8));
+
#ifdef __cplusplus
}
#endif
@@ -7723,6 +7723,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
#ifdef DEBUG
gemu_log("syscall %d", num);
#endif
+ instr_guest_user_syscall(cpu, num,
+ arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
if(do_strace)
print_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
@@ -68,3 +68,6 @@ void helper_instr_guest_mem_before_exec(
void (*instr_event__guest_mem_before_exec)(
QICPU vcpu_trans, QITCGv_cpu vcpu_exec,
QITCGv vaddr, QIMemInfo info);
+void (*instr_event__guest_user_syscall)(
+ QICPU vcpu, uint64_t num, uint64_t arg1, uint64_t arg2, uint64_t arg3,
+ uint64_t arg4, uint64_t arg5, uint64_t arg6, uint64_t arg7, uint64_t arg8);
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu> --- bsd-user/syscall.c | 6 ++++++ instrument/control.c | 18 ++++++++++++++++++ instrument/events.h | 7 +++++++ instrument/events.inc.h | 16 ++++++++++++++++ instrument/load.c | 1 + instrument/qemu-instr/control.h | 15 +++++++++++++++ linux-user/syscall.c | 2 ++ stubs/instrument.c | 3 +++ 8 files changed, 68 insertions(+)