Shared memory handling for mixed C/FORTRAN program

Corinna Vinschen corinna-cygwin@cygwin.com
Sun Apr 12 11:23:00 GMT 2015


On Apr 11 20:25, Christoph Weise wrote:
> Please see below, I provide minimal C code for three separate
> executables, one creates the shm section, another finds it, the third
> removes it. I include also a bash test script that executes the
> routines in order.

Thanks,

> Please beware as I removed some checks to reduce
> the length of the code, but it should run ok. The PAGESIZE parameter
> is hardcoded (here 512 bytes). The desired shared mem section size is
> set interactively as input to makeshm, or automatically with the bash
> script. 

Ok, but there are bugs in the code which result in GCC warnings.  I
don't know which of them are part of your original code, but they are
really a problem.

  if ((int) -1 == p)

Don't check a pointer against an int value.  It won't work on a 64 bit
platform.  Make that

  if ((void *) -1 == p)

For the same reason, don't use %x to printf a pointer.  Use %tx.

> I can write to the shm section with the second routine when the requested section <= 4096 bytes. Otherwise it's not happy. 

The problem is the call to shmget:

  #undef  PAGESIZE
  #define PAGESIZE 512
  shmid = shmget(key, PAGESIZE, IPC_ALLOC);

Since you're requesting only 512 bytes, the shared memory segment the
following shmat call returns is only 4K.  The shmget call should request
as much memory as it needs so that the OS call is called with the right
view size.

I re-read the POSIX man page for shmget, and it doesn't mention anything
which would point out that Cygwin's behaviour here is wrong.  If anybody
has more information on this, please share them.


HTH,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20150412/dd28954b/attachment.sig>


More information about the Cygwin mailing list