History log of /haiku/headers/posix/malloc_debug.h
Revision Date Author Comments
# ec0190ad 10-Apr-2015 Michael Lotz <mmlr@mlotz.ch>

malloc_debug: Implement allocation dump on exit in guarded heap.

When enabled (using heap_debug_dump_allocations_on_exit(true) or
MALLOC_DEBUG=e) this causes a dump of all remaining allocations when
libroot_debug is unloaded. It uses terminate_after to be called as
late as possible.

When combined with alloc stack traces this makes for a nice if a bit
crude leak checker. Note that a lot of allocations usually remain
even at that stage due to statically, lazyly and globally allocated
stuff from the various system libraries where it isn't necessarily
worth the overhead to free them when the program terminates anyway.


# 158e20e6 10-Apr-2015 Michael Lotz <mmlr@mlotz.ch>

malloc_debug: Implement alloc/free stack traces in guarded heap.

When configured to do so (using heap_debug_set_stack_trace_depth(depth)
or MALLOC_DEBUG=s<depth>) the guarded heap now captures stack traces on
alloc and free.

A crash due to hitting a guard page or an already freed page now dumps
these stack traces. In the case of use-after-free one can therefore see
both where the allocation was done and where it was freed.

Note that there is a hardcoded maximum stack trace depth of 50 and that
the alloc stack trace takes away space from the free stack trace which
uses up the rest of that maximum.


# 121655e9 04-Apr-2015 Michael Lotz <mmlr@mlotz.ch>

malloc_debug: Add default alignment option.

This allows for something similar as was implemented in 217f090 but
makes it optional and configurable.

The MALLOC_DEBUG environment variable now can take "a<size>" to set
the default alignment to the specified size. Note that not all
alignments may be supported depending on the heap implementation.


# 173f54f1 19-Jul-2012 Matt Madia <mattmadia@gmail.com>

Updated copyright in headers. No functional change.


# 0fae8733 03-Nov-2010 Scott McCreary <scottmc2@gmail.com>

Updated posix headers to remove commas from copyright line, to match the preferred coding guidelines.
Cleaned up some header style violations, making sure there are two blank lines after the header guards.
This fixes the posix header part of #2191.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39288 a95241bf-73f2-0310-859d-f6bbb57e9c96


# ac653a30 15-Feb-2010 Michael Lotz <mmlr@mlotz.ch>

Add heap_debug_set_debugger_calls() which allows to disable debugger calls for
the heap debug panics. Instead syslog output is generated if turned off.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35481 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c1502cf1 15-Feb-2010 Michael Lotz <mmlr@mlotz.ch>

Add heap_debug_get_allocation_info() to retrieve the size of the allocation as
well as the thread allocating it. Can for example be used to verify that an
object or buffer is as large as expected.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35480 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 081ff2db 15-Feb-2010 Michael Lotz <mmlr@mlotz.ch>

* Add heap_debug_set_memory_reuse() which allows to disable memory reuse,
keeping all returned heap memory in the 0xdeadbeef state (including the
first sizeof(void *) bytes otherwise for the free list). While wasting a lot
of memory it allows you to rely on 0xdeadbeef being always present as no
future allocation will reuse the freed memory block.
* Also added heap_debug_malloc_with_guard_page() which is intended to allocate
a memory block so it is aligned that the start of invalid memory past the
allocation is in an unmapped guard page. However the kernel backend that would
guarantee this is not yet implemented, so right now this works only by chance
if no other area happens to be allocated exactly past the created one. With a
very specifc suspicion you can put that one allocation you get to good use
though. It causes a crash when accessing memory past the allocation size so
you actually get a backtrace from where the access happened instead of only
after freeing/wall checking.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35478 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f6a6245c 07-Feb-2010 Michael Lotz <mmlr@mlotz.ch>

* Adding malloc_debug.h that exposes the malloc_debug API.
* Moving some functions around, removing and adding others for the public API.

I've written a blog post at haiku-os.org to go as documentation for this
introducing the API and the other helpful bits.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35431 a95241bf-73f2-0310-859d-f6bbb57e9c96


# ec0190adb0a9abe5a796d31468f421896eb47124 10-Apr-2015 Michael Lotz <mmlr@mlotz.ch>

malloc_debug: Implement allocation dump on exit in guarded heap.

When enabled (using heap_debug_dump_allocations_on_exit(true) or
MALLOC_DEBUG=e) this causes a dump of all remaining allocations when
libroot_debug is unloaded. It uses terminate_after to be called as
late as possible.

When combined with alloc stack traces this makes for a nice if a bit
crude leak checker. Note that a lot of allocations usually remain
even at that stage due to statically, lazyly and globally allocated
stuff from the various system libraries where it isn't necessarily
worth the overhead to free them when the program terminates anyway.


# 158e20e60e97eaa9845c5d6c90f234855be86fb1 10-Apr-2015 Michael Lotz <mmlr@mlotz.ch>

malloc_debug: Implement alloc/free stack traces in guarded heap.

When configured to do so (using heap_debug_set_stack_trace_depth(depth)
or MALLOC_DEBUG=s<depth>) the guarded heap now captures stack traces on
alloc and free.

A crash due to hitting a guard page or an already freed page now dumps
these stack traces. In the case of use-after-free one can therefore see
both where the allocation was done and where it was freed.

Note that there is a hardcoded maximum stack trace depth of 50 and that
the alloc stack trace takes away space from the free stack trace which
uses up the rest of that maximum.


# 121655e9ee3e7fa6d9244df8c68ad30f9981af8c 04-Apr-2015 Michael Lotz <mmlr@mlotz.ch>

malloc_debug: Add default alignment option.

This allows for something similar as was implemented in 217f090 but
makes it optional and configurable.

The MALLOC_DEBUG environment variable now can take "a<size>" to set
the default alignment to the specified size. Note that not all
alignments may be supported depending on the heap implementation.


# 173f54f1473bd6a6511c5fc6dc899c91fb8dd667 19-Jul-2012 Matt Madia <mattmadia@gmail.com>

Updated copyright in headers. No functional change.


# 0fae873352b02792db93f721c1a2ff6b240c8ecc 03-Nov-2010 Scott McCreary <scottmc2@gmail.com>

Updated posix headers to remove commas from copyright line, to match the preferred coding guidelines.
Cleaned up some header style violations, making sure there are two blank lines after the header guards.
This fixes the posix header part of #2191.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39288 a95241bf-73f2-0310-859d-f6bbb57e9c96


# ac653a30df0e86b403333b4d9a78aba5df8aa7f7 15-Feb-2010 Michael Lotz <mmlr@mlotz.ch>

Add heap_debug_set_debugger_calls() which allows to disable debugger calls for
the heap debug panics. Instead syslog output is generated if turned off.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35481 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c1502cf1b80d3b63ee2f0da4300f3a1800cc57c6 15-Feb-2010 Michael Lotz <mmlr@mlotz.ch>

Add heap_debug_get_allocation_info() to retrieve the size of the allocation as
well as the thread allocating it. Can for example be used to verify that an
object or buffer is as large as expected.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35480 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 081ff2db288890922fa40094d80558de6656b9ac 15-Feb-2010 Michael Lotz <mmlr@mlotz.ch>

* Add heap_debug_set_memory_reuse() which allows to disable memory reuse,
keeping all returned heap memory in the 0xdeadbeef state (including the
first sizeof(void *) bytes otherwise for the free list). While wasting a lot
of memory it allows you to rely on 0xdeadbeef being always present as no
future allocation will reuse the freed memory block.
* Also added heap_debug_malloc_with_guard_page() which is intended to allocate
a memory block so it is aligned that the start of invalid memory past the
allocation is in an unmapped guard page. However the kernel backend that would
guarantee this is not yet implemented, so right now this works only by chance
if no other area happens to be allocated exactly past the created one. With a
very specifc suspicion you can put that one allocation you get to good use
though. It causes a crash when accessing memory past the allocation size so
you actually get a backtrace from where the access happened instead of only
after freeing/wall checking.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35478 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f6a6245c8936995c9b23ab65a5b3854ea6a5088b 07-Feb-2010 Michael Lotz <mmlr@mlotz.ch>

* Adding malloc_debug.h that exposes the malloc_debug API.
* Moving some functions around, removing and adding others for the public API.

I've written a blog post at haiku-os.org to go as documentation for this
introducing the API and the other helpful bits.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35431 a95241bf-73f2-0310-859d-f6bbb57e9c96