forked from jemalloc/jemalloc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sized-delete size-checking functionality.
The existing checks are good at finding such issues (on tcache flush), but not so good at pinpointing them. Debug mode can find them, but sometimes debug mode slows down a program so much that hard-to-hit bugs can take a long time to crash. This commit adds functionality to keep programs mostly on their fast paths, while also checking every sized delete argument they get.
- Loading branch information
1 parent
53084cc
commit eaed1e3
Showing
6 changed files
with
135 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "test/jemalloc_test.h" | ||
|
||
#include "jemalloc/internal/safety_check.h" | ||
|
||
bool fake_abort_called; | ||
void fake_abort(const char *message) { | ||
(void)message; | ||
fake_abort_called = true; | ||
} | ||
|
||
#define SIZE1 SC_SMALL_MAXCLASS | ||
#define SIZE2 (SC_SMALL_MAXCLASS / 2) | ||
|
||
TEST_BEGIN(test_invalid_size_sdallocx) { | ||
test_skip_if(!config_opt_size_checks); | ||
safety_check_set_abort(&fake_abort); | ||
|
||
fake_abort_called = false; | ||
void *ptr = malloc(SIZE1); | ||
assert_ptr_not_null(ptr, "Unexpected failure"); | ||
sdallocx(ptr, SIZE2, 0); | ||
expect_true(fake_abort_called, "Safety check didn't fire"); | ||
|
||
safety_check_set_abort(NULL); | ||
} | ||
TEST_END | ||
|
||
TEST_BEGIN(test_invalid_size_sdallocx_nonzero_flag) { | ||
test_skip_if(!config_opt_size_checks); | ||
safety_check_set_abort(&fake_abort); | ||
|
||
fake_abort_called = false; | ||
void *ptr = malloc(SIZE1); | ||
assert_ptr_not_null(ptr, "Unexpected failure"); | ||
sdallocx(ptr, SIZE2, MALLOCX_TCACHE_NONE); | ||
expect_true(fake_abort_called, "Safety check didn't fire"); | ||
|
||
safety_check_set_abort(NULL); | ||
} | ||
TEST_END | ||
|
||
TEST_BEGIN(test_invalid_size_sdallocx_noflags) { | ||
test_skip_if(!config_opt_size_checks); | ||
safety_check_set_abort(&fake_abort); | ||
|
||
fake_abort_called = false; | ||
void *ptr = malloc(SIZE1); | ||
assert_ptr_not_null(ptr, "Unexpected failure"); | ||
je_sdallocx_noflags(ptr, SIZE2); | ||
expect_true(fake_abort_called, "Safety check didn't fire"); | ||
|
||
safety_check_set_abort(NULL); | ||
} | ||
TEST_END | ||
|
||
int | ||
main(void) { | ||
return test( | ||
test_invalid_size_sdallocx, | ||
test_invalid_size_sdallocx_nonzero_flag, | ||
test_invalid_size_sdallocx_noflags); | ||
} |