On Apr 8 11:49, Christoph Weise wrote: > I am porting to cygwin a program in FORTRAN/C that relies on C > routines to create a shared memory region allowing various independent > FORTRAN routines to share data. Program compiles and runs ok on Linux > with g77/gcc compilers. I am compiling on cygwin 1.7.33-2(0.280/5/3) > with gfortran/gcc (4.8.3). > > One C routine creates the shared memory section of a user-defined > size. This seems to work just fine, although I had to add two lines to > the sys/shm.h file: > > > #define SHM_R 0400 /* or S_IRUGO from */ > #define SHM_W 0200 /* or S_IWUGO from */ These are non-standard Linux extensions. You should use the normal permission bits from sys/stat.h, like S_IRUSR, S_IWUSR, etc. > The shm library functions seem to return reasonable info (page size > and address, for removal of the shm section). > > > Each FORTRAN routine then calls a C routine to find the shared memory, > with a C routine returning pointers to two positions in the section > intended for different kinds of data: > > > > #define PAGESIZE 1024 PAGESIZE on Cygwin is not 1024, and the right value to use for XSI SHM is SHMLBA (== 64K on Cygwin) > int findshm(char**pptr, /* Address of the parameter pointer */ > float**cptr) /* Address of the data pointer */ > > ....calls to shm library functions .... > > shmaddr =0; p =shmat(shmid,shmaddr,(SHM_R |SHM_W)); *pptr =p; *cptr > =(float*)(p +PAGESIZE); return npages; > > > The calling FORTRAN code looks like this: > > integer pptr,cptr integer npages npages =findshm(pptr,cptr) > > Although the total size of the created memory section npages is ok, > the amount of memory following cptr is too small on cygwin (but not in > Linux) and the program crashes for larger datasets with > > Program received signal SIGSEGV:Segmentationfault -invalid memory > reference. Does shmat actually return a non-NULL value? Are you running cygserver? Did you check if it works from plain C? If not, do you have a simple testcase in plain C? Corinna -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Maintainer cygwin AT cygwin DOT com Red Hat