Merge "Copy the M_THREAD_DISABLE_MEM_INIT constant value into malloc.h."
This commit is contained in:
commit
155901898d
2 changed files with 28 additions and 0 deletions
|
@ -170,6 +170,16 @@ int malloc_info(int __must_be_zero, FILE* __fp) __INTRODUCED_IN(23);
|
|||
* Available since API level 28.
|
||||
*/
|
||||
#define M_PURGE (-101)
|
||||
/*
|
||||
* mallopt() option for per-thread memory initialization tuning.
|
||||
* The value argument should be one of:
|
||||
* 1: Disable automatic heap initialization and, where possible, memory tagging,
|
||||
* on this thread.
|
||||
* 0: Normal behavior.
|
||||
*
|
||||
* Available since API level 31.
|
||||
*/
|
||||
#define M_THREAD_DISABLE_MEM_INIT (-103)
|
||||
/**
|
||||
* mallopt() option to set the maximum number of items in the secondary
|
||||
* cache of the scudo allocator.
|
||||
|
|
|
@ -84,6 +84,24 @@ TEST(malloc, calloc_std) {
|
|||
free(ptr);
|
||||
}
|
||||
|
||||
TEST(malloc, calloc_mem_init_disabled) {
|
||||
#if defined(__BIONIC__)
|
||||
// calloc should still zero memory if mem-init is disabled.
|
||||
// With jemalloc the mallopts will fail but that shouldn't affect the
|
||||
// execution of the test.
|
||||
mallopt(M_THREAD_DISABLE_MEM_INIT, 1);
|
||||
size_t alloc_len = 100;
|
||||
char *ptr = reinterpret_cast<char*>(calloc(1, alloc_len));
|
||||
for (size_t i = 0; i < alloc_len; i++) {
|
||||
ASSERT_EQ(0, ptr[i]);
|
||||
}
|
||||
free(ptr);
|
||||
mallopt(M_THREAD_DISABLE_MEM_INIT, 0);
|
||||
#else
|
||||
GTEST_SKIP() << "bionic-only test";
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(malloc, calloc_illegal) {
|
||||
SKIP_WITH_HWASAN;
|
||||
errno = 0;
|
||||
|
|
Loading…
Reference in a new issue