* Implemented a way to specify additional debug options via MALLOC_DEBUG when
using libroot_debug.so, instead of having to hardcode them in the application via calling private heap functions. * The following options are implemented: 'p' turns on paranoid validation, 'w' triggers periodic wall checking every 500ms ('W' does the same, but every 100ms), 'g' to use guard pages (beware, this will dramatically increase memory usage), and 'r' which forbids reusing of memory, freed memory is never actually freed. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40514 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
415bb095f3
commit
3d0d4b6200
@ -32,6 +32,7 @@ status_t __flatten_process_args(const char* const* args, int32 argCount,
|
||||
void _call_atexit_hooks_for_range(addr_t start, addr_t size);
|
||||
void __init_env(const struct user_space_program_args *args);
|
||||
void __init_heap(void);
|
||||
void __init_heap_post_env(void);
|
||||
|
||||
void __init_time(void);
|
||||
void __arch_init_time(struct real_time_data *data, bool setDefaults);
|
||||
|
@ -58,6 +58,7 @@ initialize_before(image_id imageID)
|
||||
__init_time();
|
||||
__init_heap();
|
||||
__init_env(__gRuntimeLoader->program_args);
|
||||
__init_heap_post_env();
|
||||
__init_pwd_backend();
|
||||
}
|
||||
|
||||
|
@ -119,6 +119,13 @@ __init_heap(void)
|
||||
}
|
||||
|
||||
|
||||
extern "C" void
|
||||
__init_heap_post_env(void)
|
||||
{
|
||||
// no heap options available
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
insert_chunk(free_chunk *newChunk)
|
||||
{
|
||||
|
@ -2,13 +2,14 @@
|
||||
* Copyright 2008-2009, Michael Lotz, mmlr@mlotz.ch.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Copyright 2002-2006, Axel Dörfler, axeld@pinc-software.de.
|
||||
* Copyright 2002-2011, Axel Dörfler, axeld@pinc-software.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Copyright 2001, Travis Geiselbrecht. All rights reserved.
|
||||
* Distributed under the terms of the NewOS License.
|
||||
*/
|
||||
|
||||
|
||||
#include <malloc.h>
|
||||
#include <malloc_debug.h>
|
||||
#include <stdio.h>
|
||||
@ -41,6 +42,7 @@ static bool sReuseMemory = true;
|
||||
static bool sParanoidValidation = false;
|
||||
static thread_id sWallCheckThread = -1;
|
||||
static bool sStopWallChecking = false;
|
||||
static bool sUseGuardPage = false;
|
||||
|
||||
|
||||
void
|
||||
@ -1817,6 +1819,25 @@ __init_heap(void)
|
||||
}
|
||||
|
||||
|
||||
extern "C" void
|
||||
__init_heap_post_env(void)
|
||||
{
|
||||
const char *mode = getenv("MALLOC_DEBUG");
|
||||
if (mode != NULL) {
|
||||
if (strchr(mode, 'p'))
|
||||
heap_debug_set_paranoid_validation(true);
|
||||
if (strchr(mode, 'w'))
|
||||
heap_debug_start_wall_checking(500);
|
||||
else if (strchr(mode, 'W'))
|
||||
heap_debug_start_wall_checking(100);
|
||||
if (strchr(mode, 'g'))
|
||||
sUseGuardPage = true;
|
||||
if (strchr(mode, 'r'))
|
||||
heap_debug_set_memory_reuse(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - Public API
|
||||
|
||||
|
||||
@ -1908,6 +1929,9 @@ memalign(size_t alignment, size_t size)
|
||||
void *
|
||||
malloc(size_t size)
|
||||
{
|
||||
if (sUseGuardPage)
|
||||
return heap_debug_malloc_with_guard_page(size);
|
||||
|
||||
return memalign(0, size);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user