From bb8843a78152fece454b86173250d4a6ff8263df Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 25 Jun 2023 08:26:08 +0200 Subject: Implement formatting for some system calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- print.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/print.c b/print.c index 9ca5e8d..463e95b 100644 --- a/print.c +++ b/print.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -14,12 +15,22 @@ #include #include #include +#include #include #if defined(__linux__) # ifndef CLONE_NEWTIME # define CLONE_NEWTIME 0x00000080 # endif +# ifndef SS_ONSTACK +# define SS_ONSTACK 1 +# endif +# ifndef SS_DISABLE +# define SS_DISABLE 2 +# endif +# ifndef SS_AUTODISARM +# define SS_AUTODISARM (1U << 31) +# endif #endif @@ -37,6 +48,12 @@ char *p = buf;\ unsigned long long int flags = proc->args[arg_index] +#define FLAGS_BEGIN_VALUE(VALUE)\ + do {\ + char buf[1024] = {0};\ + char *p = buf;\ + unsigned long long int flags = (VALUE) + #define FLAG(FLAG)\ do {\ _Static_assert((FLAG) != 0, #FLAG" is 0 and must not be included");\ @@ -515,6 +532,34 @@ print_pkey_access_rights(struct process *proc, size_t arg_index) FLAGS_END; } +static void +print_eventfd2_flags(struct process *proc, size_t arg_index) +{ + FLAGS_BEGIN; + FLAG(EFD_CLOEXEC); + FLAG(EFD_NONBLOCK); + FLAG(EFD_SEMAPHORE); + FLAGS_END; +} + +static void +print_stack(struct process *proc, size_t arg_index) +{ + stack_t stack; + const char *err; + if (get_struct(proc->pid, proc->args[arg_index], &stack, sizeof(stack), &err)) { + tprintf(proc, "%s", err); + return; + } + tprintf(proc, "{.ss_sp = %p, .ss_flags = ", stack.ss_sp); + FLAGS_BEGIN_VALUE(stack.ss_flags); + FLAG(SS_ONSTACK); + FLAG(SS_DISABLE); + FLAG(SS_AUTODISARM); + FLAGS_END; + tprintf(proc, ", .ss_size = %zu}", stack.ss_size); +} + static void printf_systemcall(struct process *proc, const char *scall, const char *fmt, ...) @@ -745,7 +790,7 @@ print_systemcall(struct process *proc) GENERIC_HANDLER(clone3); SIMPLE(close, "i", Int); GENERIC_HANDLER(connect); - GENERIC_HANDLER(copy_file_range); + SIMPLE(copy_file_range, "i&llii&llilux", Long); SIMPLE(creat, "so", Int); SIMPLE(create_module, "slu", Ptr); FORMATTERS(delete_module, "s1", Int, print_delete_module_flags); @@ -759,8 +804,8 @@ print_systemcall(struct process *proc) GENERIC_HANDLER(epoll_pwait); GENERIC_HANDLER(epoll_wait); GENERIC_HANDLER(epoll_wait_old); - GENERIC_HANDLER(eventfd); - GENERIC_HANDLER(eventfd2); + SIMPLE(eventfd, "i", Int); + FORMATTERS(eventfd2, "i1", Int, print_eventfd2_flags); GENERIC_HANDLER(execve); GENERIC_HANDLER(execveat); SIMPLE(exit, "i", Int); @@ -809,7 +854,7 @@ print_systemcall(struct process *proc) GENERIC_HANDLER(getitimer); GENERIC_HANDLER(getpeername); SIMPLE(getpgid, "i", Int); - GENERIC_HANDLER(getpgrp); + SIMPLE(getpgrp, "", Int); SIMPLE(getpid, "", Int); UNIMPLEMENTED(getpmsg); SIMPLE(getppid, "", Int); @@ -1010,7 +1055,7 @@ print_systemcall(struct process *proc) GENERIC_HANDLER(shmdt); GENERIC_HANDLER(shmget); FORMATTERS(shutdown, "i1", Int, print_shutdown_flag); - GENERIC_HANDLER(sigaltstack); + FORMATTERS(sigaltstack, "1>1", Int, print_stack); GENERIC_HANDLER(signalfd); GENERIC_HANDLER(signalfd4); SIMPLE(socket, "iii", Int); /* TODO flags */ -- cgit v1.2.3-70-g09d2