From 3be509a228306fda552ecb7db83217a2f8a2c295 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Sun, 13 Jan 2008 18:49:27 +0000 Subject: [PATCH] Fix the static cleanup mechanism introduced to the runtime_loader/libroot: * Fixed wrong start and size used in the runtime_loader * Fixed off by one error in the matching loop of the cleanup hook * Make sure we successfully acquire the locking sem of the exit stack git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23493 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/libroot/posix/stdlib/exit.c | 8 +++++--- src/system/runtime_loader/elf.cpp | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/system/libroot/posix/stdlib/exit.c b/src/system/libroot/posix/stdlib/exit.c index c1bf1832bb..ee13b0fb95 100644 --- a/src/system/libroot/posix/stdlib/exit.c +++ b/src/system/libroot/posix/stdlib/exit.c @@ -46,8 +46,10 @@ _exit_stack_lock() { thread_id self = find_thread(NULL); if (self != sExitStackInfo.lock_owner) { - if (atomic_add(&sExitStackInfo.lock_count, 1) > 0) - acquire_sem(sExitStackInfo.lock); + if (atomic_add(&sExitStackInfo.lock_count, 1) > 0) { + while (acquire_sem(sExitStackInfo.lock) != B_OK) + ; + } sExitStackInfo.lock_owner = self; } sExitStackInfo.recursion_count++; @@ -75,7 +77,7 @@ _call_atexit_hooks_for_range(addr_t start, addr_t size) int32 insertIndex = -1; _exit_stack_lock(); - for (index = sExitStackInfo.stack_size - 1; index > 0; index--) { + for (index = sExitStackInfo.stack_size - 1; index >= 0; index--) { addr_t function = (addr_t)sExitStackInfo.exit_stack[index]; if (function >= start && function < start + size) { (*sExitStackInfo.exit_stack[index])(); diff --git a/src/system/runtime_loader/elf.cpp b/src/system/runtime_loader/elf.cpp index b1535e5245..fcc17b4cfc 100644 --- a/src/system/runtime_loader/elf.cpp +++ b/src/system/runtime_loader/elf.cpp @@ -1460,7 +1460,7 @@ unload_library(image_id imageID, bool addOn) // call image fini here... if (gRuntimeLoader.call_atexit_hooks_for_range) { gRuntimeLoader.call_atexit_hooks_for_range( - image->regions[0].start, image->regions[0].size); + image->regions[0].vmstart, image->regions[0].vmsize); } if (image->term_routine)