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:to:subject:message-id:reply-to :references:mime-version:content-type:in-reply-to; q=dns; s= default; b=OR1A55DQ6nCpJjXikCGGV3scMTSHr+1HaT7L45RFtx1LIviqhCGsw O6JS+J8MHn20ubKn7RwOrX8T+VbRyaYiTPGo2+cMpBh3XumNxfNlNW/qNMW2Xmb8 gp8WGy1yECJS20DeoqZ6Xe8AEF5bU4TnwL1eHqi9yw+p9VcSXepI0Y= 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:to:subject:message-id:reply-to :references:mime-version:content-type:in-reply-to; s=default; bh=ZGc2mId0AuKnoiXX/oaa7yolZaQ=; b=jwCUJLEL3macroBDXxqqW40sos7d tZQS4GOy6zHZuKcZxQXDxgzsQNrdX5WJjblk1Udjnz5gTEpFKOual/eEBwru0TBi HOQZDgLL1e4WLkjbqJp+zCzGdGm4RxBvodYcJvs96f+7Klc0cd6b16fgGAycAkGw CixxZMUAXnBCALg= 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=-6.0 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2 X-HELO: calimero.vinschen.de Date: Thu, 30 Jan 2014 13:45:58 +0100 From: Corinna Vinschen To: cygwin AT cygwin DOT com Subject: Re: second call to mmap() results in error Message-ID: <20140130124558.GA2821@calimero.vinschen.de> Reply-To: cygwin AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com References: <01a801cf1cfa$77957900$66c06b00$@lbmsys.com> <20140129181250 DOT GW2821 AT calimero DOT vinschen DOT de> <52E95786 DOT 8050606 AT gmail DOT com> <20140130095822 DOT GY2821 AT calimero DOT vinschen DOT de> <001801cf1db6$66c47c40$344d74c0$@lbmsys.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="hTKW8p8tUZ/8vLMe" Content-Disposition: inline In-Reply-To: <001801cf1db6$66c47c40$344d74c0$@lbmsys.com> User-Agent: Mutt/1.5.21 (2010-09-15) --hTKW8p8tUZ/8vLMe Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 getti= ng > > an > > > >>error ("No such device") on the second call to mmap(). The first ca= ll > > works > > > >>fine. > >=20 > > 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. > >=20 > >=20 > > 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? > >=20 > >=20 > > Corinna >=20 > I reinstalled Cygwin, rebooted and the error persisted. Running 'gdb' and > stepping through the program showed that the call to mmap() fails for /bl= ock1 > also -- it is returning an invalid address. This simplification of the pr= ogram > shows that error on my machine ('Bus error (core dumped)' ) occurs > when it tries to do the memcpy() to the mapped address. Try this: > #include > #include #include > #include > #include > #include > #include > #include >=20 > int main() > { > int shm_fd1; > char *mmap1; > shm_fd1 =3D shm_open("/block1", O_CREAT | O_RDWR, 0666); > if (shm_fd1 =3D=3D -1) { > fprintf(stderr, "Couldn't get fd for block1 (%s)\n", strerror(errno)); > exit(1); > } > ftruncate(shm_fd1, 524304); > mmap1 =3D mmap(NULL, 524304, PROT_WRITE | PROT_READ, MAP_SHARED, shm_fd= 1, 0); > if (mmap1 =3D=3D (char *)-1) { > fprintf(stderr, "Couldn't map memory for /block1 (%s)\n", strerror(er= rno)); > exit(1); > } > memcpy(mmap1, "ABCDEF\0", 7); > fprintf(stdout, mmap1); >=20 > fprintf(stdout, "Shared memory initialized\n"); > exit(0); > } 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 --=20 Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Maintainer cygwin AT cygwin DOT com Red Hat --hTKW8p8tUZ/8vLMe Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJS6kmGAAoJEPU2Bp2uRE+gEAQP/Rb7FF/efOTAq9vdv82wcQ0w tQaeHnL0ciP0kcUC/C+eKJeywh3Wt1pYkYhM7Z148o/3o6F/LXv8QCWyb4mY7vNC WrixwQtrJnsCLJEte53SxKqJgSTuYH7g3F6QAuqnVlcBnumzN2Ng5PpLzpy9Ncx9 Iy+D2sayUhB6GFRBOtOY2/AjplQEitryRguA/YbnaCpkHv8KnSJ5JbYIy1a73jhj 3UGFAgSVs1BsBYyOs7JiPOksm59Znu6HPadlvh1h9LzXQpnzMKuIQWPrg8fENzXJ k+gRhKT1/CrAT9Ts7DqPIdyRntVHiSR58e9bm1K49UjmunQ8YlthoPJepUj/0FYg xVABSxQZLeHVv7fNZrmMOfXkM09b0Lh1Lg2G3ZXoMqbjb7DWzI0KnLqDneLdHpwT FC3fOWCLQ1didZ1NB2s0G4uXIYqpW3eeOE8PvXJhBFbAj5B3tIISXrqy8KAE39w8 lDrNgV3UZBTmO+IVk4Gv4tA0cdW7Bd3726CkhXVzRFBUdCqx71Y0F/4RTYRllJHi ZHhJf13cPzdDcUeyXbw16C1MgOlU7m7nnw5xBo/k/pv7d8mIMRJAlkDJGCHSUpbk 12u/Q07mF4Rc2p6QKIoPipOoeEqs3M+z2HiFuM6UCQ31ZHHJ3via9WQiOXPvUbF+ QUGeMggB+z5ec6zi30U1 =kIS+ -----END PGP SIGNATURE----- --hTKW8p8tUZ/8vLMe--