On Wed, Sep 10, 2003 at 02:17:50PM -0700, John Meacham wrote:
>On Wed, Sep 10, 2003 at 03:37:57PM -0400, John Dennis wrote:
>> 1) It may be hard to know the alignment requirements for all OS's and
>> architectures (thats part of the reason we have system header
>> files). We could guess 16 byte is sufficient. But even if we got the
>> alignment requirement right how do we specify the alignment requirement
>> to the compiler in a portable way such that it will build on a variety
>> of systems and compilers? My understanding is that compiler alignment
>> directives are not portable (e.g. not part of ANSI C). Are we
>> comfortable picking one or two common alignment directives and
>> conditionally compiling with the right one?
>
>Since we already have a jmp_buf which is much larger than necisarry, all
>that is needed is to take the first offset into it which is properly
>aligned for the given architecture and use that as the system jmp_buf.
>when the compiler can guarentee the proper alignment this becomes a
>'nop', otherwise we waste at most alignment - sizeof(intmax_t) - 1
>bytes. not a big deal. best of all, this can be implemented portably
>quite easily.

The attached patch is one way this could be done.  I've set the alignment
higher than it probably needs to be.

David
-- 
David Dawes                                     X-Oz Technologies
www.XFree86.org/~dawes                          www.x-oz.com
Index: loader/xf86sym.c
===================================================================
RCS file: /home/x-cvs/xc/programs/Xserver/hw/xfree86/loader/xf86sym.c,v
retrieving revision 1.235
diff -u -r1.235 xf86sym.c
--- loader/xf86sym.c    24 Aug 2003 19:58:05 -0000      1.235
+++ loader/xf86sym.c    12 Sep 2003 15:07:52 -0000
@@ -907,6 +907,7 @@
    SYMFUNC(xf86setjmp1)
 #endif
    SYMFUNCALIAS("xf86longjmp",longjmp)
+   SYMFUNCALIAS("xf86longjmp0",longjmp)
    SYMFUNC(xf86getjmptype)
    SYMFUNC(xf86setjmp1_arg2)
    SYMFUNC(xf86setjmperror)
Index: os-support/xf86_ansic.h
===================================================================
RCS file: /home/x-cvs/xc/programs/Xserver/hw/xfree86/os-support/xf86_ansic.h,v
retrieving revision 3.51
diff -u -r3.51 xf86_ansic.h
--- os-support/xf86_ansic.h     24 Aug 2003 17:37:03 -0000      3.51
+++ os-support/xf86_ansic.h     12 Sep 2003 15:15:36 -0000
@@ -312,10 +312,19 @@
 extern int xf86setjmperror(xf86jmp_buf env);
 extern int xf86getjmptype(void);
 extern void xf86longjmp(xf86jmp_buf env, int val);
+extern void xf86longjmp0(xf86jmp_buf env, int val);
+
+#define jb_align(env) \
+       ((int *)(((((unsigned long)(env)) + JMP_BUF_ALIGN - 1) / \
+               JMP_BUF_ALIGN) * JMP_BUF_ALIGN))
+
 #define xf86setjmp_macro(env) \
-       (xf86getjmptype() == 0 ? xf86setjmp0((env)) : \
-       (xf86getjmptype() == 1 ? xf86setjmp1((env), xf86setjmp1_arg2()) : \
-               xf86setjmperror((env))))
+       (xf86getjmptype() == 0 ? xf86setjmp0(jb_align(env)) : \
+       (xf86getjmptype() == 1 ? xf86setjmp1(jb_align(env), xf86setjmp1_arg2()) : \
+               xf86setjmperror(jb_align(env))))
+
+#define xf86longjmp_macro(env, val) \
+       xf86longjmp(jb_align(env), val)
 
 #else /* XFree86LOADER || NEED_XF86_PROTOTYPES */
 #include <unistd.h>
Index: os-support/xf86_libc.h
===================================================================
RCS file: /home/x-cvs/xc/programs/Xserver/hw/xfree86/os-support/xf86_libc.h,v
retrieving revision 3.57
diff -u -r3.57 xf86_libc.h
--- os-support/xf86_libc.h      24 Aug 2003 17:37:03 -0000      3.57
+++ os-support/xf86_libc.h      12 Sep 2003 15:19:33 -0000
@@ -95,7 +95,9 @@
 typedef int xf86key_t;
 
 /* setjmp/longjmp */
-typedef int xf86jmp_buf[1024];
+#define JMP_BUF_SIZE 4096
+#define JMP_BUF_ALIGN 4096
+typedef int xf86jmp_buf[(JMP_BUF_SIZE + JMP_BUF_ALIGN) / sizeof(int)];
 
 /* for setvbuf */
 #define XF86_IONBF    1
@@ -688,7 +690,7 @@
 #undef setjmp
 #define setjmp(a)               xf86setjmp_macro(a)
 #undef longjmp
-#define longjmp(a,b)            xf86longjmp(a,b) 
+#define longjmp(a,b)            xf86longjmp_macro(a,b) 
 #undef jmp_buf
 #define jmp_buf                 xf86jmp_buf
 #endif

Reply via email to