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: 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


On Jul  8 12:27, stevetarr@bouldersystemsdesign.com wrote:
> The following program fails after the upgrade:
> 
> #include <stdio.h>
> #include <sys/time.h>
> #include <sys/resource.h>
> #include <errno.h>
> #include <stdlib.h>
> #include <fcntl.h>
> #include <sys/stat.h>
> #include <sys/types.h>
> #include <mqueue.h>
> 
> 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


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