Skip to content

Commit c36f7a6

Browse files
cotastsquad
authored andcommitted
*-user: plugin syscalls
To avoid too much duplication add a wrapper that the existing trace and the new plugin calls can live in. We could move the -strace code here as well but that is left for a future series as the code is subtly different between the bsd and linux. Signed-off-by: Emilio G. Cota <[email protected]> Reviewed-by: Richard Henderson <[email protected]> [AJB: wrap in syscall-trace.h, expand commit msg] Signed-off-by: Alex Bennée <[email protected]>
1 parent 8634d77 commit c36f7a6

File tree

3 files changed

+59
-9
lines changed

3 files changed

+59
-9
lines changed

bsd-user/syscall.c

+15-6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "qemu.h"
2828
#include "qemu-common.h"
29+
#include "user/syscall-trace.h"
2930

3031
//#define DEBUG
3132

@@ -322,7 +323,8 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
322323
#ifdef DEBUG
323324
gemu_log("freebsd syscall %d\n", num);
324325
#endif
325-
trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
326+
record_syscall_start(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0);
327+
326328
if(do_strace)
327329
print_freebsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
328330

@@ -403,7 +405,8 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
403405
#endif
404406
if (do_strace)
405407
print_freebsd_syscall_ret(num, ret);
406-
trace_guest_user_syscall_ret(cpu, num, ret);
408+
409+
record_syscall_return(cpu, num, ret);
407410
return ret;
408411
efault:
409412
ret = -TARGET_EFAULT;
@@ -421,7 +424,9 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1,
421424
#ifdef DEBUG
422425
gemu_log("netbsd syscall %d\n", num);
423426
#endif
424-
trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0);
427+
428+
record_syscall_start(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0);
429+
425430
if(do_strace)
426431
print_netbsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
427432

@@ -479,7 +484,8 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1,
479484
#endif
480485
if (do_strace)
481486
print_netbsd_syscall_ret(num, ret);
482-
trace_guest_user_syscall_ret(cpu, num, ret);
487+
488+
record_syscall_return(cpu, num, ret);
483489
return ret;
484490
efault:
485491
ret = -TARGET_EFAULT;
@@ -497,7 +503,9 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1,
497503
#ifdef DEBUG
498504
gemu_log("openbsd syscall %d\n", num);
499505
#endif
500-
trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0);
506+
507+
record_syscall_start(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0);
508+
501509
if(do_strace)
502510
print_openbsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
503511

@@ -555,7 +563,8 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1,
555563
#endif
556564
if (do_strace)
557565
print_openbsd_syscall_ret(num, ret);
558-
trace_guest_user_syscall_ret(cpu, num, ret);
566+
567+
record_syscall_return(cpu, num, ret);
559568
return ret;
560569
efault:
561570
ret = -TARGET_EFAULT;

include/user/syscall-trace.h

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Common System Call Tracing Wrappers for *-user
3+
*
4+
* Copyright (c) 2019 Linaro
5+
* Written by Alex Bennée <[email protected]>
6+
*
7+
* SPDX-License-Identifier: GPL-2.0-or-later
8+
*/
9+
10+
#ifndef _SYSCALL_TRACE_H_
11+
#define _SYSCALL_TRACE_H_
12+
13+
/*
14+
* These helpers just provide a common place for the various
15+
* subsystems that want to track syscalls to put their hooks in. We
16+
* could potentially unify the -strace code here as well.
17+
*/
18+
19+
static inline void record_syscall_start(void *cpu, int num,
20+
abi_long arg1, abi_long arg2,
21+
abi_long arg3, abi_long arg4,
22+
abi_long arg5, abi_long arg6,
23+
abi_long arg7, abi_long arg8)
24+
{
25+
trace_guest_user_syscall(cpu, num,
26+
arg1, arg2, arg3, arg4,
27+
arg5, arg6, arg7, arg8);
28+
qemu_plugin_vcpu_syscall(cpu, num,
29+
arg1, arg2, arg3, arg4,
30+
arg5, arg6, arg7, arg8);
31+
}
32+
33+
static inline void record_syscall_return(void *cpu, int num, abi_long ret)
34+
{
35+
trace_guest_user_syscall_ret(cpu, num, ret);
36+
qemu_plugin_vcpu_syscall_ret(cpu, num, ret);
37+
}
38+
39+
40+
#endif /* _SYSCALL_TRACE_H_ */

linux-user/syscall.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112

113113
#include "qemu.h"
114114
#include "qemu/guest-random.h"
115+
#include "user/syscall-trace.h"
115116
#include "qapi/error.h"
116117
#include "fd-trans.h"
117118

@@ -11984,8 +11985,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
1198411985
}
1198511986
#endif
1198611987

11987-
trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4,
11988-
arg5, arg6, arg7, arg8);
11988+
record_syscall_start(cpu, num, arg1,
11989+
arg2, arg3, arg4, arg5, arg6, arg7, arg8);
1198911990

1199011991
if (unlikely(do_strace)) {
1199111992
print_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
@@ -11997,6 +11998,6 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
1199711998
arg5, arg6, arg7, arg8);
1199811999
}
1199912000

12000-
trace_guest_user_syscall_ret(cpu, num, ret);
12001+
record_syscall_return(cpu, num, ret);
1200112002
return ret;
1200212003
}

0 commit comments

Comments
 (0)