]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/syscall_shim: Put bin syscall dbg handler in `syscall_entertab`
authorSergiu Moga <sergiu@unikraft.io>
Tue, 28 Jan 2025 19:00:58 +0000 (21:00 +0200)
committerUnikraft Bot <monkey@unikraft.io>
Fri, 14 Feb 2025 17:47:25 +0000 (17:47 +0000)
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 <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1277

lib/syscall_shim/uk_syscall_binary.c

index 30baecde7879840ded01870978a594835e9b2ee4..dab38c7e301cabd6fc8d7674d8ef034ec1b7b7fa 100644 (file)
@@ -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)
 {