diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 46ebb1c7b..0b5097283 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,15 @@ +2007-02-08 Corinna Vinschen + + * cygwin.din (shm_open): Export. + (shm_unlink): Export. + * syscalls.cc (shm_open): New function. + (shm_unlink): New function. + * sysconf.cc (sca): Set value of _SC_SHARED_MEMORY_OBJECTS to + _POSIX_SHARED_MEMORY_OBJECTS. + * include/cygwin/version.h: Bump API minor number. + * include/sys/mman.h (shm_open): Add prototype. + (shm_unlink): Ditto. + 2007-02-08 Christopher Faylor Corinna Vinschen diff --git a/winsup/cygwin/cygwin.din b/winsup/cygwin/cygwin.din index 9fc024eef..b641a8462 100644 --- a/winsup/cygwin/cygwin.din +++ b/winsup/cygwin/cygwin.din @@ -1314,6 +1314,8 @@ shmat SIGFE shmctl SIGFE shmdt SIGFE shmget SIGFE +shm_open SIGFE +shm_unlink SIGFE shutdown = cygwin_shutdown SIGFE sigaction SIGFE sigaddset SIGFE diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h index d015fade0..8ed2f7dff 100644 --- a/winsup/cygwin/include/cygwin/version.h +++ b/winsup/cygwin/include/cygwin/version.h @@ -302,12 +302,13 @@ details. */ 162: New struct ifreq. Export if_nametoindex, if_indextoname, if_nameindex, if_freenameindex. 163: Export posix_madvise, posix_memalign. + 164: Export shm_open, shm_unlink. */ /* Note that we forgot to bump the api for ualarm, strtoll, strtoull */ #define CYGWIN_VERSION_API_MAJOR 0 -#define CYGWIN_VERSION_API_MINOR 163 +#define CYGWIN_VERSION_API_MINOR 164 /* There is also a compatibity version number associated with the shared memory regions. It is incremented when incompatible diff --git a/winsup/cygwin/include/sys/mman.h b/winsup/cygwin/include/sys/mman.h index a3c8077b0..234de8074 100644 --- a/winsup/cygwin/include/sys/mman.h +++ b/winsup/cygwin/include/sys/mman.h @@ -67,6 +67,9 @@ extern int munlock (const void *__addr, size_t __len); extern int posix_madvise (void *__addr, size_t __len, int __advice); +extern int shm_open (const char *__name, int __oflag, mode_t __mode); +extern int shm_unlink (const char *__name); + #ifdef __cplusplus }; #endif /* __cplusplus */ diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 6a0e45fb5..998fe0ed4 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -3346,3 +3346,49 @@ pclose (FILE *fp) return status; } + +#define SHM_STORAGE "/dev/shm" + +extern "C" int +shm_open (const char *name, int oflag, mode_t mode) +{ + /* Name must start with a single slash. */ + if (!name || name[0] != '/' || name[1] == '/' + || strlen (name) > CYG_MAX_PATH - sizeof (SHM_STORAGE)) + { + debug_printf ("Invalid shared memory object name '%s'", name); + set_errno (EINVAL); + return -1; + } + /* Check for valid flags. */ + if (((oflag & O_ACCMODE) != O_RDONLY && (oflag & O_ACCMODE) != O_RDWR) + || (oflag & ~(O_ACCMODE | O_CREAT | O_EXCL | O_TRUNC))) + { + debug_printf ("Invalid oflag 0%o", oflag); + set_errno (EINVAL); + return -1; + } + /* Note that we require the existance of /dev/shm here. We don't + create this directory from here. That's the task of the installer. */ + char shmname[CYG_MAX_PATH]; + strcpy (shmname, SHM_STORAGE); + strcat (shmname, name); + return open (shmname, oflag, mode & 0777); +} + +extern "C" int +shm_unlink (const char *name) +{ + /* Name must start with a single slash. */ + if (!name || name[0] != '/' || name[1] == '/' + || strlen (name) > CYG_MAX_PATH - sizeof (SHM_STORAGE)) + { + debug_printf ("Invalid shared memory object name '%s'", name); + set_errno (EINVAL); + return -1; + } + char shmname[CYG_MAX_PATH]; + strcpy (shmname, SHM_STORAGE); + strcat (shmname, name); + return unlink (shmname); +} diff --git a/winsup/cygwin/sysconf.cc b/winsup/cygwin/sysconf.cc index 04f03f78e..f1f5d391e 100644 --- a/winsup/cygwin/sysconf.cc +++ b/winsup/cygwin/sysconf.cc @@ -149,7 +149,7 @@ static struct {cons, {c:-1L}}, /* 28, _SC_PRIORITIZED_IO */ {cons, {c:_POSIX_REALTIME_SIGNALS}}, /* 29, _SC_REALTIME_SIGNALS */ {cons, {c:_POSIX_SEMAPHORES}}, /* 30, _SC_SEMAPHORES */ - {cons, {c:-1L}}, /* 31, _SC_SHARED_MEMORY_OBJECTS */ + {cons, {c:_POSIX_SHARED_MEMORY_OBJECTS}}, /* 31, _SC_SHARED_MEMORY_OBJECTS */ {cons, {c:_POSIX_SYNCHRONIZED_IO}}, /* 32, _SC_SYNCHRONIZED_IO */ {cons, {c:_POSIX_TIMERS}}, /* 33, _SC_TIMERS */ {nsup, {c:0}}, /* 34, _SC_AIO_LISTIO_MAX */