Skip to content

Commit fe93400

Browse files
committed
Get sqSetjmpShim.h right on Windows for at least ARMv8 and x86_64.
(I need the CI to test x86). Make sqSetjmpShim.h include <setjmp.h>. Modify the Alien callback support to include sqSetjmpShim.h, not <setjmp.h>.
1 parent 3de73a9 commit fe93400

File tree

13 files changed

+68
-45
lines changed

13 files changed

+68
-45
lines changed

platforms/Cross/plugins/IA32ABI/arm32abicc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
#include <sys/mman.h> /* for mprotect */
2222

2323
#include <string.h> /* for memcpy et al */
24-
#include <setjmp.h>
2524
#include <stdio.h> /* for fprintf(stderr,...) */
2625

26+
#include "sqSetjmpShim.h"
27+
2728
#include "objAccess.h"
2829
#include "vmCallback.h"
2930
#include "sqAssert.h"

platforms/Cross/plugins/IA32ABI/arm64abicc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727

2828
#include <stdlib.h> // for valloc
2929
#include <string.h> // for memcpy et al
30-
#include <setjmp.h>
3130
#include <stdio.h> // for fprintf(stderr,...)
3231

32+
#include "sqSetjmpShim.h"
33+
3334
#include "objAccess.h"
3435
#include "vmCallback.h"
3536
#include "sqAssert.h"

platforms/Cross/plugins/IA32ABI/ia32abi.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
* the downward-growing stack.
2626
*/
2727

28-
#include "sqSetjmpShim.h"
29-
3028
// Obsolete Alien call-out API, still used for the exampleCqsort example
3129

3230
#define SIGNATURE sqInt *argVector/* call args on stack or in array */, \
@@ -39,7 +37,7 @@ extern sqInt callIA32FloatReturn (SIGNATURE);
3937
extern sqInt callIA32DoubleReturn (SIGNATURE);
4038

4139

42-
// Not at all obslete callback thunk facilities.
40+
// Not at all obsolete callback thunk facilities.
4341
// A callback is a pairing of a Smalltalk block and an Alien pointing to a
4442
// thunk (a sequence of machine code) at a unique address, each callback
4543
// having exactly the same thunk but at a different address. The thunk calls

platforms/Cross/plugins/IA32ABI/ia32abicc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ void *getbaz() { return baz; }
3333
#endif
3434

3535
#include <string.h> /* for memcpy et al */
36-
#include <setjmp.h>
3736
#include <stdio.h> /* for fprintf(stderr,...) */
3837

38+
#include "sqSetjmpShim.h"
39+
3940
#include "objAccess.h"
4041
#include "vmCallback.h"
4142
#include "sqAssert.h"

platforms/Cross/plugins/IA32ABI/ppc32abicc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,13 @@ void *getbaz() { return baz; }
6060
#include <string.h>
6161
#include <unistd.h>
6262

63+
#include "sqSetjmpShim.h"
64+
6365
#include "objAccess.h"
66+
#include "vmCallback.h"
67+
#include "sqAssert.h"
6468
#include "ia32abi.h"
6569

66-
#include <setjmp.h>
67-
6870
#if !defined(min)
6971
# define min(a,b) ((a) < (b) ? (a) : (b))
7072
#endif

platforms/Cross/plugins/IA32ABI/riscv64abicc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@
3636
#include <stdlib.h> // for valloc
3737
#include <sys/mman.h> // for mprotect
3838
#include <string.h> // for memcpy et al
39-
#include <setjmp.h>
4039
#include <stdio.h> // for fprintf(stderr,...)
4140

41+
#include "sqSetjmpShim.h"
42+
4243
#include "objAccess.h"
4344
#include "vmCallback.h"
4445
#include "sqAssert.h"

platforms/Cross/plugins/IA32ABI/x64sysvabicc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ void *getbaz() { return baz; }
4040
#endif
4141

4242
#include <string.h> /* for memcpy et al */
43-
#include <setjmp.h>
4443
#include <stdio.h> /* for fprintf(stderr,...) */
4544

45+
#include "sqSetjmpShim.h"
46+
4647
#include "objAccess.h"
4748
#include "vmCallback.h"
4849
#include "sqAssert.h"

platforms/Cross/plugins/IA32ABI/x64win64abicc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818

1919
#include <stdlib.h> /* for valloc */
2020
#include <string.h> /* for memcpy et al */
21-
#include <setjmp.h>
2221
#include <stdio.h> /* for fprintf(stderr,...) */
2322

23+
#include "sqSetjmpShim.h"
24+
2425
#include "objAccess.h"
2526
#include "vmCallback.h"
2627
#include "sqAssert.h"

platforms/Cross/plugins/JPEGReadWriter2Plugin/sqJPEGReadWriter2Plugin.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*/
3030
#include <stdio.h> /* abs */
3131
#include <stdlib.h> /* abs */
32+
#include "sqSetjmpShim.h"
3233
#include "JPEGReadWriter2Plugin.h"
3334

3435
/*
@@ -322,5 +323,5 @@ void
322323
error_exit (j_common_ptr cinfo)
323324
{
324325
/* cinfo->err really points to a error_mgr2 struct, so coerce the pointer */
325-
longjmp(*((error_ptr2)(cinfo->err))->setjmp_buffer, 1);
326+
_longjmp(*((error_ptr2)(cinfo->err))->setjmp_buffer, 1);
326327
}

platforms/Cross/vm/sqSetjmpShim.h

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* sqSetjmpShim.h
22
*
3-
* Defines to ensure we use the most minimal version of setjmp/longjmp
3+
* Defines to ensure the VM uses the most minimal version of setjmp/longjmp
44
* available on the platform to avoid issues with stack unwinding.
55
*
66
* Author: Eliot Miranda
@@ -27,22 +27,32 @@
2727
* DEALINGS IN THE SOFTWARE.
2828
*/
2929

30-
/* Use the most minimal setjmp/longjmp pair available; no signal handling
31-
* wanted or necessary. On win64 to avoid crashes when unwinding the stack in
32-
* Kernel32's longjmp we use the pair in platforms/win32/misc/_setjmp-x64.asm.
30+
#if !defined(__SETJMP_SHIM)
31+
#define __SETJMP_SHIM
32+
33+
#include <setjmp.h>
34+
35+
/* Use the most minimal setjmp/longjmp pair available; unix signal(3) handling
36+
* intentionally avoided. On win64 to avoid crashes when unwinding the stack in
37+
* Kernel32's longjmp use the pairs in platforms/win32/misc/_setjmp-???.asm.
3338
*/
34-
#if !defined(_WIN32)
35-
# undef setjmp
36-
# undef longjmp
37-
# define setjmp _setjmp
38-
# define longjmp _longjmp
39-
#endif
40-
/* clang on mingw redeclares _setjmp so we have to provide an alternative */
41-
#if __MINGW32__ || __MINGW64__ /* clang on cygwin/mingw */
42-
int __attribute__((__nothrow__,__returns_twice__)) _setjmp0(jmp_buf);
43-
# undef _setjmp
39+
#undef setjmp
40+
#undef _setjmp
41+
#undef longjmp
42+
#undef _longjmp
43+
#define setjmp(b) _setjmp(b)
44+
#define longjmp(b,v) _longjmp(b,v)
45+
46+
#if defined(_WIN32) || defined(_WIN64)
47+
// Windows clang redeclares _setjmp so provide an alternative
4448
# define _setjmp(b) _setjmp0(b)
45-
# undef longjmp
46-
# define longjmp _longjmp
47-
void _longjmp(_JBTYPE *, int); /* setjmp.h only declares __mingw_longjmp via longjmp */
48-
#endif
49+
# if defined(__GNUC__) || defined(__clang__)
50+
int __attribute__((__nothrow__,__returns_twice__)) __cdecl _setjmp0(jmp_buf jb);
51+
void __attribute__((_Noreturn)) __cdecl _longjmp(jmp_buf jb,int v);
52+
# else
53+
int __cdecl _setjmp0(jmp_buf jb);
54+
void __declspec(noreturn) __cdecl _longjmp(jmp_buf jb,int v);
55+
# endif
56+
#endif // _WIN32 || _WIN64
57+
58+
#endif // __SETJMP_SHIM

0 commit comments

Comments
 (0)