Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm 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 Reply-To: From: "Shane Mann" To: "Cygwin AT Cygwin. Com" Subject: MMap offset parameter failing with ENOMEM error Date: Thu, 19 Sep 2002 12:19:06 +1000 Message-ID: <000b01c25f82$ee240380$8e90a8c0@citr.com.au> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_000C_01C25FD6.BFD01380" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Importance: Normal X-MailScanner: Found to be clean Note-from-DJ: This may be spam ------=_NextPart_000_000C_01C25FD6.BFD01380 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hi, I am having trouble with mmap using the last 'offset' parameter. I have attached a small piece of code (and sample file) which demonstrates the problem. Basically if the offset parameter is passed as a variable to mmap then the call fails with an ENOMEM error. But if you pass 0 as the parameter and then access the return address from mmap + offset - it is fine. My question: is mmap handling the offset parameter correctly? Usage for the program: ./a.exe eg: ./a.exe 11200 index.idx To see the address + offset work, comment out the first mmap call and return statement and uncomment the lines below each one. Any help appreciated. Regards, Shane Shane Mann Software Engineer Phone: +61-7-3259-2223 LeadUp Software Pty Ltd Fax: +61-7-3259-2259 339 Coronation Drive, Email: shane DOT mann AT leadup DOT com DOT au Milton, QLD, 4064 Web: http://www.leadup.com.au ------=_NextPart_000_000C_01C25FD6.BFD01380 Content-Type: application/octet-stream; name="mmap_file2.c" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="mmap_file2.c" #include =0A= #include =0A= #include =0A= #include =0A= #include =0A= #include =0A= #include =0A= #include =0A= #include =0A= =0A= #define PAGEPROT PROT_READ|PROT_WRITE=0A= #define MAPFLAGS MAP_PRIVATE|MAP_ANONYMOUS=0A= =0A= static int syspagesize =3D 0, pagemask, offmask, error_cnt =3D 0;=0A= =0A= void sigsegv(int unused)=0A= {=0A= _exit(0);=0A= }=0A= =0A= caddr_t femmap(int fd, off_t foff, size_t syz, int prot, u_char *msg) {=0A= /* femmap() and femunmap() take care of the need to allocate=0A= on page boundaries and in multiples of pages. */=0A= off_t pfoff; /* foff on a page boundary */=0A= size_t psyz; /* syz rounded up to full pages */=0A= int chopped;=0A= caddr_t rslt;=0A= if (syspagesize =3D=3D 0) {=0A= syspagesize =3D getpagesize();=0A= offmask =3D syspagesize - 1;=0A= pagemask =3D ~offmask;=0A= if (1) printf("--- Syspagesize %d, pagemask %X, offmask %X\n",=0A= syspagesize, pagemask, offmask);=0A= }=0A= printf("foff is %d\n", foff);=0A= printf("--- Syspagesize %d, pagemask %X, offmask %X\n",=0A= syspagesize, pagemask, offmask);=0A= pfoff =3D foff & pagemask;=0A= printf("pfoff is %d\n", pfoff);=0A= chopped =3D foff & offmask;=0A= psyz =3D (syz + chopped + syspagesize - 1) & pagemask;=0A= =0A= printf("**** Vars just before mmap call ****\n");=0A= printf("psyz =3D %d\nprot =3D %d\nfd =3D %d\npfoff =3D %d\n", psyz, = prot, fd, (int)pfoff);=0A= =0A= if ((rslt =3D mmap(0, psyz, prot, MAP_SHARED, fd, pfoff)) = =3D=3DMAP_FAILED) {=0A= /* if ((rslt =3D mmap(0, psyz, prot, MAP_SHARED, fd, 0)) = =3D=3DMAP_FAILED) {=0A= */=0A= printf("perror reports errno of %d\n", errno);=0A= printf(" Mapping %d at %X <---> %d (%s\n", psyz, (int)rslt, = (int)pfoff,=0A= msg);=0A= error_cnt++;=0A= exit(1);=0A= }=0A= if (1)=0A= printf(" Mapping %d at %X <---> %d (%s\n", psyz, (int)rslt, = (int)pfoff,=0A= msg);=0A= return (rslt + chopped);=0A= /* return (rslt + chopped + pfoff);=0A= */=0A= }=0A= =0A= int main(int argc, char **argv)=0A= {=0A= int fh;=0A= off_t foff;=0A= size_t syz;=0A= int prot;=0A= u_char *msg;=0A= int i;=0A= off_t size;=0A= u_char *result =3D NULL;=0A= =0A= struct stat finfo;=0A= =0A= foff =3D atoi(argv[1]);=0A= printf("Offset is %d\n", foff);=0A= =0A= for (i=3D2; i