chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-hackers] [PATCH] fix incorrect type of jmp_buf


From: Felix
Subject: Re: [Chicken-hackers] [PATCH] fix incorrect type of jmp_buf
Date: Mon, 17 Jun 2013 09:35:31 +0200 (CEST)

From: Felix <address@hidden>
Subject: [PATCH] fix incorrect type of jmp_buf
Date: Mon, 17 Jun 2013 09:06:11 +0200 (CEST)

> The attached patch fixes a bug in the runtime system: when
> sigsetjmp(3) is used, then "C_restart" and "gc_restart" must be of
> type "sigjmp_buf". Currently they are still declared as "jmp_buf",
> which in most cases will be smaller than a "sigjmp_buf", resulting in
> overwritten memory once a "jmp_buf" is set up.

The patch was not complete. Here a better variant.


cheers,
felix
>From de52f6a04b3d501d0457c824a03b76a6ff64835e Mon Sep 17 00:00:00 2001
From: felix <address@hidden>
Date: Sun, 16 Jun 2013 00:04:55 +0200
Subject: [PATCH] If sigsetjmp(3) is used, "gc_restart" must be of the correct
 type.

---
 chicken.h |    4 ++++
 runtime.c |   20 ++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/chicken.h b/chicken.h
index ce54b3c..fb7418e 100644
--- a/chicken.h
+++ b/chicken.h
@@ -1591,7 +1591,11 @@ C_varextern C_TLS C_long
 C_varextern C_TLS C_byte
   *C_fromspace_top,
   *C_fromspace_limit;
+#ifdef HAVE_SIGSETJMP
+C_varextern C_TLS sigjmp_buf C_restart;
+#else
 C_varextern C_TLS jmp_buf C_restart;
+#endif
 C_varextern C_TLS void *C_restart_address;
 C_varextern C_TLS int C_entry_point_status;
 C_varextern C_TLS int C_gui_mode;
diff --git a/runtime.c b/runtime.c
index 5ce267e..ac45de9 100644
--- a/runtime.c
+++ b/runtime.c
@@ -334,7 +334,11 @@ C_TLS C_long
 C_TLS C_byte 
   *C_fromspace_top,
   *C_fromspace_limit;
+#ifdef HAVE_SIGSETJMP
+C_TLS sigjmp_buf C_restart;
+#else
 C_TLS jmp_buf C_restart;
+#endif
 C_TLS void *C_restart_address;
 C_TLS int C_entry_point_status;
 C_TLS int (*C_gc_mutation_hook)(C_word *slot, C_word val);
@@ -442,7 +446,11 @@ static C_TLS unsigned int
   mutation_count,
   stack_size;
 static C_TLS int chicken_is_initialized;
+#ifdef HAVE_SIGSETJMP
+static C_TLS sigjmp_buf gc_restart;
+#else
 static C_TLS jmp_buf gc_restart;
+#endif
 static C_TLS double
   timer_start_ms,
   gc_ms,
@@ -1908,7 +1916,11 @@ C_word C_fcall C_restore_callback_continuation2(int 
level)
 
 C_word C_fcall C_callback(C_word closure, int argc)
 {
+#ifdef HAVE_SIGSETJMP
+  sigjmp_buf prev;
+#else
   jmp_buf prev;
+#endif
   C_word 
     *a = C_alloc(3),
     k = C_closure(&a, 2, (C_word)callback_return_continuation, C_SCHEME_FALSE);
@@ -1917,7 +1929,11 @@ C_word C_fcall C_callback(C_word closure, int argc)
   if(old && C_block_item(callback_continuation_stack_symbol, 0) == 
C_SCHEME_END_OF_LIST)
     panic(C_text("callback invoked in non-safe context"));
 
+#ifdef HAVE_SIGSETJMP
+  C_memcpy(&prev, &C_restart, sizeof(sigjmp_buf));
+#else
   C_memcpy(&prev, &C_restart, sizeof(jmp_buf));
+#endif
   callback_returned_flag = 0;       
   chicken_is_running = 1;
 
@@ -1931,7 +1947,11 @@ C_word C_fcall C_callback(C_word closure, int argc)
 
   if(!callback_returned_flag) (C_restart_trampoline)(C_restart_address);
   else {
+#ifdef HAVE_SIGSETJMP
+    C_memcpy(&C_restart, &prev, sizeof(sigjmp_buf));
+#else
     C_memcpy(&C_restart, &prev, sizeof(jmp_buf));
+#endif
     callback_returned_flag = 0;
   }
  
-- 
1.7.9.5


reply via email to

[Prev in Thread] Current Thread [Next in Thread]