X-Recipient: archive-cygwin AT delorie DOT 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:in-reply-to :references:subject:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=N/ynmoPlDZarIgqy /vOgkmYDB/ZXTZZa5eczLB0YGGFozDdv4L74EQKvFbZswMEfrJIjvn0TCmXvtAsM JLIMwvKAEu6Udhdt/OFSJ9e+OUzwintxy9o26eQcGR0z6lFYmiWdXcC+Pre6Q6MS 2joRJr1jQGynwgMmSDKZwazY2k8= 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:in-reply-to :references:subject:mime-version:content-type :content-transfer-encoding; s=default; bh=YKQkbMTEG2/uZq5RzJ5Nzj ltPgk=; b=ujpqj12ir6X8XwT1ut3TjMwydZ6PqU97s0qVsFo1DsjHPiaycdbHMh vyysEiR3xapHiKcIvCGmDziXObSKYEMbGdg5aniP9JCW6ZWKqdjG0Nv9g21e2tXV ZqwnB9cOOm4Zu7JrrPNYALqqwWkRCtKP91OlLqd2GvnhRb145A19o= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=2.1 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS,T_RP_MATCHES_RCVD,UNSUBSCRIBE_BODY autolearn=no version=3.3.2 X-HELO: nm40-vm1.bullet.mail.bf1.yahoo.com Date: Fri, 10 Apr 2015 22:20:43 +0000 (UTC) From: Christoph Weise Reply-To: Christoph Weise To: "cygwin AT cygwin DOT com" Message-ID: <1194341851.758458.1428704443750.JavaMail.yahoo@mail.yahoo.com> In-Reply-To: <1999567694.2259208.1428493743005.JavaMail.yahoo@mail.yahoo.com> References: <1999567694 DOT 2259208 DOT 1428493743005 DOT JavaMail DOT yahoo AT mail DOT yahoo DOT com> Subject: Re: Shared memory handling for mixed C/FORTRAN program MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Thanks for your help, your suggestions have helped me greatly but I'm still stuck. >> 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. Ok, thank you, changed that. >> 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) Setting PAGESIZE to SHMLBA creates problems elsewhere in the program (then PAGESIZE is too big for the program to handle, a problem I have yet to debug) so only unless there is no workaround (please see below) I'd like to avoid trying to use SHMLBA for the time being. Regardless of the choice of PAGESIZE, only a total of 4kB can be stored sequentially in the shared memory section handed by shmat. If I try to write more than this number of bytes to the shm section the program crashes. >> 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? shmat seems to work as desired, the pointers it returns are being passed properly between C and Fortran > Are you running cygserver? I am using the server. > Did you check if it works from plain C? If not, do you have a simple testcase in plain C? I modified the first C utlity, which sets up the shared memory section, to use the addresses it receives from shmat to try to write as much data as possible into the section. I could read/write to the full shm section from within that utility. I also modified a second C routine which looks for the memory section and returns addresses into the shm section. When attempting to read/write within that second routine the program crashes when accessing addresses more than 4 kB from the start of the shm section. I found this https://www.cygwin.com/ml/cygwin/2009-01/msg00492.html and links from there, which suggest that this 4kB "barrier" is probably related to cygwin's memory handling. If this is in fact a likely source of the problem, is there any way to work around this 4 kB limit while continuing to use the shm library? I can think of using multiple pointers to separate sections (perhaps as a pointer array), but that amounts to an extensive rewrite. -- 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