diff --git a/headers/private/kernel/kimage.h b/headers/private/kernel/kimage.h index ab71a8c12a..e2233b2970 100644 --- a/headers/private/kernel/kimage.h +++ b/headers/private/kernel/kimage.h @@ -1,7 +1,7 @@ /* -** Copyright 2003-2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ + * Copyright 2003-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef _KERNEL_IMAGE_H #define _KERNEL_IMAGE_H @@ -11,10 +11,18 @@ struct team; +#ifdef __cplusplus +extern "C" { +#endif + extern image_id register_image(struct team *team, image_info *info, size_t size); extern status_t unregister_image(struct team *team, image_id id); extern int32 count_images(struct team *team); extern status_t remove_images(struct team *team); + +extern status_t image_debug_lookup_user_symbol_address(struct team *team, + addr_t address, addr_t *_baseAddress, const char **_symbolName, + const char **_imageName, bool *_exactMatch); extern status_t image_init(void); // user-space exported calls @@ -26,4 +34,8 @@ extern status_t _user_get_next_image_info(team_id team, int32 *_cookie, image_info *userInfo, size_t size); extern status_t _user_get_image_info(image_id id, image_info *userInfo, size_t size); +#ifdef __cplusplus +} +#endif + #endif /* _KRENEL_IMAGE_H */ diff --git a/src/system/kernel/image.c b/src/system/kernel/image.c index d913ab8f08..0dce282e48 100644 --- a/src/system/kernel/image.c +++ b/src/system/kernel/image.c @@ -136,6 +136,11 @@ remove_images(struct team *team) } +/** Unlike in BeOS, this function only returns images that belong to the + * current team. + * ToDo: we might want to rethink that one day... + */ + status_t _get_image_info(image_id id, image_info *info, size_t size) { @@ -207,25 +212,52 @@ dump_images_list(int argc, char **argv) struct team *team = thread_get_current_thread()->team; struct image *image = NULL; - dprintf("Registered images of team 0x%lx\n", team->id); - dprintf(" ID text size data size name\n"); - - mutex_lock(&sImageMutex); + kprintf("Registered images of team 0x%lx\n", team->id); + kprintf(" ID text size data size name\n"); while ((image = list_get_next_item(&team->image_list, image)) != NULL) { image_info *info = &image->info; - dprintf("%6ld %p %-7ld %p %-7ld %s\n", info->id, info->text, info->text_size, + kprintf("%6ld %p %-7ld %p %-7ld %s\n", info->id, info->text, info->text_size, info->data, info->data_size, info->name); } - mutex_unlock(&sImageMutex); - return 0; } #endif +status_t +image_debug_lookup_user_symbol_address(struct team *team, addr_t address, + addr_t *_baseAddress, const char **_symbolName, const char **_imageName, + bool *_exactMatch) +{ + // TODO: work together with ELF reader and runtime_loader + + struct image *image = NULL; + + while ((image = list_get_next_item(&team->image_list, image)) != NULL) { + image_info *info = &image->info; + + if ((address < (addr_t)info->text + || address >= (addr_t)info->text + info->text_size) + && (address < (addr_t)info->data + || address >= (addr_t)info->data + info->data_size)) + continue; + + // found image + *_symbolName = NULL; + *_imageName = info->name; + *_baseAddress = (addr_t)info->text; + *_exactMatch = false; + + return B_OK; + } + + return B_ENTRY_NOT_FOUND; +} + + status_t image_init(void) {