master
h 86 lines 2.2 KB
Raw
1 /*
2 * miscellaneous FreeBSD system call shims
3 *
4 * Copyright (c) 2013-2014 Stacey D. Son
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8 #ifndef OS_MISC_H
9 #define OS_MISC_H
10
11 #include <sys/cpuset.h>
12 #include <sys/random.h>
13 #include <sched.h>
14
15 /*
16 * shm_open2 isn't exported, but the __sys_ alias is. We can use either for the
17 * static version, but to dynamically link we have to use the sys version.
18 */
19 int __sys_shm_open2(const char *path, int flags, mode_t mode, int shmflags,
20 const char *);
21
22 #if defined(__FreeBSD_version) && __FreeBSD_version >= 1300048
23 /* shm_open2(2) */
24 static inline abi_long do_freebsd_shm_open2(abi_ulong pathptr, abi_ulong flags,
25 abi_long mode, abi_ulong shmflags, abi_ulong nameptr)
26 {
27 int ret;
28 void *uname, *upath;
29
30 if (pathptr == (uintptr_t)SHM_ANON) {
31 upath = SHM_ANON;
32 } else {
33 upath = lock_user_string(pathptr);
34 if (upath == NULL) {
35 return -TARGET_EFAULT;
36 }
37 }
38
39 uname = NULL;
40 if (nameptr != 0) {
41 uname = lock_user_string(nameptr);
42 if (uname == NULL) {
43 unlock_user(upath, pathptr, 0);
44 return -TARGET_EFAULT;
45 }
46 }
47 ret = get_errno(__sys_shm_open2(upath,
48 target_to_host_bitmask(flags, fcntl_flags_tbl), mode,
49 target_to_host_bitmask(shmflags, shmflag_flags_tbl), uname));
50
51 if (upath != SHM_ANON) {
52 unlock_user(upath, pathptr, 0);
53 }
54 if (uname != NULL) {
55 unlock_user(uname, nameptr, 0);
56 }
57 return ret;
58 }
59 #endif /* __FreeBSD_version >= 1300048 */
60
61 #if defined(__FreeBSD_version) && __FreeBSD_version >= 1300049
62 /* shm_rename(2) */
63 static inline abi_long do_freebsd_shm_rename(abi_ulong fromptr, abi_ulong toptr,
64 abi_ulong flags)
65 {
66 int ret;
67 void *ufrom, *uto;
68
69 ufrom = lock_user_string(fromptr);
70 if (ufrom == NULL) {
71 return -TARGET_EFAULT;
72 }
73 uto = lock_user_string(toptr);
74 if (uto == NULL) {
75 unlock_user(ufrom, fromptr, 0);
76 return -TARGET_EFAULT;
77 }
78 ret = get_errno(shm_rename(ufrom, uto, flags));
79 unlock_user(ufrom, fromptr, 0);
80 unlock_user(uto, toptr, 0);
81
82 return ret;
83 }
84 #endif /* __FreeBSD_version >= 1300049 */
85
86 #endif /* OS_MISC_H */