[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 05/23] bsd-user: Implement shm_open2(2) system call
From: |
Karim Taha |
Subject: |
[PATCH v3 05/23] bsd-user: Implement shm_open2(2) system call |
Date: |
Sat, 9 Sep 2023 22:36:46 +0300 |
From: Kyle Evans <kevans@FreeBSD.org>
Signed-off-by: Kyle Evans <kevans@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
---
bsd-user/freebsd/os-misc.h | 42 +++++++++++++++++++++++++++++++++++
bsd-user/freebsd/os-syscall.c | 13 +++++++++++
2 files changed, 55 insertions(+)
diff --git a/bsd-user/freebsd/os-misc.h b/bsd-user/freebsd/os-misc.h
index 8436ccb2f7..6b424b7078 100644
--- a/bsd-user/freebsd/os-misc.h
+++ b/bsd-user/freebsd/os-misc.h
@@ -24,5 +24,47 @@
#include <sys/random.h>
#include <sched.h>
+int shm_open2(const char *path, int flags, mode_t mode, int shmflags,
+ const char *);
+
+#if defined(__FreeBSD_version) && __FreeBSD_version >= 1300048
+/* shm_open2(2) */
+static inline abi_long do_freebsd_shm_open2(abi_ulong pathptr, abi_ulong flags,
+ abi_long mode, abi_ulong shmflags, abi_ulong nameptr)
+{
+ int ret;
+ void *uname, *upath;
+
+ if (pathptr == (uintptr_t)SHM_ANON) {
+ upath = SHM_ANON;
+ } else {
+ upath = lock_user_string(pathptr);
+ if (upath == NULL) {
+ return -TARGET_EFAULT;
+ }
+ }
+
+ uname = NULL;
+ if (nameptr != 0) {
+ uname = lock_user_string(nameptr);
+ if (uname == NULL) {
+ unlock_user(upath, pathptr, 0);
+ return -TARGET_EFAULT;
+ }
+ }
+ ret = get_errno(shm_open2(upath,
+ target_to_host_bitmask(flags, fcntl_flags_tbl), mode,
+ target_to_host_bitmask(shmflags, shmflag_flags_tbl), uname));
+
+ if (upath != SHM_ANON) {
+ unlock_user(upath, pathptr, 0);
+ }
+ if (uname != NULL) {
+ unlock_user(uname, nameptr, 0);
+ }
+ return ret;
+}
+#endif /* __FreeBSD_version >= 1300048 */
+
#endif /* OS_MISC_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 2224a280ea..b4311db578 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -33,9 +33,13 @@
#include "signal-common.h"
#include "user/syscall-trace.h"
+/* BSD independent syscall shims */
#include "bsd-file.h"
#include "bsd-proc.h"
+/* *BSD dependent syscall shims */
+#include "os-misc.h"
+
/* I/O */
safe_syscall3(int, open, const char *, path, int, flags, mode_t, mode);
safe_syscall4(int, openat, int, fd, const char *, path, int, flags, mode_t,
@@ -482,6 +486,15 @@ static abi_long freebsd_syscall(void *cpu_env, int num,
abi_long arg1,
ret = do_bsd_undelete(arg1);
break;
+ /*
+ * Memory management system calls.
+ */
+#if defined(__FreeBSD_version) && __FreeBSD_version >= 1300048
+ case TARGET_FREEBSD_NR_shm_open2: /* shm_open2(2) */
+ ret = do_freebsd_shm_open2(arg1, arg2, arg3, arg4, arg5);
+ break;
+#endif
+
/*
* sys{ctl, arch, call}
*/
--
2.42.0
- [PATCH v3 00/23] bsd-user: Implement mmap related system calls for FreeBSD., Karim Taha, 2023/09/09
- [PATCH v3 01/23] bsd-user: Implement struct target_ipc_perm, Karim Taha, 2023/09/09
- [PATCH v3 02/23] bsd-user: Implement struct target_shmid_ds, Karim Taha, 2023/09/09
- [PATCH v3 03/23] bsd-user: Declarations for ipc_perm and shmid_ds conversion functions, Karim Taha, 2023/09/09
- [PATCH v3 04/23] bsd-user: Introduce freebsd/os-misc.h to the source tree, Karim Taha, 2023/09/09
- [PATCH v3 05/23] bsd-user: Implement shm_open2(2) system call,
Karim Taha <=
- [PATCH v3 06/23] bsd-user: Implement shm_rename(2) system call, Karim Taha, 2023/09/09
- [PATCH v3 07/23] bsd-user: Add bsd-mem.c to meson.build, Karim Taha, 2023/09/09
- [PATCH v3 08/23] bsd-user: Implement target_set_brk function in bsd-mem.c instead of os-syscall.c, Karim Taha, 2023/09/09
- [PATCH v3 09/23] bsd-user: Implement ipc_perm conversion between host and target., Karim Taha, 2023/09/09
- [PATCH v3 10/23] bsd-user: Implement shmid_ds conversion between host and target., Karim Taha, 2023/09/09
- [PATCH v3 11/23] bsd-user: Introduce bsd-mem.h to the source tree, Karim Taha, 2023/09/09
- [PATCH v3 12/23] bsd-user: Implement mmap(2) and munmap(2), Karim Taha, 2023/09/09
- [PATCH v3 13/23] bsd-user: Implement mprotect(2), Karim Taha, 2023/09/09