From ae66536ebdd69f1e8cd443c780da96d902724d5c Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Thu, 11 Jun 2009 21:37:23 +0000 Subject: If the running kernel has support for shm_open() and shm_unlink() as system calls (i.e. 8.0+), then invoke the system calls instead of using open/fcntl/unlink. This is a direct commit instead of an MFC since libc in 8.0 always uses the system calls directly. MFC after: 1 week --- lib/libc/gen/posixshm.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'lib/libc') diff --git a/lib/libc/gen/posixshm.c b/lib/libc/gen/posixshm.c index 05fc1c9bf403..21246e2a2c1c 100644 --- a/lib/libc/gen/posixshm.c +++ b/lib/libc/gen/posixshm.c @@ -40,12 +40,34 @@ __FBSDID("$FreeBSD$"); #include #include "un-namespace.h" +static int _shm_in_kernel = -1; + +/* Wrappers for POSIX SHM system calls in newer kernels. */ +static __inline int +_shm_open(const char *path, int flags, mode_t mode) +{ + + return (syscall(482, path, flags, mode)); +} + +static __inline int +_shm_unlink(const char *path) +{ + + return (syscall(483, path)); +} + int shm_open(const char *path, int flags, mode_t mode) { int fd; struct stat stab; + if (_shm_in_kernel == -1) + _shm_in_kernel = feature_present("posix_shm"); + if (_shm_in_kernel == 1) + return (_shm_open(path, flags, mode)); + if ((flags & O_ACCMODE) == O_WRONLY) return (EINVAL); @@ -68,5 +90,11 @@ shm_open(const char *path, int flags, mode_t mode) int shm_unlink(const char *path) { + + if (_shm_in_kernel == -1) + _shm_in_kernel = feature_present("posix_shm"); + if (_shm_in_kernel == 1) + return (_shm_unlink(path)); + return (unlink(path)); } -- cgit v1.3