Deleted Added
full compact
2c2
< Copyright (c) 2003 Hewlett-Packard Development Company, L.P.
---
> Copyright (c) 2003-2006 Hewlett-Packard Development Company, L.P.
25a26
> #include <string.h>
33a35
> #include "uwx_self_info.h"
37,47c39
< struct uwx_self_info {
< struct uwx_env *env;
< ucontext_t *ucontext;
< uint64_t bspstore;
< uint64_t rvec[10];
< uint64_t sendsig_start;
< uint64_t sendsig_end;
< alloc_cb allocate_cb;
< free_cb free_cb;
< int trace;
< };
---
> void uwx_free_load_module_cache(struct uwx_self_info *info);
49c41
< struct uwx_self_info *uwx_self_init_info(struct uwx_env *env)
---
> int uwx_self_init_info_block(struct uwx_env *env, struct uwx_self_info *info)
51,61d42
< struct uwx_self_info *info;
<
< if (env->allocate_cb == 0)
< info = (struct uwx_self_info *)
< malloc(sizeof(struct uwx_self_info));
< else
< info = (struct uwx_self_info *)
< (*env->allocate_cb)(sizeof(struct uwx_self_info));
< if (info == 0)
< return 0;
<
68,69c49
< info->allocate_cb = env->allocate_cb;
< info->free_cb = env->free_cb;
---
> info->on_heap = 0;
70a51,66
> info->load_module_cache = NULL;
>
> return UWX_OK;
> }
>
> struct uwx_self_info *uwx_self_init_info(struct uwx_env *env)
> {
> struct uwx_self_info *info;
>
> info = (struct uwx_self_info *)
> (*env->allocate_cb)(sizeof(struct uwx_self_info));
> if (info == 0)
> return 0;
>
> uwx_self_init_info_block(env, info);
> info->on_heap = 1;
76,79c72,77
< if (info->free_cb == 0)
< free((void *)info);
< else
< (*info->free_cb)((void *)info);
---
> int i;
>
> if (info->load_module_cache != NULL)
> uwx_free_load_module_cache(info);
> if (info->on_heap)
> (*info->env->free_cb)((void *)info);
99a98,99
> if (status != 0)
> return UWX_ERR_UCACCESS;
100a101,102
> if (status != 0)
> return UWX_ERR_UCACCESS;
101a104,105
> if (status != 0)
> return UWX_ERR_UCACCESS;
102a107,108
> if (status != 0)
> return UWX_ERR_UCACCESS;
104a111,112
> if (status != 0)
> return UWX_ERR_UCACCESS;
105a114,115
> if (status != 0)
> return UWX_ERR_UCACCESS;
106a117,118
> if (status != 0)
> return UWX_ERR_UCACCESS;
108a121,122
> if (status != 0)
> return UWX_ERR_UCACCESS;
109a124,125
> if (status != 0)
> return UWX_ERR_UCACCESS;
110a127,128
> if (status != 0)
> return UWX_ERR_UCACCESS;
139c157
< if (status != 0)
---
> if (status != UWX_OK)
141c159,160
< return uwx_self_init_from_sigcontext(env, info, (ucontext_t *)ucontext);
---
> return uwx_self_init_from_sigcontext(env, info,
> (ucontext_t *)(intptr_t)ucontext);
167c186
< *wp = *(unsigned long *)rem;
---
> *wp = *(unsigned long *)(intptr_t)rem;
172c191
< *dp = *(uint64_t *)rem;
---
> *dp = *(uint64_t *)(intptr_t)rem;
184c203
< *dp = *(uint64_t *)rem;
---
> *dp = *(uint64_t *)(intptr_t)rem;
190c209
< (uint64_t *)rem, 1, dp);
---
> (uint64_t *)(intptr_t)rem, 1, dp);
232a252
> #define MODULE_CACHE_SIZE 4
233a254,334
> struct load_module_cache {
> int clock;
> char *names[MODULE_CACHE_SIZE];
> struct load_module_desc descs[MODULE_CACHE_SIZE];
> struct uwx_symbol_cache *symbol_cache;
> };
>
> void uwx_free_load_module_cache(struct uwx_self_info *info)
> {
> int i;
>
> for (i = 0; i < MODULE_CACHE_SIZE; i++) {
> if (info->load_module_cache->names[i] != NULL)
> (*info->env->free_cb)((void *)info->load_module_cache->names[i]);
> }
>
> if (info->load_module_cache->symbol_cache != NULL)
> uwx_release_symbol_cache(info->env,
> info->load_module_cache->symbol_cache);
>
> (*info->env->free_cb)((void *)info->load_module_cache);
> }
>
> struct load_module_desc *uwx_get_modinfo(
> struct uwx_self_info *info,
> uint64_t ip,
> char **module_name_p)
> {
> int i;
> UINT64 handle;
> struct load_module_cache *cache;
> struct load_module_desc *desc;
> char *module_name;
>
> cache = info->load_module_cache;
> if (cache == NULL) {
> cache = (struct load_module_cache *)
> (*info->env->allocate_cb)(sizeof(struct load_module_cache));
> if (cache == NULL)
> return NULL;
> for (i = 0; i < MODULE_CACHE_SIZE; i++) {
> desc = &cache->descs[i];
> desc->text_base = 0;
> desc->text_size = 0;
> cache->names[i] = NULL;
> }
> cache->clock = 0;
> cache->symbol_cache = NULL;
> info->load_module_cache = cache;
> }
> for (i = 0; i < MODULE_CACHE_SIZE; i++) {
> desc = &cache->descs[i];
> if (ip >= desc->text_base && ip < desc->text_base + desc->text_size)
> break;
> }
> if (i >= MODULE_CACHE_SIZE) {
> i = cache->clock;
> cache->clock = (cache->clock + 1) % MODULE_CACHE_SIZE;
> desc = &cache->descs[i];
> handle = dlmodinfo(ip, desc, sizeof(*desc), 0, 0, 0);
> if (handle == 0)
> return NULL;
> if (cache->names[i] != NULL)
> (*info->env->free_cb)(cache->names[i]);
> cache->names[i] = NULL;
> }
> if (module_name_p != NULL) {
> if (cache->names[i] == NULL) {
> module_name = dlgetname(desc, sizeof(*desc), 0, 0, 0);
> if (module_name != NULL) {
> cache->names[i] = (char *)
> (*info->env->allocate_cb)(strlen(module_name)+1);
> if (cache->names[i] != NULL)
> strcpy(cache->names[i], module_name);
> }
> }
> *module_name_p = cache->names[i];
> }
> return desc;
> }
>
242c343
< struct load_module_desc desc;
---
> struct load_module_desc *desc;
244a346,348
> char *module_name;
> char *func_name;
> uint64_t offset;
245a350
> int status;
253a359
> rvec[i++] = UWX_KEY_END;
255d360
< rvec[i++] = 0;
260,261c365,366
< handle = dlmodinfo(ip, &desc, sizeof(desc), 0, 0, 0);
< if (handle == 0)
---
> desc = uwx_get_modinfo(info, ip, NULL);
> if (desc == NULL)
263,264c368,370
< unwind_base = (uint64_t *) desc.unwind_base;
< TRACE_SELF_LOOKUP_DESC(desc.text_base, unwind_base)
---
> unwind_base = (uint64_t *) (intptr_t) desc->unwind_base;
> TRACE_SELF_LOOKUP_DESC(desc->text_base,
> desc->linkage_ptr, unwind_base)
268c374
< rvec[i++] = desc.text_base;
---
> rvec[i++] = desc->text_base;
272c378
< rvec[i++] = desc.text_base + unwind_base[1];
---
> rvec[i++] = desc->text_base + unwind_base[1];
274c380,383
< rvec[i++] = desc.text_base + unwind_base[2];
---
> rvec[i++] = desc->text_base + unwind_base[2];
> rvec[i++] = UWX_KEY_GP;
> rvec[i++] = desc->linkage_ptr;
> rvec[i++] = UWX_KEY_END;
276d384
< rvec[i++] = 0;
283a392,441
> else if (request == UWX_LKUP_MODULE) {
> desc = uwx_get_modinfo(info, ip, &module_name);
> if (desc == NULL)
> return UWX_LKUP_ERR;
> if (module_name == NULL)
> return UWX_LKUP_ERR;
> i = 0;
> rvec = info->rvec;
> rvec[i++] = UWX_KEY_MODULE;
> rvec[i++] = (uint64_t)(intptr_t)module_name;
> rvec[i++] = UWX_KEY_TBASE;
> rvec[i++] = desc->text_base;
> rvec[i++] = UWX_KEY_END;
> rvec[i++] = 0;
> *resultp = rvec;
> return UWX_LKUP_SYMINFO;
> }
> else if (request == UWX_LKUP_SYMBOLS) {
> rvec = *resultp;
> for (i = 0; rvec[i] != UWX_KEY_END; i += 2) {
> if (rvec[i] == UWX_KEY_FUNCSTART)
> ip = rvec[i+1];
> }
> desc = uwx_get_modinfo(info, ip, &module_name);
> if (desc == NULL)
> return UWX_LKUP_ERR;
> if (module_name == NULL)
> return UWX_LKUP_ERR;
> status = uwx_find_symbol(info->env,
> &info->load_module_cache->symbol_cache,
> module_name, ip - desc->text_base,
> &func_name, &offset);
> i = 0;
> rvec = info->rvec;
> rvec[i++] = UWX_KEY_MODULE;
> rvec[i++] = (uint64_t)(intptr_t)module_name;
> rvec[i++] = UWX_KEY_TBASE;
> rvec[i++] = desc->text_base;
> if (status == UWX_OK) {
> rvec[i++] = UWX_KEY_FUNC;
> rvec[i++] = (uint64_t)(intptr_t)func_name;
> rvec[i++] = UWX_KEY_FUNCSTART;
> rvec[i++] = ip - offset;
> }
> rvec[i++] = UWX_KEY_END;
> rvec[i++] = 0;
> *resultp = rvec;
> return UWX_LKUP_SYMINFO;
> }
> return UWX_LKUP_ERR;