From f1fe8fa43476998e9575626e4150760929ccc70a Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Thu, 7 Oct 2010 15:26:15 +0000 Subject: [PATCH] Add hook in dynamically loaded modules for unloading actions. Dynamically loaded modules can't use reload cleanups, because they may be unloaded by pruxdld's reload cleanup before their reload cleanups get to run, causing DISK-RESTORE to attempt to execute unmapped code. Instead, pruxdld will now call dload_finalize_file if it is defined in the file. Use this mechanism in prx11. Fixes DISK-RESTORE after launching and exiting Edwin. (Does not fix DISK-RESTORE of an image that was saved while Edwin was running. That is much harder.) --- src/microcode/pruxdld.c | 18 +++++++++++++++++- src/microcode/prx11.c | 9 ++++++++- src/microcode/x11base.c | 9 +++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/microcode/pruxdld.c b/src/microcode/pruxdld.c index 13f35f846..35c719a4c 100644 --- a/src/microcode/pruxdld.c +++ b/src/microcode/pruxdld.c @@ -145,9 +145,21 @@ dld_load (const char * path) return (handle); } +static void +dld_finalize (void * handle) +{ + void * address = (dlsym (handle, "dld_finalize_file")); + if (address != 0) + { + void (*finalize) (void) = address; + (*finalize) (); + } +} + static void dld_unload (void * handle) { + dld_finalize (handle); if ((dlclose (handle)) != 0) { SCHEME_OBJECT v = (allocate_marked_vector (TC_VECTOR, 3, 1)); @@ -177,7 +189,11 @@ dld_unload_all (void) void ** scan = loaded_handles; void ** end = (scan + n_loaded_handles); while (scan < end) - dlclose (*scan++); + { + void * handle = (*scan++); + dld_finalize (handle); + dlclose (handle); + } OS_free (loaded_handles); loaded_handles_size = 0; diff --git a/src/microcode/prx11.c b/src/microcode/prx11.c index 2f4068d3e..61c44e391 100644 --- a/src/microcode/prx11.c +++ b/src/microcode/prx11.c @@ -35,7 +35,6 @@ extern void dload_initialize_x11term (void); const char * dload_initialize_file (void) { - dload_initialize_x11base (); dload_initialize_x11color (); dload_initialize_x11graph (); @@ -43,4 +42,12 @@ dload_initialize_file (void) return ("#prx11"); } +extern void dload_finalize_x11base (void); + +void +dload_finalize_file (void) +{ + dload_finalize_x11base (); +} + #endif /* defined (COMPILE_AS_MODULE) */ diff --git a/src/microcode/x11base.c b/src/microcode/x11base.c index 8a5ca3310..9ef4bbe26 100644 --- a/src/microcode/x11base.c +++ b/src/microcode/x11base.c @@ -1571,7 +1571,9 @@ initialize_once (void) (x_error_info.code) = 0; XSetErrorHandler (x_error_handler); XSetIOErrorHandler (x_io_error_handler); +#ifndef COMPILE_AS_MODULE add_reload_cleanup (x_close_all_displays); +#endif initialization_done = 1; } @@ -2815,4 +2817,11 @@ dload_initialize_x11base (void) declare_primitive ("X-WINDOW-Y-SIZE", Prim_x_window_y_size, 1, 1, 0); } +void +dload_finalize_x11base (void) +{ + if (initialization_done) + x_close_all_displays (); +} + #endif /* defined (COMPILE_AS_MODULE) */ -- 2.25.1