From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12211 invoked by alias); 9 Jul 2013 10:57:28 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 12201 invoked by uid 89); 9 Jul 2013 10:57:28 -0000 X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,TW_MQ autolearn=ham version=3.3.1 Received: from aquarius.hirmke.de (HELO calimero.vinschen.de) (217.91.18.234) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Tue, 09 Jul 2013 10:57:27 +0000 Received: by calimero.vinschen.de (Postfix, from userid 500) id DF1ED5200D9; Tue, 9 Jul 2013 12:57:24 +0200 (CEST) Date: Tue, 09 Jul 2013 15:40:00 -0000 From: Corinna Vinschen To: cygwin@cygwin.com Subject: Re: mq_open fails after upgrade from cygwin 1.7.17 with gcc 3.4.4 to cygwin 1.7.20 and gcc 4.7.3 Message-ID: <20130709105724.GB27319@calimero.vinschen.de> Reply-To: cygwin@cygwin.com Mail-Followup-To: cygwin@cygwin.com References: <0d83fe2110ce8c3066becc6ce0f546b1@bouldersystemsdesign.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <0d83fe2110ce8c3066becc6ce0f546b1@bouldersystemsdesign.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-SW-Source: 2013-07/txt/msg00181.txt.bz2 On Jul 8 12:27, stevetarr@bouldersystemsdesign.com wrote: > The following program fails after the upgrade: > > #include > #include > #include > #include > #include > #include > #include > #include > #include > > int main(int argc, char **argv) > { > mqd_t t; > struct mq_attr p; > char *name = "/stuff"; > if ( mq_unlink(name) < 0 ) { > if ( errno != ENOENT ) { > printf("Unink failed - errno = %d\n"); > } > } > t = mq_open(name,O_RDWR|O_CREAT,0666,NULL); > if ( t < 0 ) { ^^^^^^^^ This is the bug. Try if (t == (mqd_t) -1) Here's why. In mqueue.h, mqd_t is defined as follows: typedef intptr_t mqd_t; The mqd_t value returned to you by mq_open is a memory address of an internal datastructure. If the memory address is beyond the 2 Gigs border on 32 bit systems, the returned address is a negative 32 bit integer value. This is what happens when running 32 bit Cygwin under WOW64 on 64 bit machines if the executable has the large-address awareness bit set. That's default when compiling with newer gcc's. In that case, the heap is by default starting at address 0x80000000. So, for instance, if the internal datastructure is allocated at address 0x8003a990, mq_open returns the mqd_t value -2147243632, which is a valid return value. The only value specified as error value is (mqd_t) -1. Every other value is a valid, successful return value. So, bottom line, don't check for < 0, check for (mqd_t) -1. HTH, Corinna -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Maintainer cygwin AT cygwin DOT com Red Hat -- 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