This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: second call to mmap() results in error


On Jan 30 08:19, Steven Bardwell wrote:
> > On Jan 30 07:25, Steven Bardwell wrote:
> > > > > On 29/01/2014 19:12, Corinna Vinschen wrote:
> > > > > >On Jan 29 09:00, Steven Bardwell wrote:
> > > > > >>My application needs several areas of shared memory, and I am
> > getting
> > > > an
> > > > > >>error ("No such device") on the second call to mmap(). The first call
> > > > works
> > > > > >>fine.
> > > >
> > > > Sorry guys, but it still works fine for me.  I tried your testcase on W7
> > > > 32, W7 64 in 32 and 64 bit, and on Windows 8.1 64 in 32 and 64 bit.  I
> > > > tried it with Cygwin 1.7.27 and with the latest snapshot.  I'm always
> > > > getting the output "Shared memory initialized" and no error at all.
> > > >
> > > >
> > > > Any chance one of you guys could debug this further, by stepping
> > through
> > > > the Cygwin mmap64 function, preferredly using the latest snapshot or,
> > > > a self-built Cygwin DLL from?
> > > >
> > > >
> > > > Corinna
> > >
> > > I reinstalled Cygwin, rebooted and the error persisted. Running 'gdb' and
> > > stepping through the program showed that the call to mmap() fails for
> > /block1
> > > also -- it is returning an invalid address. This simplification of the program
> > > shows that error on my machine ('Bus error (core dumped)' ) occurs
> > > when it tries to do the memcpy() to the mapped address.
> > The reason is that ftruncate is defined with the second argument being
> > off_t, which is 8 byte.  524304 is an int (4 byte) only, though.  Since
> > ftruncate is declared in unistd.h, but you didn't include unistd.h, the
> > 2nd parameter to ftruncate is auto-propagated to int, which results in
> > an invalid new file length, and which makes ftruncate fail.  Since you
> > missed to check ftruncate's return value... you get the idea.
> > 
> > 
> > Corinna
> 
> Thanks so much for wasting your time debugging my program. 
> 
> Adding the <unistd.h> fixes the problem in all its iterations -- the original mmap() 
> test works (without the call to ftruncate()), as well as the second one. 

I'm glad to read that.

> You all run a great technical support operation.

I'm glad you think that.


:)
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

Attachment: pgplS2NOK2gXq.pgp
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]