Instead of using and checking malloc'd error strings formatted with asprintf and passed through a pointer in function arguments, use a global thread-local statically allocated error buffer with functions to set and get it. This is more efficient, less error-prone, and easier to use than the old method, especially now that NM is larger (meaning that errors are returned through multiple layers) and parts of it are re-used in other things.
21 lines
625 B
C
21 lines
625 B
C
#ifndef NM_DLHOOK_H
|
|
#define NM_DLHOOK_H
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include "util.h"
|
|
|
|
// nm_dlhook takes a lib handle from dlopen and redirects the specified symbol
|
|
// to another, returning a pointer to the original one. Only calls from within
|
|
// that library itself are affected (because it replaces that library's GOT).
|
|
// This function requires glibc and Linux. It should work on any architecture,
|
|
// and it should be resilient to most errors. If it fails, NULL is returned and
|
|
// nm_err is set.
|
|
NM_PRIVATE void *nm_dlhook(void *handle, const char *symname, void *target);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
#endif
|