Added private get_image_symbol_etc() that can recursively search for a symbol

(similar to how dlsym() works).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29356 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2009-02-28 18:50:40 +00:00
parent 25c4a958a2
commit 80ece78534
5 changed files with 55 additions and 14 deletions
+21
View File
@@ -0,0 +1,21 @@
/*
* Copyright 2009, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef _LIBROOT_IMAGE_PRIVATE_H
#define _LIBROOT_IMAGE_PRIVATE_H
#include <sys/cdefs.h>
#include <image.h>
__BEGIN_DECLS
status_t get_image_symbol_etc(image_id id, char const* symbolName,
int32 symbolType, bool recursive, image_id* _inImage, void** _location);
__END_DECLS
#endif // _LIBROOT_IMAGE_PRIVATE_H
@@ -28,7 +28,7 @@ struct rld_export {
image_id (*load_library)(char const *path, uint32 flags, void **_handle); image_id (*load_library)(char const *path, uint32 flags, void **_handle);
status_t (*unload_library)(void* handle); status_t (*unload_library)(void* handle);
status_t (*get_image_symbol)(image_id imageID, char const *symbolName, status_t (*get_image_symbol)(image_id imageID, char const *symbolName,
int32 symbolType, void **_location); int32 symbolType, bool recursive, image_id *_inImage, void **_location);
status_t (*get_library_symbol)(void* handle, void* caller, status_t (*get_library_symbol)(void* handle, void* caller,
const char* symbolName, void **_location); const char* symbolName, void **_location);
status_t (*get_nth_image_symbol)(image_id imageID, int32 num, char *symbolName, status_t (*get_nth_image_symbol)(image_id imageID, int32 num, char *symbolName,
+20 -8
View File
@@ -3,18 +3,19 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#include <image.h>
#include <image_private.h>
#include <stdlib.h>
#include <string.h>
#include <OS.h>
#include <libroot_private.h> #include <libroot_private.h>
#include <runtime_loader.h> #include <runtime_loader.h>
#include <syscalls.h> #include <syscalls.h>
#include <user_runtime.h> #include <user_runtime.h>
#include <OS.h>
#include <image.h>
#include <stdlib.h>
#include <string.h>
thread_id thread_id
load_image(int32 argCount, const char **args, const char **environ) load_image(int32 argCount, const char **args, const char **environ)
@@ -81,9 +82,20 @@ unload_add_on(image_id id)
status_t status_t
get_image_symbol(image_id id, char const *symbolName, int32 symbolType, void **_location) get_image_symbol(image_id id, char const *symbolName, int32 symbolType,
void **_location)
{ {
return __gRuntimeLoader->get_image_symbol(id, symbolName, symbolType, _location); return __gRuntimeLoader->get_image_symbol(id, symbolName, symbolType,
false, NULL, _location);
}
status_t
get_image_symbol_etc(image_id id, char const *symbolName, int32 symbolType,
bool recursive, image_id *_inImage, void **_location)
{
return __gRuntimeLoader->get_image_symbol(id, symbolName, symbolType,
recursive, _inImage, _location);
} }
+12 -4
View File
@@ -2421,7 +2421,7 @@ out:
status_t status_t
get_symbol(image_id imageID, char const *symbolName, int32 symbolType, get_symbol(image_id imageID, char const *symbolName, int32 symbolType,
void **_location) bool recursive, image_id *_inImage, void **_location)
{ {
status_t status = B_OK; status_t status = B_OK;
image_t *image; image_t *image;
@@ -2436,9 +2436,17 @@ get_symbol(image_id imageID, char const *symbolName, int32 symbolType,
// 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); image = find_loaded_image_by_id(imageID);
if (image != NULL) if (image != NULL) {
status = find_symbol(image, symbolName, symbolType, _location); if (recursive) {
else // breadth-first search in the given image and its dependencies
status = find_symbol_breadth_first(image, symbolName, symbolType,
&image, _location);
} else
status = find_symbol(image, symbolName, symbolType, _location);
if (status == B_OK && _inImage != NULL)
*_inImage = image->id;
} else
status = B_BAD_IMAGE_ID; status = B_BAD_IMAGE_ID;
rld_unlock(); rld_unlock();
@@ -35,7 +35,7 @@ status_t unload_library(void* handle, image_id imageID, bool addOn);
status_t get_nth_symbol(image_id imageID, int32 num, char *nameBuffer, status_t get_nth_symbol(image_id imageID, int32 num, char *nameBuffer,
int32 *_nameLength, int32 *_type, void **_location); int32 *_nameLength, int32 *_type, void **_location);
status_t get_symbol(image_id imageID, char const *symbolName, int32 symbolType, status_t get_symbol(image_id imageID, char const *symbolName, int32 symbolType,
void **_location); bool recursive, image_id *_inImage, void **_location);
status_t get_library_symbol(void* handle, void* caller, const char* symbolName, status_t get_library_symbol(void* handle, void* caller, const char* symbolName,
void **_location); void **_location);
status_t get_next_image_dependency(image_id id, uint32 *cookie, status_t get_next_image_dependency(image_id id, uint32 *cookie,