[Glibc-bsd-commits] r2570 - in trunk/glibc-ports/kfreebsd: . bits
Aurelien Jarno
aurel32 at alioth.debian.org
Wed Jun 3 08:03:40 UTC 2009
Author: aurel32
Date: 2009-06-03 08:03:40 +0000 (Wed, 03 Jun 2009)
New Revision: 2570
Added:
trunk/glibc-ports/kfreebsd/shm_open.c
trunk/glibc-ports/kfreebsd/shm_unlink.c
Modified:
trunk/glibc-ports/kfreebsd/Makefile
trunk/glibc-ports/kfreebsd/Versions
trunk/glibc-ports/kfreebsd/bits/fcntl.h
trunk/glibc-ports/kfreebsd/kernel-features.h
trunk/glibc-ports/kfreebsd/syscalls.list
Log:
Add shm_open() and shm_unlink() support
Modified: trunk/glibc-ports/kfreebsd/Makefile
===================================================================
--- trunk/glibc-ports/kfreebsd/Makefile 2009-06-03 08:03:09 UTC (rev 2569)
+++ trunk/glibc-ports/kfreebsd/Makefile 2009-06-03 08:03:40 UTC (rev 2570)
@@ -87,6 +87,7 @@
# for INLINE_SYSCALL
sysdep_routines += sys_fork sys_execve sys_sigaction sys_close sys_fcntl
sysdep_routines += sys_clock_getres sys_clock_gettime sys_clock_settime
+sysdep_routines += sys_shm_open sys_shm_unlink
endif
ifeq ($(subdir),posix)
Modified: trunk/glibc-ports/kfreebsd/Versions
===================================================================
--- trunk/glibc-ports/kfreebsd/Versions 2009-06-03 08:03:09 UTC (rev 2569)
+++ trunk/glibc-ports/kfreebsd/Versions 2009-06-03 08:03:40 UTC (rev 2570)
@@ -91,7 +91,10 @@
__syscall_wait4; __syscall_fcntl;
# needed by librt as INLINE_SYSCALL:
__syscall_clock_getres; __syscall_clock_gettime; __syscall_clock_settime;
- # misc fixes for FreeBSD:
+ __syscall_shm_open; __syscall_shm_unlink;
+ # needed by librt:
+ __unlink;
+ # misc fixes for FreeBSD:
__syscall_freebsd6_lseek; __syscall_freebsd6_pread; __syscall_freebsd6_pwrite;
__syscall_lseek; __syscall_pread; __syscall_pwrite;
__syscall_connect; __syscall_sendto;
Modified: trunk/glibc-ports/kfreebsd/bits/fcntl.h
===================================================================
--- trunk/glibc-ports/kfreebsd/bits/fcntl.h 2009-06-03 08:03:09 UTC (rev 2569)
+++ trunk/glibc-ports/kfreebsd/bits/fcntl.h 2009-06-03 08:03:40 UTC (rev 2570)
@@ -77,6 +77,21 @@
#define FWRITE 2
#endif
+/*
+ * We are out of bits in f_flag (which is a short). However,
+ * the flag bits not set in FMASK are only meaningful in the
+ * initial open syscall. Those bits can thus be given a
+ * different meaning for fcntl(2).
+ */
+#if __USE_BSD
+/*
+ * Set by shm_open(3) to get automatic MAP_ASYNC behavior
+ * for POSIX shared memory objects (which are otherwise
+ * implemented as plain files).
+ */
+#define FPOSIXSHM O_NOFOLLOW
+#endif
+
/* Values for the second argument to `fcntl'. */
#define F_DUPFD 0 /* Duplicate file descriptor. */
#define F_GETFD 1 /* Get file descriptor flags. */
Modified: trunk/glibc-ports/kfreebsd/kernel-features.h
===================================================================
--- trunk/glibc-ports/kfreebsd/kernel-features.h 2009-06-03 08:03:09 UTC (rev 2569)
+++ trunk/glibc-ports/kfreebsd/kernel-features.h 2009-06-03 08:03:40 UTC (rev 2570)
@@ -72,8 +72,13 @@
# define __ASSUME_PREAD_PWRITE_SYSCALLS 1
#endif
+/* The `shm_*' syscalls were introduced in kFreeBSD 8.0 */
+#if __KFREEBSD_KERNEL_VERSION >= 0x8000C
+# define __ASSUME_SHMFCTS 1
+#endif
+
/* The `*at' syscalls were introduced in kFreeBSD 8.0. */
#if __KFREEBSD_KERNEL_VERSION >= 0x8001D
-# define __ASSUME_ATFCTS 1
+# define __ASSUME_ATFCTS 1
#endif
Added: trunk/glibc-ports/kfreebsd/shm_open.c
===================================================================
--- trunk/glibc-ports/kfreebsd/shm_open.c (rev 0)
+++ trunk/glibc-ports/kfreebsd/shm_open.c 2009-06-03 08:03:40 UTC (rev 2570)
@@ -0,0 +1,65 @@
+/* Copyright (C) 2009 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sysdep.h>
+
+extern int __syscall_shm_open (const char *path, int flags, mode_t mode);
+libc_hidden_proto (__syscall_shm_open);
+
+/* Open shared memory object. */
+int
+shm_open (const char *name, int oflag, mode_t mode)
+{
+ /* First try the new syscall. */
+ int fd = INLINE_SYSCALL (shm_open, 3, name, oflag, mode);
+
+#ifndef __ASSUME_POSIXSHM_SYSCALL
+ /* New syscall not available, use fallback code. */
+ if (fd == -1 && errno == ENOSYS)
+ {
+ struct stat stab;
+
+ if ((oflag & O_ACCMODE) == O_WRONLY)
+ return (EINVAL);
+
+ fd = __open (name, oflag, mode);
+ if (fd != -1)
+ {
+ if (__fstat (fd, &stab) != 0 || !S_ISREG (stab.st_mode))
+ {
+ __close (fd);
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ if (__fcntl (fd, F_SETFL, (int) FPOSIXSHM) != 0)
+ {
+ __close (fd);
+ return -1;
+ }
+ }
+ }
+#endif
+
+ return fd;
+}
Added: trunk/glibc-ports/kfreebsd/shm_unlink.c
===================================================================
--- trunk/glibc-ports/kfreebsd/shm_unlink.c (rev 0)
+++ trunk/glibc-ports/kfreebsd/shm_unlink.c 2009-06-03 08:03:40 UTC (rev 2570)
@@ -0,0 +1,42 @@
+/* Copyright (C) 2009 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sysdep.h>
+
+extern int __syscall_shm_unlink (const char *name);
+libc_hidden_proto (__syscall_shm_unlink)
+
+/* Unlink a shared memory object. */
+int
+shm_unlink (const char *name)
+{
+ /* First try the new syscall. */
+ int result = INLINE_SYSCALL (shm_unlink, 1, name);
+
+#ifndef __ASSUME_POSIXSHM_SYSCALL
+ /* New syscall not available, simply unlink the file. */
+ if (result == -1 && errno == ENOSYS)
+ result = __unlink (name);
+#endif
+
+ return result;
+}
Modified: trunk/glibc-ports/kfreebsd/syscalls.list
===================================================================
--- trunk/glibc-ports/kfreebsd/syscalls.list 2009-06-03 08:03:09 UTC (rev 2569)
+++ trunk/glibc-ports/kfreebsd/syscalls.list 2009-06-03 08:03:40 UTC (rev 2570)
@@ -177,3 +177,5 @@
sys_renameat - renameat i:isis __syscall_renameat
sys_symlinkat - symlinkat i:sis __syscall_symlinkat
sys_unlinkat - unlinkat i:isi __syscall_unlinkat
+sys_shm_open - shm_open i:sii __syscall_shm_open
+sys_shm_unlink - shm_unlink i:s __syscall_shm_unlink
More information about the Glibc-bsd-commits
mailing list