non-portable sigjmp_buf

Neal H. Walfield neal@walfield.org
Thu May 28 07:14:00 GMT 2009


Ping?

At Sat, 02 May 2009 19:34:26 +0200,
Neal H. Walfield wrote:
> 
> Hi,
> 
> I'm using the sigjmp_buf definition in libc/include/machine/setjmp.h
> for my operating system, which runs on the amd64 architecture:
> 
>   typedef int sigjmp_buf[_JBLEN+2];
> 
> There are two issues with this definition that prevent it from
> generalizing.  First, it assumes that _JBLEN is in integer-sized
> units.  This is not always the case: if _JBTYPE is defined, then that
> is the type that should be used (cf. jmp_buf's definition).  Second,
> it assumes that the size of sigset_t is an integer.  This is not
> necessarily the case.  On my system, for instance, sigset_t is a
> 64-bit quantity.  The attach patch corrects both of these problems.
> (The definition is modelled after jmp_buf's definition.)
> 
> There remains a small issue with this approach, which is that on
> 32-bit architectures with 64-bit sigset_t's, sigsetjmp and siglongjmp
> may do an unaligned write or read, respectively, when saving the
> signal mask.  This could be fixed for platforms that decide to use
> these definitions in the future by changing the definition and the
> sigsetjmp and siglongjmp implementation, however, this is rather
> messy.  An alternative is to change the definition of sigjmp_buf to be
> a structure:
> 
>   struct _sigjmp_buf
>   {
>     _JBTYPE buf[_JBLEN];
>     int saved_mask;
>     sigset_t mask;
>   };
>   typedef struct _sigjmp_buf sigjmp_buf[1];
> 
> This is backwards compatible with the current ABI as all users
> currently assume that the size of registers and sigset_t are equal to
> sizeof (int).
> 
> Neal
> 
> 2009-05-02  Neal H. Walfield  <neal@gnu.org>
> 
> 	* libc/include/machine/setjmp.h (sigjmp_buf): Size according to
> 	_JBTYPE and the size of sigset_t.
> 
> --- newlib/newlib/libc/include/machine/setjmp.h	2008-02-29 23:46:46.000000000 +0100
> +++ newlib/newlib/libc/include/machine/setjmp.h~	2008-02-29 23:41:19.000000000 +0100
> @@ -259,7 +259,11 @@
>  #endif
>  
>  /* POSIX sigsetjmp/siglongjmp macros */
> -typedef int sigjmp_buf[_JBLEN+2];
> +#ifdef _JBTYPE
> +typedef _JBTYPE sigjmp_buf[_JBLEN+1+(sizeof (sigset_t)/sizeof (_JBTYPE))];
> +#else
> +typedef int sigjmp_buf[_JBLEN+1+(sizeof (sigset_t)/sizeof (int))];
> +#endif
>  
>  #define _SAVEMASK	_JBLEN
>  #define _SIGMASK	(_JBLEN+1)
> 



More information about the Newlib mailing list