runtime_loader: Use a RecursiveLocker instead of manually unlocking.
No functional change intended.
This commit is contained in:
@@ -53,20 +53,6 @@ static uint32 sPreloadedImageCount = 0;
|
|||||||
static recursive_lock sLock = RECURSIVE_LOCK_INITIALIZER(kLockName);
|
static recursive_lock sLock = RECURSIVE_LOCK_INITIALIZER(kLockName);
|
||||||
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
rld_lock()
|
|
||||||
{
|
|
||||||
recursive_lock_lock(&sLock);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
rld_unlock()
|
|
||||||
{
|
|
||||||
recursive_lock_unlock(&sLock);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
find_dt_rpath(image_t *image)
|
find_dt_rpath(image_t *image)
|
||||||
{
|
{
|
||||||
@@ -431,7 +417,7 @@ load_program(char const *path, void **_entry)
|
|||||||
|
|
||||||
KTRACE("rld: load_program(\"%s\")", path);
|
KTRACE("rld: load_program(\"%s\")", path);
|
||||||
|
|
||||||
rld_lock();
|
RecursiveLocker _(sLock);
|
||||||
// for now, just do stupid simple global locking
|
// for now, just do stupid simple global locking
|
||||||
|
|
||||||
preload_images();
|
preload_images();
|
||||||
@@ -475,8 +461,6 @@ load_program(char const *path, void **_entry)
|
|||||||
|
|
||||||
*_entry = (void *)(gProgramImage->entry_point);
|
*_entry = (void *)(gProgramImage->entry_point);
|
||||||
|
|
||||||
rld_unlock();
|
|
||||||
|
|
||||||
gProgramLoaded = true;
|
gProgramLoaded = true;
|
||||||
|
|
||||||
KTRACE("rld: load_program(\"%s\") done: entry: %p, id: %" B_PRId32 , path,
|
KTRACE("rld: load_program(\"%s\") done: entry: %p, id: %" B_PRId32 , path,
|
||||||
@@ -499,7 +483,6 @@ err:
|
|||||||
gErrorMessage.Buffer(), gErrorMessage.ContentSize(), 0, 0);
|
gErrorMessage.Buffer(), gErrorMessage.ContentSize(), 0, 0);
|
||||||
}
|
}
|
||||||
_kern_loading_app_failed(status);
|
_kern_loading_app_failed(status);
|
||||||
rld_unlock();
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@@ -517,7 +500,7 @@ load_library(char const *path, uint32 flags, bool addOn, void** _handle)
|
|||||||
|
|
||||||
KTRACE("rld: load_library(\"%s\", %#" B_PRIx32 ", %d)", path, flags, addOn);
|
KTRACE("rld: load_library(\"%s\", %#" B_PRIx32 ", %d)", path, flags, addOn);
|
||||||
|
|
||||||
rld_lock();
|
RecursiveLocker _(sLock);
|
||||||
// for now, just do stupid simple global locking
|
// for now, just do stupid simple global locking
|
||||||
|
|
||||||
// have we already loaded this library?
|
// have we already loaded this library?
|
||||||
@@ -526,7 +509,6 @@ load_library(char const *path, uint32 flags, bool addOn, void** _handle)
|
|||||||
// a NULL path is fine -- it means the global scope shall be opened
|
// a NULL path is fine -- it means the global scope shall be opened
|
||||||
if (path == NULL) {
|
if (path == NULL) {
|
||||||
*_handle = RLD_GLOBAL_SCOPE;
|
*_handle = RLD_GLOBAL_SCOPE;
|
||||||
rld_unlock();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -536,7 +518,6 @@ load_library(char const *path, uint32 flags, bool addOn, void** _handle)
|
|||||||
|
|
||||||
if (image) {
|
if (image) {
|
||||||
atomic_add(&image->ref_count, 1);
|
atomic_add(&image->ref_count, 1);
|
||||||
rld_unlock();
|
|
||||||
KTRACE("rld: load_library(\"%s\"): already loaded: %" B_PRId32,
|
KTRACE("rld: load_library(\"%s\"): already loaded: %" B_PRId32,
|
||||||
path, image->id);
|
path, image->id);
|
||||||
*_handle = image;
|
*_handle = image;
|
||||||
@@ -546,7 +527,6 @@ load_library(char const *path, uint32 flags, bool addOn, void** _handle)
|
|||||||
|
|
||||||
status = load_image(path, type, NULL, NULL, &image);
|
status = load_image(path, type, NULL, NULL, &image);
|
||||||
if (status < B_OK) {
|
if (status < B_OK) {
|
||||||
rld_unlock();
|
|
||||||
KTRACE("rld: load_library(\"%s\") failed to load container: %s", path,
|
KTRACE("rld: load_library(\"%s\") failed to load container: %s", path,
|
||||||
strerror(status));
|
strerror(status));
|
||||||
return status;
|
return status;
|
||||||
@@ -582,8 +562,6 @@ load_library(char const *path, uint32 flags, bool addOn, void** _handle)
|
|||||||
remap_images();
|
remap_images();
|
||||||
init_dependencies(image, true);
|
init_dependencies(image, true);
|
||||||
|
|
||||||
rld_unlock();
|
|
||||||
|
|
||||||
KTRACE("rld: load_library(\"%s\") done: id: %" B_PRId32, path, image->id);
|
KTRACE("rld: load_library(\"%s\") done: id: %" B_PRId32, path, image->id);
|
||||||
|
|
||||||
*_handle = image;
|
*_handle = image;
|
||||||
@@ -594,7 +572,6 @@ err:
|
|||||||
|
|
||||||
dequeue_loaded_image(image);
|
dequeue_loaded_image(image);
|
||||||
delete_image(image);
|
delete_image(image);
|
||||||
rld_unlock();
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -611,7 +588,7 @@ unload_library(void* handle, image_id imageID, bool addOn)
|
|||||||
if (handle == RLD_GLOBAL_SCOPE)
|
if (handle == RLD_GLOBAL_SCOPE)
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
rld_lock();
|
RecursiveLocker _(sLock);
|
||||||
// for now, just do stupid simple global locking
|
// for now, just do stupid simple global locking
|
||||||
|
|
||||||
if (gInvalidImageIDs) {
|
if (gInvalidImageIDs) {
|
||||||
@@ -694,7 +671,6 @@ unload_library(void* handle, image_id imageID, bool addOn)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rld_unlock();
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -707,14 +683,12 @@ get_nth_symbol(image_id imageID, int32 num, char *nameBuffer,
|
|||||||
uint32 i;
|
uint32 i;
|
||||||
image_t *image;
|
image_t *image;
|
||||||
|
|
||||||
rld_lock();
|
RecursiveLocker _(sLock);
|
||||||
|
|
||||||
// get the image from those who have been already initialized
|
// get the image from those who have been already initialized
|
||||||
image = find_loaded_image_by_id(imageID, false);
|
image = find_loaded_image_by_id(imageID, false);
|
||||||
if (image == NULL) {
|
if (image == NULL)
|
||||||
rld_unlock();
|
|
||||||
return B_BAD_IMAGE_ID;
|
return B_BAD_IMAGE_ID;
|
||||||
}
|
|
||||||
|
|
||||||
// iterate through all the hash buckets until we've found the one
|
// iterate through all the hash buckets until we've found the one
|
||||||
for (i = 0; i < HASHTABSIZE(image); i++) {
|
for (i = 0; i < HASHTABSIZE(image); i++) {
|
||||||
@@ -749,8 +723,6 @@ get_nth_symbol(image_id imageID, int32 num, char *nameBuffer,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
rld_unlock();
|
|
||||||
|
|
||||||
if (num != count)
|
if (num != count)
|
||||||
return B_BAD_INDEX;
|
return B_BAD_INDEX;
|
||||||
|
|
||||||
@@ -763,13 +735,11 @@ get_nearest_symbol_at_address(void* address, image_id* _imageID,
|
|||||||
char** _imagePath, char** _imageName, char** _symbolName, int32* _type,
|
char** _imagePath, char** _imageName, char** _symbolName, int32* _type,
|
||||||
void** _location, bool* _exactMatch)
|
void** _location, bool* _exactMatch)
|
||||||
{
|
{
|
||||||
rld_lock();
|
RecursiveLocker _(sLock);
|
||||||
|
|
||||||
image_t* image = find_loaded_image_by_address((addr_t)address);
|
image_t* image = find_loaded_image_by_address((addr_t)address);
|
||||||
if (image == NULL) {
|
if (image == NULL)
|
||||||
rld_unlock();
|
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
}
|
|
||||||
|
|
||||||
bool exactMatch = false;
|
bool exactMatch = false;
|
||||||
elf_sym* foundSymbol = NULL;
|
elf_sym* foundSymbol = NULL;
|
||||||
@@ -824,7 +794,6 @@ get_nearest_symbol_at_address(void* address, image_id* _imageID,
|
|||||||
*_location = NULL;
|
*_location = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
rld_unlock();
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -850,7 +819,7 @@ get_symbol(image_id imageID, char const *symbolName, int32 symbolType,
|
|||||||
|| strcmp(symbolName, B_TERM_AFTER_FUNCTION_NAME) == 0)
|
|| strcmp(symbolName, B_TERM_AFTER_FUNCTION_NAME) == 0)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
rld_lock();
|
RecursiveLocker _(sLock);
|
||||||
// for now, just do stupid simple global locking
|
// for now, just do stupid simple global locking
|
||||||
|
|
||||||
// get the image from those who have been already initialized
|
// get the image from those who have been already initialized
|
||||||
@@ -874,7 +843,6 @@ get_symbol(image_id imageID, char const *symbolName, int32 symbolType,
|
|||||||
} else
|
} else
|
||||||
status = B_BAD_IMAGE_ID;
|
status = B_BAD_IMAGE_ID;
|
||||||
|
|
||||||
rld_unlock();
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -888,7 +856,7 @@ get_library_symbol(void* handle, void* caller, const char* symbolName,
|
|||||||
if (symbolName == NULL)
|
if (symbolName == NULL)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
rld_lock();
|
RecursiveLocker _(sLock);
|
||||||
// for now, just do stupid simple global locking
|
// for now, just do stupid simple global locking
|
||||||
|
|
||||||
if (handle == RTLD_DEFAULT || handle == RLD_GLOBAL_SCOPE) {
|
if (handle == RTLD_DEFAULT || handle == RLD_GLOBAL_SCOPE) {
|
||||||
@@ -986,7 +954,6 @@ get_library_symbol(void* handle, void* caller, const char* symbolName,
|
|||||||
&inImage, _location);
|
&inImage, _location);
|
||||||
}
|
}
|
||||||
|
|
||||||
rld_unlock();
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1001,19 +968,15 @@ get_next_image_dependency(image_id id, uint32 *cookie, const char **_name)
|
|||||||
if (_name == NULL)
|
if (_name == NULL)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
rld_lock();
|
RecursiveLocker _(sLock);
|
||||||
|
|
||||||
image = find_loaded_image_by_id(id, false);
|
image = find_loaded_image_by_id(id, false);
|
||||||
if (image == NULL) {
|
if (image == NULL)
|
||||||
rld_unlock();
|
|
||||||
return B_BAD_IMAGE_ID;
|
return B_BAD_IMAGE_ID;
|
||||||
}
|
|
||||||
|
|
||||||
dynamicSection = (elf_dyn *)image->dynamic_ptr;
|
dynamicSection = (elf_dyn *)image->dynamic_ptr;
|
||||||
if (dynamicSection == NULL || image->num_needed <= searchIndex) {
|
if (dynamicSection == NULL || image->num_needed <= searchIndex)
|
||||||
rld_unlock();
|
|
||||||
return B_ENTRY_NOT_FOUND;
|
return B_ENTRY_NOT_FOUND;
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0, j = 0; dynamicSection[i].d_tag != DT_NULL; i++) {
|
for (i = 0, j = 0; dynamicSection[i].d_tag != DT_NULL; i++) {
|
||||||
if (dynamicSection[i].d_tag != DT_NEEDED)
|
if (dynamicSection[i].d_tag != DT_NEEDED)
|
||||||
@@ -1024,12 +987,10 @@ get_next_image_dependency(image_id id, uint32 *cookie, const char **_name)
|
|||||||
|
|
||||||
*_name = STRING(image, neededOffset);
|
*_name = STRING(image, neededOffset);
|
||||||
*cookie = searchIndex + 1;
|
*cookie = searchIndex + 1;
|
||||||
rld_unlock();
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rld_unlock();
|
|
||||||
return B_ENTRY_NOT_FOUND;
|
return B_ENTRY_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user