diff options
author | Kyle Evans <kevans@FreeBSD.org> | 2019-09-25 17:59:15 +0000 |
---|---|---|
committer | Kyle Evans <kevans@FreeBSD.org> | 2019-09-25 17:59:15 +0000 |
commit | 20f7057685cdb96761f1448f4827606e4a6f4406 (patch) | |
tree | 17a0b1890a892d0381e7ece777c3f7e983b74e39 /sys/kern/uipc_shm.c | |
parent | e11365676b89695bbec90db2f9f9a5f8bda87121 (diff) | |
download | src-20f7057685cdb96761f1448f4827606e4a6f4406.tar.gz src-20f7057685cdb96761f1448f4827606e4a6f4406.zip |
Add a shm_open2 syscall to support upcoming memfd_create
shm_open2 allows a little more flexibility than the original shm_open.
shm_open2 doesn't enforce CLOEXEC on its callers, and it has a separate
shmflag argument that can be expanded later. Currently the only shmflag is
to allow file sealing on the returned fd.
shm_open and memfd_create will both be implemented in libc to use this new
syscall.
__FreeBSD_version is bumped to indicate the presence.
Reviewed by: kib, markj
Differential Revision: https://reviews.freebsd.org/D21393
Notes
Notes:
svn path=/head/; revision=352700
Diffstat (limited to 'sys/kern/uipc_shm.c')
-rw-r--r-- | sys/kern/uipc_shm.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/sys/kern/uipc_shm.c b/sys/kern/uipc_shm.c index 2674fdfedba9..4c21da4bc38a 100644 --- a/sys/kern/uipc_shm.c +++ b/sys/kern/uipc_shm.c @@ -1316,3 +1316,36 @@ SYSCTL_PROC(_kern_ipc, OID_AUTO, posix_shm_list, CTLFLAG_RD | CTLFLAG_MPSAFE | CTLTYPE_OPAQUE, NULL, 0, sysctl_posix_shm_list, "", "POSIX SHM list"); + +int +kern_shm_open2(struct thread *td, const char *path, int flags, mode_t mode, + int shmflags, const char *name __unused) +{ + int initial_seals; + + if ((shmflags & ~SHM_ALLOW_SEALING) != 0) + return (EINVAL); + + initial_seals = F_SEAL_SEAL; + if ((shmflags & SHM_ALLOW_SEALING) != 0) + initial_seals &= ~F_SEAL_SEAL; + return (kern_shm_open(td, path, flags, 0, NULL, initial_seals)); +} + +/* + * This version of the shm_open() interface leaves CLOEXEC behavior up to the + * caller, and libc will enforce it for the traditional shm_open() call. This + * allows other consumers, like memfd_create(), to opt-in for CLOEXEC. This + * interface also includes a 'name' argument that is currently unused, but could + * potentially be exported later via some interface for debugging purposes. + * From the kernel's perspective, it is optional. Individual consumers like + * memfd_create() may require it in order to be compatible with other systems + * implementing the same function. + */ +int +sys_shm_open2(struct thread *td, struct shm_open2_args *uap) +{ + + return (kern_shm_open2(td, uap->path, uap->flags, uap->mode, + uap->shmflags, uap->name)); +} |