summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/shm.cc
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2015-04-12 14:05:12 +0200
committerCorinna Vinschen <corinna@vinschen.de>2015-04-23 21:59:49 +0200
commit023be4aedbd5bfb0a56164a2803c9c24a0d546f5 (patch)
tree356327450ad36b405cec091fb937ad74b510607f /winsup/cygwin/shm.cc
parent5778304f168a0ce4d1b6cd048a5e499436f0f6d0 (diff)
downloadcygnal-023be4aedbd5bfb0a56164a2803c9c24a0d546f5.tar.gz
cygnal-023be4aedbd5bfb0a56164a2803c9c24a0d546f5.tar.bz2
cygnal-023be4aedbd5bfb0a56164a2803c9c24a0d546f5.zip
Don't rely on size argument in shmget call
* shm.cc (shmget): Fetch segment size from server rather than using size argument to accommodate existing segments. Add comment to explain why. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'winsup/cygwin/shm.cc')
-rw-r--r--winsup/cygwin/shm.cc9
1 files changed, 8 insertions, 1 deletions
diff --git a/winsup/cygwin/shm.cc b/winsup/cygwin/shm.cc
index c5ab708a4..e209346f7 100644
--- a/winsup/cygwin/shm.cc
+++ b/winsup/cygwin/shm.cc
@@ -377,7 +377,14 @@ shmget (key_t key, size_t size, int shmflg)
shmid and hdl value to the list. */
ssh_new_entry->shmid = shmid;
ssh_new_entry->hdl = hdl;
- ssh_new_entry->size = size;
+ /* Fetch segment size from server. If this is an already existing segment,
+ the size value in this shmget call is supposed to be meaningless. */
+ struct shmid_ds stat;
+ client_request_shm stat_req (shmid, IPC_STAT, &stat);
+ if (stat_req.make_request () == -1 || stat_req.retval () == -1)
+ ssh_new_entry->size = size;
+ else
+ ssh_new_entry->size = stat.shm_segsz;
ssh_new_entry->ref_count = 0;
SLIST_INSERT_HEAD (&ssh_list, ssh_new_entry, ssh_next);
SLIST_UNLOCK ();