Subject: bug#47067: 28.0.50; [feature/native-comp] Crash while scrolling through dispnew.c

From: Pip Cet <[email-masked]>
Date: Sun, 14 Mar 2021 12:17:35 +0000

On Sun, Mar 14, 2021 at 12:09 PM Pip Cet <[email-masked]> wrote:
> On Sun, Mar 14, 2021 at 12:07 PM Eli Zaretskii <[email-masked]> wrote:
> > So I think this should be pushed, with the corresponding bump of the
> > ABI version.
>
> I'll prepare a version which actually changes the ABI and bumps the ABI version.

Still don't have a Windows machine (and I gave up on setting up a Wine
environment for Emacs testing), so can someone check this compiles on
WINDOWSNT and avoids the crash?

Any nitpicks would, as always, be appreciated, too!

Pip
From 980929876c9fa6db046eef021854be20a8d49875 Mon Sep 17 00:00:00 2001
From: Pip Cet <[email-masked]>
Date: Sun, 14 Mar 2021 12:13:40 +0000
Subject: [PATCH] Don't call setjmp through a function pointer on Windows
 (bug#47067)

* src/comp.c (ABI_VERSION): Bump.
(emit_setjmp): Call setjmp directly.
(declare_runtime_imported_funcs): Remove setjmp.
(helper_link_table): Remove entry for setjmp.
---
 src/comp.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/src/comp.c b/src/comp.c
index 2ed893cbe0404..7d10f1f2b6926 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -429,7 +429,7 @@ load_gccjit_if_necessary (bool mandatory)
 
 
 /* Increase this number to force a new Vcomp_abi_hash to be generated.  */
-#define ABI_VERSION "3"
+#define ABI_VERSION "4"
 
 /* Length of the hashes used for eln file naming.  */
 #define HASH_LENGTH 8
@@ -654,9 +654,6 @@ #define NUM_CAST_TYPES 15
     helper_PSEUDOVECTOR_TYPEP_XUNTAG,
     pure_write_error,
     push_handler,
-#ifdef WINDOWSNT
-    SETJMP_NAME,
-#endif
     record_unwind_protect_excursion,
     helper_unbind_n,
     helper_save_restriction,
@@ -1972,6 +1969,11 @@ emit_setjmp (gcc_jit_rvalue *buf)
   return gcc_jit_context_new_call (comp.ctxt, NULL, f, 1, args);
 #else
   /* _setjmp (buf, __builtin_frame_address (0)) */
+  gcc_jit_param *params[] =
+  {
+    gcc_jit_context_new_param (comp.ctxt, NULL, comp.void_ptr_type, "buf"),
+    gcc_jit_context_new_param (comp.ctxt, NULL, comp.void_ptr_type, "frame"),
+  };
   gcc_jit_rvalue *args[2];
 
   args[0] =
@@ -1985,8 +1987,14 @@ emit_setjmp (gcc_jit_rvalue *buf)
 					    "__builtin_frame_address"),
       1, args);
   args[0] = buf;
-  return emit_call (intern_c_string (STR (SETJMP_NAME)), comp.int_type, 2, args,
-                    false);
+  gcc_jit_function *f =
+    gcc_jit_context_new_function (comp.ctxt, NULL,
+				  GCC_JIT_FUNCTION_IMPORTED,
+				  comp.int_type, STR (SETJMP_NAME),
+				  ARRAYELTS (params), params,
+				  false);
+
+  return gcc_jit_context_new_call (comp.ctxt, NULL, f, 2, args);
 #endif
 }
 
@@ -2701,12 +2709,6 @@ #define ADD_IMPORTED(f_name, ret_type, nargs, args)			       \
   args[1] = comp.int_type;
   ADD_IMPORTED (push_handler, comp.handler_ptr_type, 2, args);
 
-#ifdef WINDOWSNT
-  args[0] = gcc_jit_type_get_pointer (gcc_jit_struct_as_type (comp.jmp_buf_s));
-  args[1] = comp.void_ptr_type;
-  ADD_IMPORTED (SETJMP_NAME, comp.int_type, 2, args);
-#endif
-
   ADD_IMPORTED (record_unwind_protect_excursion, comp.void_type, 0, NULL);
 
   args[0] = comp.lisp_obj_type;
-- 
2.30.1