X-Recipient: archive-cygwin@delorie.com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:date:from:reply-to:to:message-id:subject
	:mime-version:content-type:content-transfer-encoding; q=dns; s=
	default; b=cyLbEYy55/CYaVf7CMi1Wh9yasqkp201Od7ARSOdLhu0Tsk0IgyYr
	ppBVdfUOTMnLDhjB+gnuT3O8t/XfljL0RxNjn6DsNhr2l/CF/xgcaFM8fFe2I2nj
	SfgJUpUEcq63wuR/v/0nd+pKjMsTKjl5zWGgGUY+hkcjmg6sfCkkKk=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:date:from:reply-to:to:message-id:subject
	:mime-version:content-type:content-transfer-encoding; s=default;
	 bh=fgveS1mcU1NDgLs6J5tMUpL98Gk=; b=ebkRGmie96N0VruI1gJVv4Ixb9Nq
	2ZFmiTvinBcHNJisfOyfgvxxoAdEKWP5AALxAL+2RRl6MQ6cORFrw6L8W0iSgg6w
	jYRPIBI80iFIFdmKozjkQ56wl7XbH4LQ2304UHN1khXGsQTxkg7klyuh2O6mPNkV
	h+t5RBpqymwhiFo=
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=2.0 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2
X-HELO: nm16.bullet.mail.bf1.yahoo.com
Date: Wed, 8 Apr 2015 11:49:03 +0000 (UTC)
From: Christoph Weise <cfweise@yahoo.com>
Reply-To: Christoph Weise <cfweise@yahoo.com>
To: "cygwin@cygwin.com" <cygwin@cygwin.com>
Message-ID: <1999567694.2259208.1428493743005.JavaMail.yahoo@mail.yahoo.com>
Subject: Shared memory handling for mixed C/FORTRAN program
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

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 <linux/stat.h> */
#define SHM_W        0200        /* or S_IWUGO from <linux/stat.h> */


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

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.

Thinking it might have to do with the different underlying data types for the pointers (integer vs char/float) in the C versus FORTRAN code, I tried changing the type definitions of the pointers within the FORTRAN routines to

byte pptr
real*4 cptr

and it all compiles and runs, but gives exactly the same runtime error, and doesn't explain why the program works in Linux.

The pointer cptr is passed to FORTRAN subroutines as

real cbuf(*)

Not sure what I can do at this point (what to look out for, where to get help), so input appreciated. 

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

