]>
Commit | Line | Data |
---|---|---|
137d963c SS |
1 | /* |
2 | * miscellaneous FreeBSD system call shims | |
3 | * | |
4 | * Copyright (c) 2013-14 Stacey D. Son | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
20 | #ifndef OS_MISC_H | |
21 | #define OS_MISC_H | |
22 | ||
23 | #include <sys/cpuset.h> | |
24 | #include <sys/random.h> | |
25 | #include <sched.h> | |
26 | ||
0c352988 KT |
27 | /* |
28 | * shm_open2 isn't exported, but the __sys_ alias is. We can use either for the | |
29 | * static version, but to dynamically link we have to use the sys version. | |
30 | */ | |
31 | int __sys_shm_open2(const char *path, int flags, mode_t mode, int shmflags, | |
32 | const char *); | |
33 | ||
34 | #if defined(__FreeBSD_version) && __FreeBSD_version >= 1300048 | |
35 | /* shm_open2(2) */ | |
36 | static inline abi_long do_freebsd_shm_open2(abi_ulong pathptr, abi_ulong flags, | |
37 | abi_long mode, abi_ulong shmflags, abi_ulong nameptr) | |
38 | { | |
39 | int ret; | |
40 | void *uname, *upath; | |
41 | ||
42 | if (pathptr == (uintptr_t)SHM_ANON) { | |
43 | upath = SHM_ANON; | |
44 | } else { | |
45 | upath = lock_user_string(pathptr); | |
46 | if (upath == NULL) { | |
47 | return -TARGET_EFAULT; | |
48 | } | |
49 | } | |
50 | ||
51 | uname = NULL; | |
52 | if (nameptr != 0) { | |
53 | uname = lock_user_string(nameptr); | |
54 | if (uname == NULL) { | |
55 | unlock_user(upath, pathptr, 0); | |
56 | return -TARGET_EFAULT; | |
57 | } | |
58 | } | |
59 | ret = get_errno(__sys_shm_open2(upath, | |
60 | target_to_host_bitmask(flags, fcntl_flags_tbl), mode, | |
61 | target_to_host_bitmask(shmflags, shmflag_flags_tbl), uname)); | |
62 | ||
63 | if (upath != SHM_ANON) { | |
64 | unlock_user(upath, pathptr, 0); | |
65 | } | |
66 | if (uname != NULL) { | |
67 | unlock_user(uname, nameptr, 0); | |
68 | } | |
69 | return ret; | |
70 | } | |
71 | #endif /* __FreeBSD_version >= 1300048 */ | |
72 | ||
182ea728 KE |
73 | #if defined(__FreeBSD_version) && __FreeBSD_version >= 1300049 |
74 | /* shm_rename(2) */ | |
75 | static inline abi_long do_freebsd_shm_rename(abi_ulong fromptr, abi_ulong toptr, | |
76 | abi_ulong flags) | |
77 | { | |
78 | int ret; | |
79 | void *ufrom, *uto; | |
80 | ||
81 | ufrom = lock_user_string(fromptr); | |
82 | if (ufrom == NULL) { | |
83 | return -TARGET_EFAULT; | |
84 | } | |
85 | uto = lock_user_string(toptr); | |
86 | if (uto == NULL) { | |
87 | unlock_user(ufrom, fromptr, 0); | |
88 | return -TARGET_EFAULT; | |
89 | } | |
90 | ret = get_errno(shm_rename(ufrom, uto, flags)); | |
91 | unlock_user(ufrom, fromptr, 0); | |
92 | unlock_user(uto, toptr, 0); | |
93 | ||
94 | return ret; | |
95 | } | |
96 | #endif /* __FreeBSD_version >= 1300049 */ | |
137d963c SS |
97 | |
98 | #endif /* OS_MISC_H */ |