From 7f4e6824dfccc85a3c7ed45fd8ef4b7a944c395b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 6 Oct 2006 11:40:20 +0000 Subject: [PATCH] Added a private call to get the dependencies of a loaded image. This will be used to determine linkage of libnet.so vs. libsocket.so/libbind.so in the libnetwork.so. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19008 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/kernel/user_runtime.h | 2 ++ headers/private/libroot/libroot_private.h | 18 ++++++++--- src/system/libroot/os/image.c | 7 +++++ src/system/runtime_loader/elf.c | 31 +++++++++++++++++++ src/system/runtime_loader/export.c | 10 +++++- .../runtime_loader/runtime_loader_private.h | 1 + 6 files changed, 64 insertions(+), 5 deletions(-) diff --git a/headers/private/kernel/user_runtime.h b/headers/private/kernel/user_runtime.h index 504f2a3b1f..cf7036949a 100644 --- a/headers/private/kernel/user_runtime.h +++ b/headers/private/kernel/user_runtime.h @@ -34,6 +34,8 @@ struct rld_export { int32 *nameLength, int32 *symbolType, void **_location); status_t (*test_executable)(const char *path, uid_t user, gid_t group, char *starter); + status_t (*get_next_image_dependency)(image_id id, uint32 *cookie, + const char **_name); const struct uspace_program_args *program_args; }; diff --git a/headers/private/libroot/libroot_private.h b/headers/private/libroot/libroot_private.h index e918beefd4..b197a7cf96 100644 --- a/headers/private/libroot/libroot_private.h +++ b/headers/private/libroot/libroot_private.h @@ -7,13 +7,24 @@ #include +#include struct uspace_program_args; struct real_time_data; +extern char _single_threaded; + /* This determines if a process runs single threaded or not */ + + +#ifdef __cplusplus +extern "C" { +#endif + status_t __parse_invoke_line(char *invoker, char ***_newArgs, char * const **_oldArgs, int32 *_argCount); +status_t __get_next_image_dependency(image_id id, uint32 *cookie, + const char **_name); status_t __test_executable(const char *path, char *invoker); void __init_env(const struct uspace_program_args *args); void __init_heap(void); @@ -22,9 +33,8 @@ void __init_time(void); void __arch_init_time(struct real_time_data *data, bool setDefaults); bigtime_t __arch_get_system_time_offset(struct real_time_data *data); - -extern char _single_threaded; - /* This determines if a process runs single threaded or not */ - +#ifdef __cplusplus +} +#endif #endif /* LIBROOT_PRIVATE_H */ diff --git a/src/system/libroot/os/image.c b/src/system/libroot/os/image.c index 22af19624c..b20ba69a05 100644 --- a/src/system/libroot/os/image.c +++ b/src/system/libroot/os/image.c @@ -182,6 +182,13 @@ __parse_invoke_line(char *invoker, char ***_newArgs, } +status_t +__get_next_image_dependency(image_id id, uint32 *cookie, const char **_name) +{ + return __gRuntimeLoader->get_next_image_dependency(id, cookie, _name); +} + + status_t __test_executable(const char *path, char *invoker) { diff --git a/src/system/runtime_loader/elf.c b/src/system/runtime_loader/elf.c index 59fddd4979..e6a136e0a3 100644 --- a/src/system/runtime_loader/elf.c +++ b/src/system/runtime_loader/elf.c @@ -1419,6 +1419,37 @@ get_symbol(image_id imageID, char const *symbolName, int32 symbolType, void **_l } +status_t +get_next_image_dependency(image_id id, uint32 *cookie, const char **_name) +{ + image_t *image = find_loaded_image_by_id(id); + uint32 i, j, searchIndex = *cookie; + struct Elf32_Dyn *dynamicSection; + + if (image == NULL) + return B_BAD_VALUE; + + dynamicSection = (struct Elf32_Dyn *)image->dynamic_ptr; + if (dynamicSection == NULL || image->num_needed <= searchIndex) + return B_ENTRY_NOT_FOUND; + + for (i = 0, j = 0; dynamicSection[i].d_tag != DT_NULL; i++) { + if (dynamicSection[i].d_tag != DT_NEEDED) + continue; + + if (j++ == searchIndex) { + int32 neededOffset = dynamicSection[i].d_un.d_val; + + *_name = STRING(image, neededOffset); + *cookie = searchIndex + 1; + return B_OK; + } + } + + return B_ENTRY_NOT_FOUND; +} + + // #pragma mark - diff --git a/src/system/runtime_loader/export.c b/src/system/runtime_loader/export.c index 754c2234dc..fa3015f052 100644 --- a/src/system/runtime_loader/export.c +++ b/src/system/runtime_loader/export.c @@ -49,13 +49,21 @@ export_test_executable(const char *path, uid_t user, gid_t group, char *starter) } +static status_t +export_get_next_image_dependency(image_id id, uint32 *cookie, const char **_name) +{ + return get_next_image_dependency(id, cookie, _name); +} + + struct rld_export gRuntimeLoader = { // dynamic loading support API export_load_add_on, export_unload_add_on, export_get_image_symbol, export_get_nth_image_symbol, - export_test_executable + export_test_executable, + export_get_next_image_dependency }; diff --git a/src/system/runtime_loader/runtime_loader_private.h b/src/system/runtime_loader/runtime_loader_private.h index 4759c4bef5..e668c43cd2 100644 --- a/src/system/runtime_loader/runtime_loader_private.h +++ b/src/system/runtime_loader/runtime_loader_private.h @@ -34,6 +34,7 @@ status_t get_nth_symbol(image_id imageID, int32 num, char *nameBuffer, int32 *_n int32 *_type, void **_location); status_t get_symbol(image_id imageID, char const *symbolName, int32 symbolType, void **_location); +status_t get_next_image_dependency(image_id id, uint32 *cookie, const char **_name); int resolve_symbol(image_t *image, struct Elf32_Sym *sym, addr_t *sym_addr);