emacs-diffs
[Top][All Lists]
Advanced

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

scratch/comp-static-data b67b328d6ab 16/16: Pin native comp units with s


From: Vibhav Pant
Subject: scratch/comp-static-data b67b328d6ab 16/16: Pin native comp units with static objects for now.
Date: Thu, 19 Jan 2023 12:44:47 -0500 (EST)

branch: scratch/comp-static-data
commit b67b328d6ab7e833b58156283b4f79fa8da7bdda
Author: Vibhav Pant <vibhavp@gmail.com>
Commit: Vibhav Pant <vibhavp@gmail.com>

    Pin native comp units with static objects for now.
    
    * src/alloc.c (pin_object): New function.
    * src/comp.c (register_native_comp_unit): If the unit contains static
    lisp objects, pin it to avoid use-after-free crashes if heap allocated
    objects in static objects don't get marked.
---
 src/alloc.c | 12 ++++++++++--
 src/comp.c  |  5 +++++
 src/lisp.h  |  1 +
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/alloc.c b/src/alloc.c
index b05eb347c22..58e7c4bc4aa 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -6243,6 +6243,15 @@ compact_undo_list (Lisp_Object list)
   return list;
 }
 
+void
+pin_object (Lisp_Object obj)
+{
+  struct pinned_object *o = xmalloc (sizeof *o);
+  o->object = obj;
+  o->next = pinned_objects;
+  pinned_objects = o;
+}
+
 static void
 mark_pinned_objects (void)
 {
@@ -6847,8 +6856,7 @@ mark_char_table (struct Lisp_Vector *ptr, enum pvec_type 
pvectype)
     }
 }
 
-static void
-mark_stack_push_values (Lisp_Object *values, ptrdiff_t n);
+static void mark_stack_push_values (Lisp_Object *values, ptrdiff_t n);
 
 static void
 mark_native_comp_unit (struct Lisp_Vector *ptr)
diff --git a/src/comp.c b/src/comp.c
index 7185a0a4029..a2cb51180cd 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -7676,6 +7676,11 @@ register_native_comp_unit (Lisp_Object comp_u)
 {
   Fputhash (
     XNATIVE_COMP_UNIT (comp_u)->file, comp_u, Vcomp_loaded_comp_units_h);
+  /* TODO: This is a hack to avoid use-after-free issues with
+     heap-allocated objects being in static objects not getting marked
+     after a native comp unit is freed.  */
+  if (XNATIVE_COMP_UNIT (comp_u)->have_static_lisp_data)
+    pin_object (comp_u);
 }
 
 
diff --git a/src/lisp.h b/src/lisp.h
index e33c08958ab..ce4493c3b2d 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4257,6 +4257,7 @@ extern void alloc_unexec_post (void);
 extern void mark_c_stack (char const *, char const *);
 extern void flush_stack_call_func1 (void (*func) (void *arg), void *arg);
 extern void mark_memory (void const *start, void const *end);
+extern void pin_object (Lisp_Object obj);
 #ifdef HAVE_STATIC_LISP_GLOBALS
 extern bool static_comp_object_p (Lisp_Object obj);
 #else



reply via email to

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