This is the mail archive of the
cygwin-cvs@cygwin.com
mailing list for the Cygwin project.
[newlib-cygwin/cygwin-2.0] Don't rely on size argument in shmget call
- From: Corinna Vinschen <corinna at sourceware dot org>
- To: cygwin-cvs at sourceware dot org
- Date: 23 Apr 2015 20:52:25 -0000
- Subject: [newlib-cygwin/cygwin-2.0] Don't rely on size argument in shmget call
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=023be4aedbd5bfb0a56164a2803c9c24a0d546f5
commit 023be4aedbd5bfb0a56164a2803c9c24a0d546f5
Author: Corinna Vinschen <corinna@vinschen.de>
Date: Sun Apr 12 14:05:12 2015 +0200
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>
Diff:
---
winsup/cygwin/ChangeLog | 6 ++++++
winsup/cygwin/release/2.0.0 | 3 +++
winsup/cygwin/shm.cc | 9 ++++++++-
3 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 9a48131..a75810f 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,9 @@
+2015-04-12 Corinna Vinschen <corinna@vinschen.de>
+
+ * shm.cc (shmget): Fetch segment size from server rather than using
+ size argument to accommodate existing segments. Add comment to explain
+ why.
+
2015-04-10 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/version.h (CYGWIN_VERSION_DLL_MAJOR): Bump to 2000.
diff --git a/winsup/cygwin/release/2.0.0 b/winsup/cygwin/release/2.0.0
index f01e497..6c89819 100644
--- a/winsup/cygwin/release/2.0.0
+++ b/winsup/cygwin/release/2.0.0
@@ -40,3 +40,6 @@ Bug Fixes
- Fix UTF-16 surrogate handling in wctomb and friends.
Addresses: https://cygwin.com/ml/cygwin/2015-03/msg00452.html
+
+- Fix shmget usage of size parameter for already existing segments.
+ Addresses: https://cygwin.com/ml/cygwin/2015-04/msg00105.html
diff --git a/winsup/cygwin/shm.cc b/winsup/cygwin/shm.cc
index c5ab708..e209346 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 ();