Merge "Fix broken return code of M_INITIALIZE_GWP_ASAN." am: b47aa42a11
am: 10878a22ca
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1831562 Change-Id: I056bc2722172241d8d8f6509e68c399a2e90870a
This commit is contained in:
commit
a588c14e26
5 changed files with 34 additions and 6 deletions
|
@ -277,3 +277,14 @@ bool MaybeInitGwpAsan(libc_globals* globals, bool force_init) {
|
|||
bool DispatchIsGwpAsan(const MallocDispatch* dispatch) {
|
||||
return dispatch == &gwp_asan_dispatch;
|
||||
}
|
||||
|
||||
bool EnableGwpAsan(bool force_init) {
|
||||
if (GwpAsanInitialized) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ret_value;
|
||||
__libc_globals.mutate(
|
||||
[&](libc_globals* globals) { ret_value = MaybeInitGwpAsan(globals, force_init); });
|
||||
return ret_value;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,9 @@
|
|||
#include <private/bionic_malloc_dispatch.h>
|
||||
#include <stddef.h>
|
||||
|
||||
// Enable GWP-ASan, used by android_mallopt.
|
||||
bool EnableGwpAsan(bool force_init);
|
||||
|
||||
// Hooks for libc to possibly install GWP-ASan.
|
||||
bool MaybeInitGwpAsanFromLibc(libc_globals* globals);
|
||||
|
||||
|
|
|
@ -330,9 +330,8 @@ extern "C" bool android_mallopt(int opcode, void* arg, size_t arg_size) {
|
|||
errno = EINVAL;
|
||||
return false;
|
||||
}
|
||||
__libc_globals.mutate([&](libc_globals* globals) {
|
||||
return MaybeInitGwpAsan(globals, *reinterpret_cast<bool*>(arg));
|
||||
});
|
||||
|
||||
return EnableGwpAsan(*reinterpret_cast<bool*>(arg));
|
||||
}
|
||||
errno = ENOTSUP;
|
||||
return false;
|
||||
|
|
|
@ -530,9 +530,8 @@ extern "C" bool android_mallopt(int opcode, void* arg, size_t arg_size) {
|
|||
errno = EINVAL;
|
||||
return false;
|
||||
}
|
||||
__libc_globals.mutate([&](libc_globals* globals) {
|
||||
return MaybeInitGwpAsan(globals, *reinterpret_cast<bool*>(arg));
|
||||
});
|
||||
|
||||
return EnableGwpAsan(*reinterpret_cast<bool*>(arg));
|
||||
}
|
||||
// Try heapprofd's mallopt, as it handles options not covered here.
|
||||
return HeapprofdMallopt(opcode, arg, arg_size);
|
||||
|
|
|
@ -1268,6 +1268,22 @@ TEST(android_mallopt, set_allocation_limit_multiple_threads) {
|
|||
#endif
|
||||
}
|
||||
|
||||
TEST(android_mallopt, force_init_gwp_asan) {
|
||||
#if defined(__BIONIC__)
|
||||
bool force_init = true;
|
||||
ASSERT_TRUE(android_mallopt(M_INITIALIZE_GWP_ASAN, &force_init, sizeof(force_init)));
|
||||
|
||||
// Verify that trying to do the call again also passes no matter the
|
||||
// value of force_init.
|
||||
force_init = false;
|
||||
ASSERT_TRUE(android_mallopt(M_INITIALIZE_GWP_ASAN, &force_init, sizeof(force_init)));
|
||||
force_init = true;
|
||||
ASSERT_TRUE(android_mallopt(M_INITIALIZE_GWP_ASAN, &force_init, sizeof(force_init)));
|
||||
#else
|
||||
GTEST_SKIP() << "bionic extension";
|
||||
#endif
|
||||
}
|
||||
|
||||
void TestHeapZeroing(int num_iterations, int (*get_alloc_size)(int iteration)) {
|
||||
std::vector<void*> allocs;
|
||||
constexpr int kMaxBytesToCheckZero = 64;
|
||||
|
|
Loading…
Reference in a new issue