mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-08 08:07:10 +02:00
MINOR: tools: add functions to retrieve the address of a symbol
get_sym_curr_addr() will return the address of the first occurrence of the given symbol while get_sym_next_addr() will return the address of the next occurrence of the symbol. These ones return NULL on non-linux, non-ELF, non-USE_DL.
This commit is contained in:
parent
d3a88c1c32
commit
64192392c4
@ -1003,6 +1003,8 @@ void dump_hex(struct buffer *out, const char *pfx, const void *buf, int len, int
|
|||||||
int may_access(const void *ptr);
|
int may_access(const void *ptr);
|
||||||
const void *resolve_sym_name(struct buffer *buf, const char *pfx, const void *addr);
|
const void *resolve_sym_name(struct buffer *buf, const char *pfx, const void *addr);
|
||||||
const char *get_exec_path();
|
const char *get_exec_path();
|
||||||
|
void *get_sym_curr_addr(const char *name);
|
||||||
|
void *get_sym_next_addr(const char *name);
|
||||||
|
|
||||||
/* Note that this may result in opening libgcc() on first call, so it may need
|
/* Note that this may result in opening libgcc() on first call, so it may need
|
||||||
* to have been called once before chrooting.
|
* to have been called once before chrooting.
|
||||||
|
43
src/tools.c
43
src/tools.c
@ -4740,7 +4740,50 @@ static int dladdr_and_size(const void *addr, Dl_info *dli, size_t *size)
|
|||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Tries to retrieve the address of the first occurrence symbol <name>.
|
||||||
|
* Note that NULL in return is not always an error as a symbol may have that
|
||||||
|
* address in special situations.
|
||||||
|
*/
|
||||||
|
void *get_sym_curr_addr(const char *name)
|
||||||
|
{
|
||||||
|
void *ptr = NULL;
|
||||||
|
|
||||||
|
#ifdef RTLD_DEFAULT
|
||||||
|
ptr = dlsym(RTLD_DEFAULT, name);
|
||||||
#endif
|
#endif
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Tries to retrieve the address of the next occurrence of symbol <name>
|
||||||
|
* Note that NULL in return is not always an error as a symbol may have that
|
||||||
|
* address in special situations.
|
||||||
|
*/
|
||||||
|
void *get_sym_next_addr(const char *name)
|
||||||
|
{
|
||||||
|
void *ptr = NULL;
|
||||||
|
|
||||||
|
#ifdef RTLD_NEXT
|
||||||
|
ptr = dlsym(RTLD_NEXT, name);
|
||||||
|
#endif
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else /* elf & linux & dl */
|
||||||
|
|
||||||
|
/* no possible resolving on other platforms at the moment */
|
||||||
|
void *get_sym_curr_addr(const char *name)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *get_sym_next_addr(const char *name)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* elf & linux & dl */
|
||||||
|
|
||||||
/* Tries to append to buffer <buf> some indications about the symbol at address
|
/* Tries to append to buffer <buf> some indications about the symbol at address
|
||||||
* <addr> using the following form:
|
* <addr> using the following form:
|
||||||
|
Loading…
Reference in New Issue
Block a user