diff mbox series

[3/6] bsd-user/freebsd/os-syscall.c: Tracing and error boilerplate

Message ID 20220607201440.41464-4-imp@bsdimp.com
State New
Headers show
Series bsd-user upstreaming: read, write and exit | expand

Commit Message

Warner Losh June 7, 2022, 8:14 p.m. UTC
Add in the tracing and this system call not implemented boilerplate. Do
this by moving the guts of do_freebsd_syscall to freebsd_syscall. Put
the tracing in the wrapper function. Since freebsd_syscall is a
singleton static function, it will almost certainly be inlined. Fix
comments that referred to do_syscall since that was renamed some tie
ago.

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/freebsd/os-syscall.c | 50 ++++++++++++++++++++++++++++++++---
 1 file changed, 46 insertions(+), 4 deletions(-)

Comments

Richard Henderson June 7, 2022, 9:34 p.m. UTC | #1
On 6/7/22 13:14, Warner Losh wrote:
> +static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
> +                                abi_long arg2, abi_long arg3, abi_long arg4,
> +                                abi_long arg5, abi_long arg6, abi_long arg7,
> +                                abi_long arg8)
> +{
> +    abi_long ret;
> +
> +    switch (num) {
> +    default:
> +        gemu_log("qemu: unsupported syscall: %d\n", num);

qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);


> +#ifdef DEBUG
> +    gemu_log("freebsd syscall %d\n", num);
> +#endif

Drop this.  It's redundant with strace.

Otherwise,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~
Warner Losh June 7, 2022, 9:56 p.m. UTC | #2
On Tue, Jun 7, 2022 at 2:34 PM Richard Henderson <
richard.henderson@linaro.org> wrote:

> On 6/7/22 13:14, Warner Losh wrote:
> > +static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
> > +                                abi_long arg2, abi_long arg3, abi_long
> arg4,
> > +                                abi_long arg5, abi_long arg6, abi_long
> arg7,
> > +                                abi_long arg8)
> > +{
> > +    abi_long ret;
> > +
> > +    switch (num) {
> > +    default:
> > +        gemu_log("qemu: unsupported syscall: %d\n", num);
>
> qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);
>

Agreed.


>
> > +#ifdef DEBUG
> > +    gemu_log("freebsd syscall %d\n", num);
> > +#endif
>
> Drop this.  It's redundant with strace.
>

Yea, it was a quick hack in the past that the wrapper function highlighted
nicely..


> Otherwise,
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


Thanks!

Warner
diff mbox series

Patch

diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 510307f29d9..334c573739b 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -201,16 +201,58 @@  void unlock_iovec(struct iovec *vec, abi_ulong target_addr,
 }
 
 /*
- * do_syscall() should always have a single exit point at the end so that
- * actions, such as logging of syscall results, can be performed.  All errnos
- * that do_syscall() returns must be -TARGET_<errcode>.
+ * All errnos that freebsd_syscall() returns must be -TARGET_<errcode>.
+ */
+static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
+                                abi_long arg2, abi_long arg3, abi_long arg4,
+                                abi_long arg5, abi_long arg6, abi_long arg7,
+                                abi_long arg8)
+{
+    abi_long ret;
+
+    switch (num) {
+    default:
+        gemu_log("qemu: unsupported syscall: %d\n", num);
+        ret = -TARGET_ENOSYS;
+        break;
+    }
+
+    return ret;
+}
+
+/*
+ * do_freebsd_syscall() should always have a single exit point at the end so
+ * that actions, such as logging of syscall results, can be performed. This
+ * as a wrapper around freebsd_syscall() so that actually happens. Since
+ * that is a singleton, modern compilers will inline it anyway...
  */
 abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
                             abi_long arg2, abi_long arg3, abi_long arg4,
                             abi_long arg5, abi_long arg6, abi_long arg7,
                             abi_long arg8)
 {
-    return 0;
+    CPUState *cpu = env_cpu(cpu_env);
+    int ret;
+
+#ifdef DEBUG
+    gemu_log("freebsd syscall %d\n", num);
+#endif
+    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);
+    }
+
+    ret = freebsd_syscall(cpu_env, num, arg1, arg2, arg3, arg4, arg5, arg6,
+                          arg7, arg8);
+#ifdef DEBUG
+    gemu_log(" = %ld\n", ret);
+#endif
+    if (do_strace) {
+        print_freebsd_syscall_ret(num, ret);
+    }
+    trace_guest_user_syscall_ret(cpu, num, ret);
+
+    return ret;
 }
 
 void syscall_init(void)