aboutsummaryrefslogtreecommitdiff
path: root/ports/libffi/win32-disable-stackframe-check.patch
blob: 8fdca8b011ff19a2145b11be525a6e745b425014 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Rolf Gebhardt <rolf.gebhardt@lbs-sw.de>
22 Jul 2020
[PATCH] x86/win32: disable runtime stack frame checks with msvc
 around built assembly

based on the patch for x86/win64:

From 53291b332b1bc061a3409d3b60c38f313609b98e Mon Sep 17 00:00:00 2001
From: Matthew Waters <matthew@centricular.com>
Date: Fri, 16 Mar 2018 15:10:04 +1100
Subject: [PATCH] x86/win64: disable runtime stack frame checks with msvc
 around built assembly

MSVC can add truntime code that checks if a stack frame is mismanaged
however our custom assembly delibrately accesses and modifies the parent
stack frame.  Fortunately we can disable that specific check for the
function call so do that.
---
 src/x86/ffi.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/x86/ffi.c b/src/x86/ffi.c
index 9a59218..9f5d703 100644
--- a/src/x86/ffi.c
+++ b/src/x86/ffi.c
@@ -255,6 +255,14 @@ static const struct abi_params abi_params[FFI_LAST_ABI] = {

 extern void FFI_DECLARE_FASTCALL ffi_call_i386(struct call_frame *, char *) FFI_HIDDEN;

+/* we perform some black magic here to use some of the parent's
+ * stack frame in ff_call_win() that breaks with the msvc compiler
+ * with the /RTCs or /GZ flags.  Disable the 'Stack frame run time
+ * error checking' for this function so we don't hit weird exceptions
+ * in debug builds */
+#if defined(_MSC_VER)
+#pragma runtime_checks("s", off)
+#endif
 static void
 ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue,
              void **avalue, void *closure)
@@ -390,6 +398,9 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue,

   ffi_call_i386 (frame, stack);
 }
+#if defined(_MSC_VER)
+#pragma runtime_checks("s", restore)
+#endif

 void
 ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)