From 4fba79feee58e074d112bb47467913f9aec089c7 Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Wed, 10 Feb 2021 21:48:19 +0100 Subject: [PATCH] Add late load pdumper hooks so these can call into Lisp * src/pdumper.h (pdumper_do_now_and_after_late_load): New function. * src/pdumper.c (dump_late_hooks, nr_dump_late_hooks): New static variables. (dump_metadata_for_pdumper): Add support for late load hooks. (pdumper_do_now_and_after_late_load_impl): New functions. (pdumper_load): Add support for late load hooks. * src/window.c (init_window_once): Register 'init_window_once_for_pdumper' to be executed after late load. --- src/pdumper.c | 24 ++++++++++++++++++++++++ src/pdumper.h | 13 +++++++++++++ src/window.c | 2 +- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/pdumper.c b/src/pdumper.c index f0711078a5a..1f1f6e05df4 100644 --- a/src/pdumper.c +++ b/src/pdumper.c @@ -121,6 +121,9 @@ static const char dump_magic[16] = { static pdumper_hook dump_hooks[24]; static int nr_dump_hooks = 0; +static pdumper_hook dump_late_hooks[24]; +static int nr_dump_late_hooks = 0; + static struct { void *mem; @@ -3245,6 +3248,12 @@ dump_metadata_for_pdumper (struct dump_context *ctx) (void const *) dump_hooks[i]); dump_emacs_reloc_immediate_int (ctx, &nr_dump_hooks, nr_dump_hooks); + for (int i = 0; i < nr_dump_late_hooks; ++i) + dump_emacs_reloc_to_emacs_ptr_raw (ctx, &dump_late_hooks[i], + (void const *) dump_late_hooks[i]); + dump_emacs_reloc_immediate_int (ctx, &nr_dump_late_hooks, + nr_dump_late_hooks); + for (int i = 0; i < nr_remembered_data; ++i) { dump_emacs_reloc_to_emacs_ptr_raw (ctx, &remembered_data[i].mem, @@ -4316,6 +4325,15 @@ pdumper_do_now_and_after_load_impl (pdumper_hook hook) hook (); } +void +pdumper_do_now_and_after_late_load_impl (pdumper_hook hook) +{ + if (nr_dump_late_hooks == ARRAYELTS (dump_late_hooks)) + fatal ("out of dump hooks: make dump_late_hooks[] bigger"); + dump_late_hooks[nr_dump_late_hooks++] = hook; + hook (); +} + static void pdumper_remember_user_data_1 (void *mem, int nbytes) { @@ -5597,6 +5615,12 @@ pdumper_load (const char *dump_filename, char *argv0, char const *original_pwd) dump_do_all_dump_reloc_for_phase (header, dump_base, LATE_RELOCS); dump_do_all_dump_reloc_for_phase (header, dump_base, VERY_LATE_RELOCS); + + /* Run the functions Emacs registered for doing post-dump-load + initialization. */ + for (int i = 0; i < nr_dump_late_hooks; ++i) + dump_late_hooks[i] (); + initialized = true; struct timespec load_timespec = diff --git a/src/pdumper.h b/src/pdumper.h index 24e99e22c7a..49e6739b0dc 100644 --- a/src/pdumper.h +++ b/src/pdumper.h @@ -81,6 +81,7 @@ pdumper_remember_lv_ptr_raw (void *ptr, enum Lisp_Type type) typedef void (*pdumper_hook)(void); extern void pdumper_do_now_and_after_load_impl (pdumper_hook hook); +extern void pdumper_do_now_and_after_late_load_impl (pdumper_hook hook); INLINE void pdumper_do_now_and_after_load (pdumper_hook hook) @@ -92,6 +93,18 @@ pdumper_do_now_and_after_load (pdumper_hook hook) #endif } +/* Same as 'pdumper_do_now_and_after_load' but for hooks running code + that can call into Lisp. */ +INLINE void +pdumper_do_now_and_after_late_load (pdumper_hook hook) +{ +#ifdef HAVE_PDUMPER + pdumper_do_now_and_after_late_load_impl (hook); +#else + hook (); +#endif +} + /* Macros useful in pdumper callback functions. Assign a value if we're loading a dump and the value needs to be reset to its original value, and if we're initializing for the first time, diff --git a/src/window.c b/src/window.c index eb16e2a4338..f8b97287e64 100644 --- a/src/window.c +++ b/src/window.c @@ -8134,7 +8134,7 @@ init_window_once (void) minibuf_selected_window = Qnil; staticpro (&minibuf_selected_window); - pdumper_do_now_and_after_load (init_window_once_for_pdumper); + pdumper_do_now_and_after_late_load (init_window_once_for_pdumper); } static void init_window_once_for_pdumper (void) -- 2.39.5