From 4787e8398f4d0376f31cffc0771b71f5bbdd9d52 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Tue, 14 Apr 2009 19:54:38 +0200 Subject: Only set sec in _stp_mod_sec_lookup when not NULL. * runtime/sym.c (_stp_mod_sec_lookup): Only set sec when not NULL. --- runtime/sym.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'runtime/sym.c') diff --git a/runtime/sym.c b/runtime/sym.c index a2cdd0ff..fc9b2e80 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -150,7 +150,8 @@ static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, if (user != NULL) { m = (struct _stp_module *)user; - *sec = &m->sections[0]; // XXX check actual section and relocate + if (sec) + *sec = &m->sections[0]; // XXX check actual section and relocate dbug_sym(1, "found section %s in module %s at 0x%lx\n", m->sections[0].name, m->name, vm_start); if (strcmp(".dynamic", m->sections[0].name) == 0) -- cgit From c1af604e1c626b90834113ba7d71c4a2ea1bda68 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Tue, 14 Apr 2009 20:58:26 +0200 Subject: Make sure addr falls inside section in _stp_mod_sec_lookup. * runtime/sym.c (_stp_mod_sec_lookup): Use section size to match addr. Only return exact matches, not just closes offset. --- runtime/sym.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'runtime/sym.c') diff --git a/runtime/sym.c b/runtime/sym.c index fc9b2e80..f6f97ac2 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -136,9 +136,7 @@ static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, struct _stp_section **sec) { void *user = NULL; - struct _stp_module *m = NULL; unsigned midx = 0; - unsigned long closest_section_offset = ~0; // Try vma matching first if task given. if (task) @@ -149,7 +147,7 @@ static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, NULL, &user) == 0) if (user != NULL) { - m = (struct _stp_module *)user; + struct _stp_module *m = (struct _stp_module *)user; if (sec) *sec = &m->sections[0]; // XXX check actual section and relocate dbug_sym(1, "found section %s in module %s at 0x%lx\n", @@ -165,21 +163,19 @@ static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, unsigned secidx; for (secidx = 0; secidx < _stp_modules[midx]->num_sections; secidx++) { - unsigned long this_section_addr; - unsigned long this_section_offset; - this_section_addr = _stp_modules[midx]->sections[secidx].addr; - if (addr < this_section_addr) continue; - this_section_offset = addr - this_section_addr; - if (this_section_offset < closest_section_offset) - { - closest_section_offset = this_section_offset; - m = _stp_modules[midx]; + unsigned long sec_addr; + unsigned long sec_size; + sec_addr = _stp_modules[midx]->sections[secidx].addr; + sec_size = _stp_modules[midx]->sections[secidx].size; + if (addr >= sec_addr && addr < sec_addr + sec_size) + { if (sec) - *sec = & m->sections[secidx]; + *sec = & _stp_modules[midx]->sections[secidx]; + return _stp_modules[midx]; } } } - return m; + return NULL; } -- cgit