diff mbox series

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

Message ID 20220201111455.52511-17-imp@bsdimp.com (mailing list archive)
State New, archived
Headers show
Series bsd-user: Start upstreaming the system calls. | expand

Commit Message

Warner Losh Feb. 1, 2022, 11:14 a.m. UTC
Add in the tracing and this system call not implemented boilerplate.

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

Comments

Richard Henderson Feb. 1, 2022, 9:31 p.m. UTC | #1
On 2/1/22 22:14, Warner Losh wrote:
> Add in the tracing and this system call not implemented boilerplate.
> 
> Signed-off-by: Warner Losh <imp@bsdimp.com>
> ---
>   bsd-user/freebsd/os-syscall.c | 27 ++++++++++++++++++++++++++-
>   1 file changed, 26 insertions(+), 1 deletion(-)
> 
> diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
> index d49945f0fcc..fcfa6221182 100644
> --- a/bsd-user/freebsd/os-syscall.c
> +++ b/bsd-user/freebsd/os-syscall.c
> @@ -200,7 +200,32 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
>                               abi_long arg5, abi_long arg6, abi_long arg7,
>                               abi_long arg8)
>   {
> -    return 0;
> +    CPUState *cpu = env_cpu(cpu_env);
> +    abi_long 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);
> +    }
> +
> +    switch (num) {
> +    default:
> +        gemu_log("qemu: unsupported syscall: %d\n", num);
> +        ret = -TARGET_ENOSYS;
> +        break;
> +    }
> +
> +#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;
>   }

I think it's simpler to put the logging in a wrapper function, so that one can return from 
the switch rather than be required to break.


r~
diff mbox series

Patch

diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index d49945f0fcc..fcfa6221182 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -200,7 +200,32 @@  abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
                             abi_long arg5, abi_long arg6, abi_long arg7,
                             abi_long arg8)
 {
-    return 0;
+    CPUState *cpu = env_cpu(cpu_env);
+    abi_long 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);
+    }
+
+    switch (num) {
+    default:
+        gemu_log("qemu: unsupported syscall: %d\n", num);
+        ret = -TARGET_ENOSYS;
+        break;
+    }
+
+#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)