Refactored error handling (#62)
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.
This commit is contained in:
10
src/dlhook.h
10
src/dlhook.h
@@ -8,11 +8,11 @@ extern "C" {
|
||||
|
||||
// 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). If
|
||||
// an error occurs, NULL is returned and if err is a valid pointer, it is set to
|
||||
// a malloc'd string describing it. This function requires glibc and Linux. It
|
||||
// should work on any architecture, and it should be resilient to most errors.
|
||||
NM_PRIVATE void *nm_dlhook(void *handle, const char *symname, void *target, char **err_out);
|
||||
// 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user