Add hooking functionality

This allows us to hook chosen functions and do interesting things there (in
particular: reentrancy checking).
This commit is contained in:
David Goldblatt
2017-03-28 17:30:54 -07:00
committed by David Goldblatt
parent 36bd90b962
commit 0a0fcd3e6a
19 changed files with 183 additions and 11 deletions

38
test/unit/hooks.c Normal file
View File

@@ -0,0 +1,38 @@
#include "test/jemalloc_test.h"
static bool hook_called = false;
static void
hook() {
hook_called = true;
}
static int
func_to_hook(int arg1, int arg2) {
return arg1 + arg2;
}
#define func_to_hook JEMALLOC_HOOK(func_to_hook, hooks_libc_hook)
TEST_BEGIN(unhooked_call) {
hooks_libc_hook = NULL;
hook_called = false;
assert_d_eq(3, func_to_hook(1, 2), "Hooking changed return value.");
assert_false(hook_called, "Nulling out hook didn't take.");
}
TEST_END
TEST_BEGIN(hooked_call) {
hooks_libc_hook = &hook;
hook_called = false;
assert_d_eq(3, func_to_hook(1, 2), "Hooking changed return value.");
assert_true(hook_called, "Hook should have executed.");
}
TEST_END
int
main(void) {
return test(
unhooked_call,
hooked_call);
}

View File

@@ -76,6 +76,6 @@ TEST_END
int
main(void) {
return test(
return test_no_reentrancy(
test_idump);
}

View File

@@ -112,6 +112,6 @@ TEST_END
int
main(void) {
return test(
return test_no_reentrancy(
test_prof_active);
}

View File

@@ -69,6 +69,6 @@ TEST_END
int
main(void) {
return test(
return test_no_reentrancy(
test_gdump);
}

View File

@@ -278,7 +278,7 @@ main(void) {
/* Intercept dumping prior to running any tests. */
prof_dump_open = prof_dump_open_intercept;
return test(
return test_no_reentrancy(
test_prof_reset_basic,
test_prof_reset_cleanup,
test_prof_reset,

View File

@@ -41,6 +41,6 @@ TEST_END
int
main(void) {
return test(
return test_no_reentrancy(
test_prof_realloc);
}

View File

@@ -79,6 +79,7 @@ thd_start(void *arg) {
}
TEST_BEGIN(test_tsd_main_thread) {
test_skip_if(test_is_reentrant());
thd_start((void *)(uintptr_t)0xa5f3e329);
}
TEST_END