From: Sergiu Moga Date: Tue, 28 Jan 2025 19:00:58 +0000 (+0200) Subject: lib/syscall_shim: Put bin syscall dbg handler in `syscall_entertab` X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=077dff1f39fb2fa86217c5cc0e4db8971cdd6e10;p=unikraft%2Funikraft.git lib/syscall_shim: Put bin syscall dbg handler in `syscall_entertab` Move the debug handler printing to a `syscall_entertab` handler. Since we want this to be printed on binary system calls exit only, make sure to check for it. Lastly, add an assertion for a nested depth of 1. It should be impossible that this would be different from 1 as it would either mean a kernel internal system call invoked the binary handler somehow or the TLS counter nesting variable is corrupted. Signed-off-by: Sergiu Moga Approved-by: Michalis Pappas Reviewed-by: Michalis Pappas GitHub-Closes: #1277 --- diff --git a/lib/syscall_shim/uk_syscall_binary.c b/lib/syscall_shim/uk_syscall_binary.c index 30baecde7..dab38c7e3 100644 --- a/lib/syscall_shim/uk_syscall_binary.c +++ b/lib/syscall_shim/uk_syscall_binary.c @@ -101,16 +101,6 @@ void ukplat_syscall_handler(struct uk_syscall_ctx *usc) UK_ASSERT(t->uktlsp == ukarch_auxspcb_get_uktlsp(auxspcb)); #endif /* CONFIG_LIBSYSCALL_SHIM_HANDLER_ULTLS */ -#if CONFIG_LIBSYSCALL_SHIM_DEBUG_HANDLER - _uk_printd(uk_libid_self(), __STR_BASENAME__, __LINE__, - "Binary system call request \"%s\" (%lu) at ip:%p (arg0=0x%lx, arg1=0x%lx, ...)\n", - uk_syscall_name(execenv->regs.__syscall_rsyscall), - execenv->regs.__syscall_rsyscall, - (void *)execenv->regs.__syscall_rip, - execenv->regs.__syscall_rarg0, - execenv->regs.__syscall_rarg1); -#endif /* CONFIG_LIBSYSCALL_SHIM_DEBUG_HANDLER */ - uk_syscall_nested_depth++; uk_syscall_enter_ctx_init(&enter_ctx, execenv, uk_syscall_nested_depth, @@ -130,6 +120,30 @@ void ukplat_syscall_handler(struct uk_syscall_ctx *usc) #endif /* CONFIG_LIBSYSCALL_SHIM_HANDLER_ULTLS */ } +#if CONFIG_LIBSYSCALL_SHIM_DEBUG_HANDLER +static void binary_syscall_debug_handler(struct uk_syscall_enter_ctx *enter_ctx) +{ + struct ukarch_execenv *execenv; + + UK_ASSERT(enter_ctx); + + if (!(enter_ctx->flags & UK_SYSCALL_ENTER_CTX_BINARY_SYSCALL)) + return; + + execenv = enter_ctx->execenv; + + _uk_printd(uk_libid_self(), __STR_BASENAME__, __LINE__, + "Binary system call request \"%s\" (%lu) at ip:%p (arg0=0x%lx, arg1=0x%lx, ...)\n", + uk_syscall_name(execenv->regs.__syscall_rsyscall), + execenv->regs.__syscall_rsyscall, + (void *)execenv->regs.__syscall_rip, + execenv->regs.__syscall_rarg0, + execenv->regs.__syscall_rarg1); +} + +uk_syscall_entertab_prio(binary_syscall_debug_handler, UK_PRIO_EARLIEST); +#endif /* CONFIG_LIBSYSCALL_SHIM_DEBUG_HANDLER */ + #if CONFIG_LIBSYSCALL_SHIM_STRACE static void binary_syscall_strace(struct uk_syscall_exit_ctx *exit_ctx) {