alignment bug in birnetcdefs.h

View: New views
2 Messages — Rating Filter:   Alert me  

alignment bug in birnetcdefs.h

by Sam Hocevar :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

   birnetcdefs.h has the following declaration:

typedef union {
  void       *cond_pointer;
  BirnetUInt8 cond_dummy[MAX (8, BIRNET_SIZEOF_PTH_COND_T)];
} BirnetCond;

   On 32-bit systems, this union is 32-bit aligned. The problem
is that it is cast to a pthread_cond_t* pointer, for instance in
birnetthreadimpl.cc, yet there is no knowledge about the pthread_cond_t
alignment requirements. It causes crashes for instance on the sparc
platform where pthread_cond_t has 64-bit members and thus requires
64-bit alignment.

   I suggest this simple solution. It may waste a few bytes on some
platforms, but that is certainly negligible:

typedef union {
  void         *cond_pointer;
  BirnetUInt8   cond_dummy[MAX (8, BIRNET_SIZEOF_PTH_COND_T)];
  long long int align;
} BirnetCond;

   I of course suggest doing the same to BirnetMutex.

Cheers,
--
Sam.
_______________________________________________
beast mailing list
beast@...
http://mail.gnome.org/mailman/listinfo/beast

Re: alignment bug in birnetcdefs.h

by Stefan Westerfeld :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

   Hi!

Thank, Tim has implemeted your bugfix idea.

   Cu... Stefan

On Sat, Feb 09, 2008 at 03:29:58PM +0100, Sam Hocevar wrote:

>    birnetcdefs.h has the following declaration:
>
> typedef union {
>   void       *cond_pointer;
>   BirnetUInt8 cond_dummy[MAX (8, BIRNET_SIZEOF_PTH_COND_T)];
> } BirnetCond;
>
>    On 32-bit systems, this union is 32-bit aligned. The problem
> is that it is cast to a pthread_cond_t* pointer, for instance in
> birnetthreadimpl.cc, yet there is no knowledge about the pthread_cond_t
> alignment requirements. It causes crashes for instance on the sparc
> platform where pthread_cond_t has 64-bit members and thus requires
> 64-bit alignment.
>
>    I suggest this simple solution. It may waste a few bytes on some
> platforms, but that is certainly negligible:
>
> typedef union {
>   void         *cond_pointer;
>   BirnetUInt8   cond_dummy[MAX (8, BIRNET_SIZEOF_PTH_COND_T)];
>   long long int align;
> } BirnetCond;
>
>    I of course suggest doing the same to BirnetMutex.
--
Stefan Westerfeld, Hamburg/Germany, http://space.twc.de/~stefan
_______________________________________________
beast mailing list
beast@...
http://mail.gnome.org/mailman/listinfo/beast
LightInTheBox - Buy quality products at wholesale price