Jelajahi Sumber

LibC: Mark atexit() entries as 'called' before calling them

This guards as from recursing into an atexit callback if exit() is called
from within it.
Itamar 4 tahun lalu
induk
melakukan
9eaa6527f7
1 mengubah file dengan 1 tambahan dan 1 penghapusan
  1. 1 1
      Userland/Libraries/LibC/cxxabi.cpp

+ 1 - 1
Userland/Libraries/LibC/cxxabi.cpp

@@ -101,10 +101,10 @@ void __cxa_finalize(void* dso_handle)
         bool needs_calling = !exit_entry.has_been_called && (!dso_handle || dso_handle == exit_entry.dso_handle);
         bool needs_calling = !exit_entry.has_been_called && (!dso_handle || dso_handle == exit_entry.dso_handle);
         if (needs_calling) {
         if (needs_calling) {
             dbgln_if(GLOBAL_DTORS_DEBUG, "__cxa_finalize: calling entry[{}] {:p}({:p}) dso: {:p}", entry_index, exit_entry.method, exit_entry.parameter, exit_entry.dso_handle);
             dbgln_if(GLOBAL_DTORS_DEBUG, "__cxa_finalize: calling entry[{}] {:p}({:p}) dso: {:p}", entry_index, exit_entry.method, exit_entry.parameter, exit_entry.dso_handle);
-            exit_entry.method(exit_entry.parameter);
             unlock_atexit_handlers();
             unlock_atexit_handlers();
             exit_entry.has_been_called = true;
             exit_entry.has_been_called = true;
             lock_atexit_handlers();
             lock_atexit_handlers();
+            exit_entry.method(exit_entry.parameter);
         }
         }
     }
     }
 }
 }