summaryrefslogtreecommitdiffstats
path: root/src/core/malloc.c
Commit message (Collapse)AuthorAgeFilesLines
* [init] Show startup and shutdown function names in debug messagesMichael Brown2019-01-251-0/+1
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [malloc] Avoid false positive warnings from valgrindMichael Brown2017-09-041-1/+8
| | | | | | | | | | | | | | Calling discard_cache() is likely to result in a call to free_memblock(), which will call valgrind_make_blocks_noaccess() before returning. This causes valgrind to report an invalid read on the next iteration through the loop in alloc_memblock(). Fix by explicitly calling valgrind_make_blocks_defined() after discard_cache() returns. Also call valgrind_make_blocks_noaccess() before calling discard_cache(), to guard against free list corruption while executing cache discarders. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [malloc] Track maximum heap usageMichael Brown2017-03-221-3/+21
| | | | | | | Track the current and maximum heap usage, and display the maximum during shutdown when DEBUG=malloc is enabled. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [malloc] Guard against unsigned integer overflowMichael Brown2016-02-061-2/+13
| | | | | | | | | | | | | Commit f3fbb5f ("[malloc] Avoid integer overflow for excessively large memory allocations") fixed signed integer overflow issues caused by the use of ssize_t, but did not guard against unsigned integer overflow. Add explicit checks for unsigned integer overflow where needed. As a side bonus, erroneous calls to malloc_dma() with an (illegal) size of zero will now fail cleanly. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [malloc] Avoid integer overflow for excessively large memory allocationsMichael Brown2015-09-291-48/+49
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [malloc] Rewrite unrelicensable portions of malloc.cMichael Brown2015-03-031-22/+41
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [malloc] Report caller address as soon as memory corruption is detectedMichael Brown2014-12-151-1/+21
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [malloc] Check integrity of free listMichael Brown2014-12-151-1/+59
| | | | | | | | | | | | | | | | | | Check the integrity of the free memory block list before and after any modifications to the list. We check that certain invariants are preserved: - the list is a well-formed doubly linked list - all blocks are at least MIN_MEMBLOCK_SIZE - no block extends beyond the end of our address space - blocks remain sorted in ascending order of address - no blocks are adjacent (i.e. any adjacent blocks have been merged) Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [malloc] Sanity check parameters to alloc_memblock() and free_memblock()Michael Brown2014-12-151-0/+6
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [malloc] Tidy up debug outputMichael Brown2014-12-151-19/+23
| | | | | | Colourise debug output and move per-allocation messages to DBGLVL_EXTRA. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [malloc] Allow allocation of memory with a specified alignment offsetMichael Brown2012-08-311-5/+7
| | | | | | | | Allow for allocation of memory blocks having a specified offset from a specified physical alignment, such as being 12 bytes before a 2kB boundary. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [legal] Update FSF mailing address in GPL licence textsMichael Brown2012-07-201-1/+2
| | | | | Suggested-by: Daniel P. Berrange <berrange@redhat.com> Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [malloc] Increase heap size to 512kBMichael Brown2012-07-091-2/+2
| | | | | | | | The maximum TCP throughput is fundamentally limited by the amount of available receive buffer space. Increase the heap size from 128kB to 512kB to allow the use of larger TCP windows. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [malloc] Discard cached items less aggressivelyMichael Brown2012-07-091-3/+5
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [malloc] Allow Valgrind to be used when all assertions are enabledMichael Brown2012-05-041-11/+67
| | | | | | | | | | | | The free-memory-block traversal code triggers multiple warnings from Valgrind when assertions are enabled, since the list consistency checks performed by list_check() end up accessing areas that have been marked as inaccessible. Fix by ensuring that any memory areas that will be accessed by list_check() are marked as defined when necessary. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [malloc] Discard all cached data on shutdownMichael Brown2012-05-041-0/+25
| | | | | | | Allow detection of genuine memory leaks by ensuring that all cached data is freed on shutdown. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [linux] Make malloc and linux_umalloc valgrindablePiotr Jaroszyński2011-03-271-2/+57
| | | | | | | | | | Make the allocators used by malloc and linux_umalloc valgrindable. Include valgrind headers in the codebase to avoid a build dependency on valgrind. Signed-off-by: Piotr Jaroszyński <p.jaroszynski@gmail.com> Modified-by: Michael Brown <mcb30@ipxe.org> Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [malloc] Avoid immediately clobbering reference count when freeing memoryMichael Brown2010-11-081-2/+14
| | | | | | | | | | Rearrange the fields in struct memory_block (without altering MIN_MEMBLOCK_SIZE) so that the "count" field of a reference-counted object is left intact when the memory containing the object is freed. This allows for the possibility of detecting reference-counting errors such as double-freeing. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [malloc] Use list_for_each_entry_safe() when we may delete a list entryMichael Brown2010-11-081-1/+2
| | | | | | | | | | | | | | free_memblock() currently uses list_for_each_entry() to iterate over the free list, and may delete an entry over which it iterates. While there is no way that the deleted list entry could be overwritten before we reference it, this does rely upon list_del() leaving the "next" pointer intact, which is not guaranteed. Discovered while tracking down a list-corruption bug (as a result of having modified list_del() to sanitise the deleted list entry). Fix by using list_for_each_entry_safe(). Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [malloc] Add cache discard mechanismMichael Brown2010-07-211-46/+68
| | | | | | | Add a facility allowing cached data to be discarded in order to satisfy memory allocations that would otherwise fail. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [build] Rename gPXE to iPXEMichael Brown2010-04-201-4/+4
| | | | | | | | | | | Access to the gpxe.org and etherboot.org domains and associated resources has been revoked by the registrant of the domain. Work around this problem by renaming project from gPXE to iPXE, and updating URLs to match. Also update README, LOG and COPYRIGHTS to remove obsolete information. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [legal] Add a selection of FILE_LICENCE declarationsMichael Brown2009-05-181-0/+2
| | | | | Add FILE_LICENCE declarations to almost all files that make up the various standard builds of gPXE.
* [ioapi] Remove old io.h file and switch all users over to <gpxe/io.h>Michael Brown2008-10-121-1/+1
|
* Revert "malloc attribute changes"Holger Lubitz2007-08-061-4/+0Star
| | | | | wasn't meant for my local "master" branch ;) This reverts commit 373022108ba389fb3d50a3d50f9baf64c6c82171.
* malloc attribute changesHolger Lubitz2007-08-021-0/+4
|
* Separated out initialisation functions from startup/shutdown functions.Michael Brown2007-07-041-0/+24
|
* Renamed _calloc() to zalloc(), ready to be used as a standalone function.Michael Brown2007-06-111-1/+4
|
* Use stdio.h instead of vsprintf.hMichael Brown2007-01-191-1/+1
|
* Move include/malloc.h to include/gpxe/malloc.h, since everything in thereMichael Brown2007-01-181-1/+10
| | | | | | | is now gPXE-specific. (The standard malloc() et al have been in stdlib.h for a while). Add free memory counter.
* Don't always zero memory in malloc(). This saves around 2us on aMichael Brown2007-01-181-2/+17
| | | | full-length PKB allocation.
* Fix typoMichael Brown2007-01-121-1/+1
|
* Implemented realloc(), and changed the semantics of malloc(0) to allowMichael Brown2006-11-241-15/+79
| | | | for realloc(0) being a valid way to free memory.
* We don't actually have a stdio.h header file. Our printf() functions areMichael Brown2006-09-271-1/+0Star
| | | | | | | | defined in vsprintf.h. (This may change, since vsprintf.h is a non-standard name, but for now it's the one to use.) There should be no need to include vsprintf.h just for DBG() statements, since include/compiler.h forces it in for a debug build anyway.
* include stdio.h to suppress printf warning, general warnings fixupsMarty Connor2006-09-271-0/+2
|
* Tidied up debugging messagesMichael Brown2006-05-271-4/+4
|
* Fix typoMichael Brown2006-05-161-1/+1
|
* Add an explicit failure debug messageMichael Brown2006-04-281-0/+2
|
* Glenn managed to shrink .text by 5 more bytes.Michael Brown2006-04-251-3/+6
|
* Fixed erroneous comparisonMichael Brown2006-04-251-1/+1
|
* Removed incorrect comment; malloc() is inefficient only when theMichael Brown2006-04-251-5/+0Star
| | | | | alignment and size are both powers of two, and there's no way to specify an alignment through the malloc() interface anyway.
* Now passes trivial tests. free_memblock() needs neatening up.Michael Brown2006-04-251-15/+34
|
* Updated memory allocator to improve support for unaligned or partiallyMichael Brown2006-04-251-118/+158
| | | | | | | | | aligned blocks. Moved header to include/malloc.h, since we now also provide the POSIX-like malloc()/free() pair. Not yet tested.
* First draft of a dynamic memory allocatorMichael Brown2006-04-241-0/+209