Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Jun 2009 17:44:55 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-other@freebsd.org
Subject:   svn commit: r194744 - in stable/4/lib/libc: . gen
Message-ID:  <200906231744.n5NHit0f084841@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Tue Jun 23 17:44:55 2009
New Revision: 194744
URL: http://svn.freebsd.org/changeset/base/194744

Log:
  MF7: 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.

Modified:
  stable/4/lib/libc/   (props changed)
  stable/4/lib/libc/gen/posixshm.c

Modified: stable/4/lib/libc/gen/posixshm.c
==============================================================================
--- stable/4/lib/libc/gen/posixshm.c	Tue Jun 23 17:42:06 2009	(r194743)
+++ stable/4/lib/libc/gen/posixshm.c	Tue Jun 23 17:44:55 2009	(r194744)
@@ -37,12 +37,34 @@
 #include <errno.h>
 #include <unistd.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);
 
@@ -65,5 +87,11 @@ shm_open(const char *path, int flags, mo
 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));
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200906231744.n5NHit0f084841>