]> sourceware.org Git - newlib-cygwin.git/commitdiff
* shm.cc (shmat): If shmid is unknown, call a special variation
authorCorinna Vinschen <corinna@vinschen.de>
Tue, 30 Mar 2004 15:20:08 +0000 (15:20 +0000)
committerCorinna Vinschen <corinna@vinschen.de>
Tue, 30 Mar 2004 15:20:08 +0000 (15:20 +0000)
of shmget to retrieve the shared memory segment from Cygserver
instead of failing immediately.
* include/cygwin/ipc.h (IPC_KEY_IS_SHMID): New internal flag for
shmget when called from shmat.

winsup/cygwin/ChangeLog
winsup/cygwin/include/cygwin/ipc.h
winsup/cygwin/shm.cc

index aa0951ee959edb45c675701c6190659fdf5f0574..b81057696d3e3531403a0a90ab79aa6457668433 100644 (file)
@@ -1,3 +1,11 @@
+2004-03-30  Corinna Vinschen  <corinna@vinschen.de>
+
+       * shm.cc (shmat): If shmid is unknown, call a special variation
+       of shmget to retrieve the shared memory segment from Cygserver
+       instead of failing immediately.
+       * include/cygwin/ipc.h (IPC_KEY_IS_SHMID): New internal flag for 
+       shmget when called from shmat.
+
 2004-03-29  Corinna Vinschen  <corinna@vinschen.de>
 
        * fhandler.h (class fhandler_socket): Add has_been_closed member.
index 90534c29d0f3b5b2ca7d691b1d21d40d2bc50677..d0f5beaa11c349cd9598a3f6016a4be7b9bf38ec 100644 (file)
@@ -32,6 +32,9 @@ struct ipc_perm
 
 /* Mode bits:
  */
+#ifdef _KERNEL
+#define IPC_KEY_IS_SHMID 0x0100        /* Used in shmget when called from shmat. */
+#endif
 #define IPC_CREAT  0x0200      /* Create entry if key does not exist. */
 #define IPC_EXCL   0x0400      /* Fail if key exists. */
 #define IPC_NOWAIT 0x0800      /* Error if request must wait. */
index 7e4be9ebd00cf392ff96ab64745921d152febf11..4bae7b2d28d12e2a2fef182e2a3c8c91efc51507 100644 (file)
@@ -160,9 +160,26 @@ shmat (int shmid, const void *shmaddr, int shmflg)
     }
   if (!ssh_entry)
     {
-      /* Invalid shmid */
-      set_errno (EINVAL);
-      return (void *) -1;
+      /* The shmid is unknown to this process so far.  Try to get it from
+         the server if it exists.  Use special internal call to shmget,
+        which interprets the key as a shmid and only returns a valid
+        shmid if one exists.  Since shmctl inserts a new entry for this
+        shmid into ssh_list automatically, we just have to go through
+        that list again.  If that still fails, well, bad luck. */
+      if (shmid && shmget ((key_t) shmid, 0, IPC_KEY_IS_SHMID) != -1)
+        {
+         SLIST_FOREACH (ssh_entry, &ssh_list, ssh_next)
+           {
+             if (ssh_entry->shmid == shmid)
+               break;
+           }
+       }
+      if (!ssh_entry)
+        {
+         /* Invalid shmid */
+         set_errno (EINVAL);
+         return (void *) -1;
+       }
     }
   vm_object_t attach_va = NULL;
   if (shmaddr)
This page took 0.033472 seconds and 5 git commands to generate.