From 534d384e8f7932d6f62d4ef89dc48060d1fd745e Mon Sep 17 00:00:00 2001 From: Marc Rittinghaus Date: Fri, 14 Apr 2023 17:01:15 +0200 Subject: [PATCH] lib/syscall_shim: Add (F|R|W|X)_OK and access This commit adds a definition of the (F|R|W|X)_OK flags and the access syscall Signed-off-by: Marc Rittinghaus Reviewed-by: Razvan Deaconescu Reviewed-by: Cezar Craciunoiu Approved-by: Simon Kuenzer Tested-by: Unikraft CI GitHub-Closes: #836 --- lib/syscall_shim/uk_prsyscall.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/syscall_shim/uk_prsyscall.c b/lib/syscall_shim/uk_prsyscall.c index 657e8ccc7..2b8d80cd6 100644 --- a/lib/syscall_shim/uk_prsyscall.c +++ b/lib/syscall_shim/uk_prsyscall.c @@ -4,6 +4,7 @@ * You may not use this file except in compliance with the License. */ +#define _GNU_SOURCE #include #include @@ -332,6 +333,7 @@ enum param_type { PT_DIRFD, /* File descriptor number of directory */ PT_PID, /* PID number */ PT_OFLAGS, + PT_OKFLAGS, PT_PROTFLAGS, PT_MAPFLAGS, PT_FUTEXOP, @@ -416,6 +418,22 @@ static inline void param_oflags(struct uk_streambuf *sb, int fmtf, int oflags) PR_FLAG_END(sb, fmtf, orig_seek, oflags); } +static inline void param_okflag(struct uk_streambuf *sb, int fmtf, int okflags) +{ + __sz orig_seek = uk_streambuf_seek(sb); + + if (okflags == 0) { + uk_streambuf_shcc(sb, fmtf, FLAGS); + uk_streambuf_strcpy(sb, "F_OK"); + uk_streambuf_shcc(sb, fmtf, RESET); + return; + } + PR_FLAG(sb, fmtf, orig_seek, R_, OK, okflags); + PR_FLAG(sb, fmtf, orig_seek, W_, OK, okflags); + PR_FLAG(sb, fmtf, orig_seek, X_, OK, okflags); + PR_FLAG_END(sb, fmtf, orig_seek, okflags); +} + #if CONFIG_LIBPOSIX_MMAP || CONFIG_LIBUKMMAP #include @@ -732,6 +750,9 @@ static void pr_param(struct uk_streambuf *sb, int fmtf, case PT_OFLAGS: param_oflags(sb, fmtf, param); break; + case PT_OKFLAGS: + param_okflag(sb, fmtf, param); + break; #if CONFIG_LIBPOSIX_MMAP || CONFIG_LIBUKMMAP case PT_PROTFLAGS: param_protflags(sb, fmtf, param); @@ -1196,6 +1217,14 @@ static void pr_syscall(struct uk_streambuf *sb, int fmtf, break; #endif /* HAVE_uk_syscall_clone */ +#ifdef HAVE_uk_syscall_access + case SYS_access: + VPR_SYSCALL(sb, fmtf, syscall_num, args, rc == 0, + PT_PATH, PT_OKFLAGS); + PR_SYSRET(sb, fmtf, PT_STATUS, rc); + break; +#endif /* HAVE_uk_syscall_access */ + #ifdef HAVE_uk_syscall_uname case SYS_uname: VPR_SYSCALL(sb, fmtf, syscall_num, args, rc == 0, -- 2.39.5