diff options
| author | Karim Taha <kariem.taha2.7@gmail.com> | 2023-09-25 21:26:51 +0300 |
|---|---|---|
| committer | Warner Losh <imp@bsdimp.com> | 2023-10-03 17:14:06 -0600 |
| commit | 0c3529888a427cefe248227423f7a89c8f665fab (patch) | |
| tree | 0ee85931a523ce1bc242212b6951f206a0c85f2f /bsd-user/freebsd/os-misc.h | |
| parent | 137d963cfb1c9f0d9e76a40229df2996809b746b (diff) | |
| download | focaccia-qemu-0c3529888a427cefe248227423f7a89c8f665fab.tar.gz focaccia-qemu-0c3529888a427cefe248227423f7a89c8f665fab.zip | |
bsd-user: Implement shm_open2(2) system call
Signed-off-by: Kyle Evans <kevans@FreeBSD.org> Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20230925182709.4834-6-kariem.taha2.7@gmail.com>
Diffstat (limited to 'bsd-user/freebsd/os-misc.h')
| -rw-r--r-- | bsd-user/freebsd/os-misc.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/bsd-user/freebsd/os-misc.h b/bsd-user/freebsd/os-misc.h index 8436ccb2f7..d5e8b5484c 100644 --- a/bsd-user/freebsd/os-misc.h +++ b/bsd-user/freebsd/os-misc.h @@ -24,5 +24,51 @@ #include <sys/random.h> #include <sched.h> +/* + * shm_open2 isn't exported, but the __sys_ alias is. We can use either for the + * static version, but to dynamically link we have to use the sys version. + */ +int __sys_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(__sys_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 */ |