History log of /haiku-fatelf/src/system/libroot/posix/malloc_debug/heap.cpp
Revision Date Author Comments
# 1eaa9e63 16-Aug-2012 Alex Smith <alex@alex-smith.me.uk>

Compilation fix for malloc_debug.


# ae901935 24-Nov-2011 Oliver Tappe <zooey@hirschkaefer.de>

Introduce __set_errno() throughout libroot.

* add errno_private.h, which defines the __set_errno() macro with
and without tracing
* instead of setting errno manually, all libroot's code now invokes
__set_errno(), which makes it much easier to trace changes to errno
* redirect glibc's use of __set_errno() to our own version


# fff761af 16-Feb-2011 Oliver Tappe <zooey@hirschkaefer.de>

Closing #7227:
* fix debug-heap's handling of page-guarded allocations in realloc()
* let calloc() use page-guarded allocations, too, if requested


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


# 3d0d4b62 15-Feb-2011 Axel Dörfler <axeld@pinc-software.de>

* 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


# 610a2eed 01-Mar-2010 Michael Lotz <mmlr@mlotz.ch>

Made heap classes const just in case. They really already were though.


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


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

Finish the implementation of heap_debug_malloc_with_guard_page() using mprotect
to make the guard page inaccessible. Thanks Ingo for the pointer!


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


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

Return an error when encountering an invalid allocation info.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35482 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


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

Must only advance by step sizes, otherwise we may end up with misaligned pages
again.


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


# 160abe26 06-Feb-2010 Michael Lotz <mmlr@mlotz.ch>

Sync two locking changes from kernel heap. This just moves the page locking into
the contiguous page allocation function and unlocks a bin locker a bit earlier.


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


# 638a24fa 06-Feb-2010 Michael Lotz <mmlr@mlotz.ch>

* Seperate the raw page wise allocation and allocations from bins.
* Make the contiguous page allocation capable of aligning the allocation
and make it more clever by checking up front if there's a chance of getting
enough pages at all, by giving up earlier if the page count can't be fit
anymore, and in the alignment case by only checking the pages which have a
valid alignment.
* If the alignment requirement is > B_PAGE_SIZE we now use page allocation
directly, because the bins aren't necesarily aligned on their size past
B_PAGE_SIZE anymore.
* When doing aligned bin allocation, calculate the aligned size up front and
choose the right heap for the allocation.
* Also when doing aligned bin allocations we not only need to round up the size
but also ensure that the bin we choose is aligned at all.
* Moved adding leak check info into it's own function.

Fixes various misalignment problems when working with alignments > B_PAGE_SIZE
or when using alignments < allocation size. Also the directly aligned page
allocations now only use up as many pages as actually required instead of
allocating based on the rounded up to align size.


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


# ee7ec205 22-Oct-2009 Michael Lotz <mmlr@mlotz.ch>

Account for single page allocations. They aren't used anywhere right now because
the bin sizes ensure that when hitting this case it always allocates multiple
pages. This makes it more flexible for other use cases though.


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


# 6bb41327 21-Oct-2009 Michael Lotz <mmlr@mlotz.ch>

The allocation size wasn't updated on an area based realloc that would still
fit into the existing area. In that case further reallocs could then assume the
wrong previous size and then not copy enough from the original buffer, leading
to lost bytes at the end of the new buffer.


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


# b501a038 17-Oct-2009 Michael Lotz <mmlr@mlotz.ch>

anevilyak+korli+mmlr:
* Check for overflows in memory allocation. If someone happened to (erroneously)
try to allocate a negative amount of memory we could overflow and crash
because of the sizes getting messed up.
* Review and update the alignment logic which was a bit broken for the huge
allocation case (reaching the area threshold). Also assert the results so
next time this will be easier to spot.


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


# 3bb69a82 12-Oct-2009 Michael Lotz <mmlr@mlotz.ch>

* Use mutex and rw_lock and the proper AutoLockers as in the kernel version, as
these interfaces are now available.
* Don't be quite so paranoid by default, the checks that are on by default
should be enough to detect most memory corruptions.

This makes the debug heap way more usable, so much that you can even use it as
your normal everyday heap without noticing much performance impact (it has quite
a bit of additional memory overhead though).


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


# aad5c042 05-Sep-2009 Michael Lotz <mmlr@mlotz.ch>

Add valloc() and posix_memalign() to malloc debug heap.


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


# a7123731 05-Sep-2009 Michael Lotz <mmlr@mlotz.ch>

Apply fix of r32951 to malloc debug heap as well.


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


# 185fd1c5 01-Sep-2009 Michael Lotz <mmlr@mlotz.ch>

Ported over the kernel heap to libroot to make use of it's validation
capabilities to aid in debugging memory corruption issues.

It does:
* Initialize memory to 0xcc to help turn up use of uninitialized memory
* Set freed memory to 0xdeadbeef to help find accesses of freed memory
* Use the paranoid heap validation to turn up many cases of memory corruption
* Use a simplistic wall check to turn up memory overwrites past allocations
* Take extra steps to validate freed addresses to turn up misaligned frees

It has an interface to en-/disable paranoid validation and to start/stop regular
wall checking. Both are currently just enabled. At a later stage a debug version
of libroot could be used by an application and the checks enabled at will. Note
that due to the paranoid validation and the suboptimal locking this allocator
will perform horribly. Still to find memory corruption issues in the system or
also in your applications it can be helpful to build your installation with it
turned on. To enable it you currently need to edit the Jamfile to sub-include
the malloc_debug instead of the malloc directory.


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


# 1eaa9e63cd2d8ce8ed11974e0314860bdd4eb621 16-Aug-2012 Alex Smith <alex@alex-smith.me.uk>

Compilation fix for malloc_debug.


# ae9019359606f1db67632ef51a77ce70001d3770 24-Nov-2011 Oliver Tappe <zooey@hirschkaefer.de>

Introduce __set_errno() throughout libroot.

* add errno_private.h, which defines the __set_errno() macro with
and without tracing
* instead of setting errno manually, all libroot's code now invokes
__set_errno(), which makes it much easier to trace changes to errno
* redirect glibc's use of __set_errno() to our own version


# fff761afaba8122ba2ec8af76c2004a8e9d6ba0c 16-Feb-2011 Oliver Tappe <zooey@hirschkaefer.de>

Closing #7227:
* fix debug-heap's handling of page-guarded allocations in realloc()
* let calloc() use page-guarded allocations, too, if requested


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


# 3d0d4b6200bc16c89e241afb715ce35f15f50020 15-Feb-2011 Axel Dörfler <axeld@pinc-software.de>

* 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


# 610a2eed63be6e9b81c23bb0461ea650274973a3 01-Mar-2010 Michael Lotz <mmlr@mlotz.ch>

Made heap classes const just in case. They really already were though.


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


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

Finish the implementation of heap_debug_malloc_with_guard_page() using mprotect
to make the guard page inaccessible. Thanks Ingo for the pointer!


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


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

Return an error when encountering an invalid allocation info.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35482 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


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

Must only advance by step sizes, otherwise we may end up with misaligned pages
again.


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


# 160abe2685548c91221a824b8309797a1869f504 06-Feb-2010 Michael Lotz <mmlr@mlotz.ch>

Sync two locking changes from kernel heap. This just moves the page locking into
the contiguous page allocation function and unlocks a bin locker a bit earlier.


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


# 638a24fa520c5adaab2f7d3297fc9f7ad3e611b2 06-Feb-2010 Michael Lotz <mmlr@mlotz.ch>

* Seperate the raw page wise allocation and allocations from bins.
* Make the contiguous page allocation capable of aligning the allocation
and make it more clever by checking up front if there's a chance of getting
enough pages at all, by giving up earlier if the page count can't be fit
anymore, and in the alignment case by only checking the pages which have a
valid alignment.
* If the alignment requirement is > B_PAGE_SIZE we now use page allocation
directly, because the bins aren't necesarily aligned on their size past
B_PAGE_SIZE anymore.
* When doing aligned bin allocation, calculate the aligned size up front and
choose the right heap for the allocation.
* Also when doing aligned bin allocations we not only need to round up the size
but also ensure that the bin we choose is aligned at all.
* Moved adding leak check info into it's own function.

Fixes various misalignment problems when working with alignments > B_PAGE_SIZE
or when using alignments < allocation size. Also the directly aligned page
allocations now only use up as many pages as actually required instead of
allocating based on the rounded up to align size.


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


# ee7ec20503558510377023a090bb36b19f7eebd3 22-Oct-2009 Michael Lotz <mmlr@mlotz.ch>

Account for single page allocations. They aren't used anywhere right now because
the bin sizes ensure that when hitting this case it always allocates multiple
pages. This makes it more flexible for other use cases though.


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


# 6bb413270ba254d2592b22cb4a1a7283e9989cbd 21-Oct-2009 Michael Lotz <mmlr@mlotz.ch>

The allocation size wasn't updated on an area based realloc that would still
fit into the existing area. In that case further reallocs could then assume the
wrong previous size and then not copy enough from the original buffer, leading
to lost bytes at the end of the new buffer.


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


# b501a0387df65dd53f9d5f7edc12e9e7d7cba100 17-Oct-2009 Michael Lotz <mmlr@mlotz.ch>

anevilyak+korli+mmlr:
* Check for overflows in memory allocation. If someone happened to (erroneously)
try to allocate a negative amount of memory we could overflow and crash
because of the sizes getting messed up.
* Review and update the alignment logic which was a bit broken for the huge
allocation case (reaching the area threshold). Also assert the results so
next time this will be easier to spot.


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


# 3bb69a8235d2f552a680d9f48d4a47dc3fe7eee4 12-Oct-2009 Michael Lotz <mmlr@mlotz.ch>

* Use mutex and rw_lock and the proper AutoLockers as in the kernel version, as
these interfaces are now available.
* Don't be quite so paranoid by default, the checks that are on by default
should be enough to detect most memory corruptions.

This makes the debug heap way more usable, so much that you can even use it as
your normal everyday heap without noticing much performance impact (it has quite
a bit of additional memory overhead though).


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


# aad5c04223a154a80f6e1fb201e8b99b987f8207 05-Sep-2009 Michael Lotz <mmlr@mlotz.ch>

Add valloc() and posix_memalign() to malloc debug heap.


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


# a7123731380cde8ac0a479503e00609bd5403e93 05-Sep-2009 Michael Lotz <mmlr@mlotz.ch>

Apply fix of r32951 to malloc debug heap as well.


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


# 185fd1c5d288172e07a6d33e3b3c2bc815ba05af 01-Sep-2009 Michael Lotz <mmlr@mlotz.ch>

Ported over the kernel heap to libroot to make use of it's validation
capabilities to aid in debugging memory corruption issues.

It does:
* Initialize memory to 0xcc to help turn up use of uninitialized memory
* Set freed memory to 0xdeadbeef to help find accesses of freed memory
* Use the paranoid heap validation to turn up many cases of memory corruption
* Use a simplistic wall check to turn up memory overwrites past allocations
* Take extra steps to validate freed addresses to turn up misaligned frees

It has an interface to en-/disable paranoid validation and to start/stop regular
wall checking. Both are currently just enabled. At a later stage a debug version
of libroot could be used by an application and the checks enabled at will. Note
that due to the paranoid validation and the suboptimal locking this allocator
will perform horribly. Still to find memory corruption issues in the system or
also in your applications it can be helpful to build your installation with it
turned on. To enable it you currently need to edit the Jamfile to sub-include
the malloc_debug instead of the malloc directory.


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