]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/syscall_shim: Add (F|R|W|X)_OK and access
authorMarc Rittinghaus <marc.rittinghaus@unikraft.io>
Fri, 14 Apr 2023 15:01:15 +0000 (17:01 +0200)
committerUnikraft <monkey@unikraft.io>
Wed, 26 Apr 2023 23:10:14 +0000 (23:10 +0000)
This commit adds a definition of the (F|R|W|X)_OK flags
and the access syscall

Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Reviewed-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.io>
Approved-by: Simon Kuenzer <simon@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #836

lib/syscall_shim/uk_prsyscall.c

index 657e8ccc7dfe553595f52b3680abde833767a77a..2b8d80cd64c53ce03b800323393050538487bee4 100644 (file)
@@ -4,6 +4,7 @@
  * You may not use this file except in compliance with the License.
  */
 
+#define _GNU_SOURCE
 #include <uk/config.h>
 
 #include <string.h>
@@ -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 <sys/mman.h>
 
@@ -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,