diff --git a/headers/os/kernel/image.h b/headers/os/kernel/image.h index fe11a22d24..854e5e8c81 100644 --- a/headers/os/kernel/image.h +++ b/headers/os/kernel/image.h @@ -56,6 +56,12 @@ typedef struct { #define B_TERM_BEFORE_FUNCTION_NAME "terminate_before" #define B_TERM_AFTER_FUNCTION_NAME "terminate_after" +#define B_APP_IMAGE_SYMBOL ((void*)(addr_t)0) + // value that can be used instead of a pointer to a symbol in the program + // image. +#define B_CURRENT_IMAGE_SYMBOL ((void*)&__haiku_init_before) + // pointer to a symbol in the callers image + // flags for _kern_load_image() (private API) enum { B_WAIT_TILL_LOADED = 0x01, @@ -91,6 +97,9 @@ status_t _get_image_info(image_id image, image_info *info, size_t size); status_t _get_next_image_info(team_id team, int32 *cookie, image_info *info, size_t size); +/* private */ +void __haiku_init_before(image_id id); + #ifdef __cplusplus } #endif diff --git a/src/kits/storage/Resources.cpp b/src/kits/storage/Resources.cpp index c962cc566f..54bf553a1c 100644 --- a/src/kits/storage/Resources.cpp +++ b/src/kits/storage/Resources.cpp @@ -204,19 +204,18 @@ status_t BResources::SetToImage(const void* codeOrDataPointer, bool clobber) { #ifdef HAIKU_TARGET_PLATFORM_HAIKU - if (!codeOrDataPointer) - return B_BAD_VALUE; - // iterate through the images and find the one in question addr_t address = (addr_t)codeOrDataPointer; image_info info; int32 cookie = 0; while (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) { - if (((addr_t)info.text <= address - && address - (addr_t)info.text < (addr_t)info.text_size) - || ((addr_t)info.data <= address - && address - (addr_t)info.data < (addr_t)info.data_size)) { + if (address == 0 + ? info.type == B_APP_IMAGE + : (((addr_t)info.text <= address + && address - (addr_t)info.text < (addr_t)info.text_size) + || ((addr_t)info.data <= address + && address - (addr_t)info.data < (addr_t)info.data_size))) { return SetTo(info.name, clobber); } }