1137d963cSStacey Son /* 2137d963cSStacey Son * miscellaneous FreeBSD system call shims 3137d963cSStacey Son * 4137d963cSStacey Son * Copyright (c) 2013-14 Stacey D. Son 5137d963cSStacey Son * 6137d963cSStacey Son * This program is free software; you can redistribute it and/or modify 7137d963cSStacey Son * it under the terms of the GNU General Public License as published by 8137d963cSStacey Son * the Free Software Foundation; either version 2 of the License, or 9137d963cSStacey Son * (at your option) any later version. 10137d963cSStacey Son * 11137d963cSStacey Son * This program is distributed in the hope that it will be useful, 12137d963cSStacey Son * but WITHOUT ANY WARRANTY; without even the implied warranty of 13137d963cSStacey Son * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14137d963cSStacey Son * GNU General Public License for more details. 15137d963cSStacey Son * 16137d963cSStacey Son * You should have received a copy of the GNU General Public License 17137d963cSStacey Son * along with this program; if not, see <http://www.gnu.org/licenses/>. 18137d963cSStacey Son */ 19137d963cSStacey Son 20137d963cSStacey Son #ifndef OS_MISC_H 21137d963cSStacey Son #define OS_MISC_H 22137d963cSStacey Son 23137d963cSStacey Son #include <sys/cpuset.h> 24137d963cSStacey Son #include <sys/random.h> 25137d963cSStacey Son #include <sched.h> 26137d963cSStacey Son 27*0c352988SKarim Taha /* 28*0c352988SKarim Taha * shm_open2 isn't exported, but the __sys_ alias is. We can use either for the 29*0c352988SKarim Taha * static version, but to dynamically link we have to use the sys version. 30*0c352988SKarim Taha */ 31*0c352988SKarim Taha int __sys_shm_open2(const char *path, int flags, mode_t mode, int shmflags, 32*0c352988SKarim Taha const char *); 33*0c352988SKarim Taha 34*0c352988SKarim Taha #if defined(__FreeBSD_version) && __FreeBSD_version >= 1300048 35*0c352988SKarim Taha /* shm_open2(2) */ 36*0c352988SKarim Taha static inline abi_long do_freebsd_shm_open2(abi_ulong pathptr, abi_ulong flags, 37*0c352988SKarim Taha abi_long mode, abi_ulong shmflags, abi_ulong nameptr) 38*0c352988SKarim Taha { 39*0c352988SKarim Taha int ret; 40*0c352988SKarim Taha void *uname, *upath; 41*0c352988SKarim Taha 42*0c352988SKarim Taha if (pathptr == (uintptr_t)SHM_ANON) { 43*0c352988SKarim Taha upath = SHM_ANON; 44*0c352988SKarim Taha } else { 45*0c352988SKarim Taha upath = lock_user_string(pathptr); 46*0c352988SKarim Taha if (upath == NULL) { 47*0c352988SKarim Taha return -TARGET_EFAULT; 48*0c352988SKarim Taha } 49*0c352988SKarim Taha } 50*0c352988SKarim Taha 51*0c352988SKarim Taha uname = NULL; 52*0c352988SKarim Taha if (nameptr != 0) { 53*0c352988SKarim Taha uname = lock_user_string(nameptr); 54*0c352988SKarim Taha if (uname == NULL) { 55*0c352988SKarim Taha unlock_user(upath, pathptr, 0); 56*0c352988SKarim Taha return -TARGET_EFAULT; 57*0c352988SKarim Taha } 58*0c352988SKarim Taha } 59*0c352988SKarim Taha ret = get_errno(__sys_shm_open2(upath, 60*0c352988SKarim Taha target_to_host_bitmask(flags, fcntl_flags_tbl), mode, 61*0c352988SKarim Taha target_to_host_bitmask(shmflags, shmflag_flags_tbl), uname)); 62*0c352988SKarim Taha 63*0c352988SKarim Taha if (upath != SHM_ANON) { 64*0c352988SKarim Taha unlock_user(upath, pathptr, 0); 65*0c352988SKarim Taha } 66*0c352988SKarim Taha if (uname != NULL) { 67*0c352988SKarim Taha unlock_user(uname, nameptr, 0); 68*0c352988SKarim Taha } 69*0c352988SKarim Taha return ret; 70*0c352988SKarim Taha } 71*0c352988SKarim Taha #endif /* __FreeBSD_version >= 1300048 */ 72*0c352988SKarim Taha 73137d963cSStacey Son 74137d963cSStacey Son #endif /* OS_MISC_H */ 75