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=KvO1gxG85fp3wxwZtakZYH9iBdDzlzhJzdyzp7rEkTGcDAZc91y46 5Gl/j5be2PQYYnEVOzeAeLcFgvtuMNazjZmBc66yi0CDDvBBQ5EW1TpLyG58bN6F kcBRMttGqHbEEQGCM/DK40KsL92stjeGreZhOHteyJAS1+axJ+53l8= 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=JSIrj+zpug8k8iehOwt+SiRDvOQ=; b=nhwnn0nz8T47mIfSJvwdKifLW983 WqaD/cA+RRM1RAJMLxeDgjl/4BLugkYOr7CER3mGOWNIG2Yqmn10P7aKmUFjJP9n tqhgPaWxgMgg4Sv0hvhTZocm4swlMESmsrWJXre88RAs33Vm5K7hL7w8WkN5jFM0 EKr5aWxGicVv/rk= 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 X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,TW_MQ autolearn=ham version=3.3.1 Date: Tue, 9 Jul 2013 12:57:24 +0200 From: Corinna Vinschen To: cygwin AT cygwin DOT 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 AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com References: <0d83fe2110ce8c3066becc6ce0f546b1 AT bouldersystemsdesign DOT 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) On Jul 8 12:27, stevetarr AT bouldersystemsdesign DOT 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