63 Commits

Author SHA1 Message Date
vivek.j
322ff67050 [lib][miniheap] fix: modify the assert condition in miniheap
For LK_DEBUGLEVEL > 1
> alloc_struct_begin_size: 24
> free_heap_chunk_size: 24

size: max(alloc_struct_begin_size, free_heap_chunk_size)

But when freeing the chunk, allocated size is expected to be
greater than size of free_heap_chunk struct.
It contradicts its own code.
So add >= instead of > to maintain the integrity between
allocation and freeing of memory chunk.

Signed-off-by: vivek.j <vivek.j@samsung.com>
2025-04-05 00:25:54 -07:00
Travis Geiselbrecht
ed3876dae7 [lib][cmpctmalloc] mark cmpctmalloc as needing float
It's just a test routine that's using floating point, but since nothing
in cmpctmalloc should be used in interrupt context, it should be okay to
mark this code as using float.
2024-05-14 00:47:43 -07:00
Mingjie Shen
ed2a3a754d [lib][heap] Fix array index out-of-range
argv[] should have at least 3 elements because argv[2] is accessed in line 345.
2024-03-01 15:22:36 -08:00
Alex Richardson
e40ac2a883 [clang] Avoid a nested function in heap_wrapper.c
This GCC extension is not supported by clang and in this case is not
necessary. Move the function to the top level to avoid the syntax error.
2023-06-01 17:50:50 -07:00
Travis Geiselbrecht
5a3d51e3e7 [assert] fix up a few places broken at DEBUG=0 after recent assert changes
Forgot to test at DEBUG=0. Both of these are basically cases where
the new DEBUG_ASSERT_COND should be used, since the default DEBUG_ASSERT
will now always emit code that gets cleaned up in the optimizer.
2021-04-02 20:16:53 -07:00
Travis Geiselbrecht
ebdc1ea077 [lib][libcpp] move c++ specific shims out of libc and heap
Consolidate into a single library. Also renames legacy new.h to
the more standard new.

Possible that some C++ code will need to get this added to their
MODULE_DEPS.
2021-04-02 19:28:58 -07:00
Travis Geiselbrecht
4edb93adde [lib][console] rename some console command types to be prefixed with console_
Some of the structures, notably 'cmd', in the lib console stuff are a
little too generically named and have collided with some other code
so prefix the names a bit more cleanly with console_

The change is largely mechanical, and folks with out of tree code can
easily switch by renaming:
cmd -> console_cmd
cmd_args -> console_cmd_args
cmd_block -> console_cmd_block
console_cmd -> console_cmd_func

Apologies if this breaks you but it should be pretty easy to fix.
2020-07-25 15:59:58 -07:00
Travis Geiselbrecht
3e5319ff14 [lib][cmpctmalloc] add some missing statics to inline 2020-05-16 19:05:28 -07:00
Travis Geiselbrecht
1b36390a39 [heap][miniheap] fix assert when miniheap is initialized with a non 8 byte aligned ptr on 64bit cpu 2020-01-16 23:38:38 -08:00
Travis Geiselbrecht
ad246760ff [c++] remove WITH_CPP_SUPPORT flag
Just always build with it enabled.
2019-07-13 17:41:25 -07:00
Travis Geiselbrecht
6cb02526b7 [include][console] split lib/console.h into two
TL;DR most uses of lib/console.h -> lk/console_cmd.h

Move the part that lets a piece of code somewhere in the system to
define a console command from the actual lib/console api to start an
instance of the console. Move in almost every place the user of the
console command definition to the new header, lk/console_cmd.h which is
always in the include path.

Also remove most uses of testing for WITH_LIB_CONSOLE since you can
almost always just safely define it and then let the linker remove it.
2019-07-13 16:56:33 -07:00
Travis Geiselbrecht
3aecdda231 [includes] replace header guards with #pragma once 2019-07-13 15:46:16 -07:00
Travis Geiselbrecht
cba9e47987 [license] replace the longer full MIT license with a shorter one
Used scripts/replacelic. Everything seems to build fine.
2019-07-05 17:22:23 -07:00
Travis Geiselbrecht
3699e45942 [include][lib] move most of the dangling top level include/lib/.h files into their lib
Only remaining one is console.h which is a little funny and will need to
be dealt with separately.
2019-06-19 22:44:15 -07:00
Travis Geiselbrecht
d8fa82cb91 [formatting] run everything through codestyle
Almost nothing changes here except moving braces to the same line as the
function declaration. Everything else is largely whitespace changes and
a few dangling files with tab indents.

See scripts/codestyle
2019-06-19 21:02:24 -07:00
Travis Geiselbrecht
1b7a28efb8 [include][lk] fixup lk/ include path move 2019-06-19 19:46:11 -07:00
Travis Geiselbrecht
7bbf6d5831 [nit] fix extraneous trailing ; in CDECLS lines 2018-12-16 16:49:40 -08:00
klemens
d0b90c2d68 [spelling] spelling-fixes. (not external/) 2016-08-25 17:30:34 -07:00
Erik Corry
4a553a7941 [pull][cmpctmalloc] Fix cmpctmalloc for large allocations (#147) 2016-06-21 09:35:40 -07:00
Erik Corry
6d0122b98e [heap] Add API used by Dartino to get arena list 2016-03-23 21:22:39 +01:00
Travis Geiselbrecht
7c412c38d7 [lib][heap] move dlmalloc implementation to external/ 2016-02-20 11:31:51 -08:00
Travis Geiselbrecht
2eb32a4369 [style] mass reformat all the non external code to 4 space indents
Ran everything through scripts/codestyle.space, which uses astyle
to generally follow K&R style.

Biggest non whitespace change is pulling brackets down on function
declarations, which I'm pretty ambivalent about, but astyle insists
on taking a stance
2016-02-14 12:24:01 -08:00
Gurjant Kalsi
52f4728c44 [magic][constants] Convert all of LK's multichar character kernel magic constants to hex. 2016-02-09 15:02:05 -08:00
Erik Corry
ddbb67ad25 [lib][cmpctmalloc] Tweak bucket sizes to optimize power-of-2 allocs. Fix and test heap_trim better 2015-11-13 12:48:12 -08:00
Travis Geiselbrecht
08955ff63f [heap][cmpctmalloc] mark some internal functions as static 2015-11-05 17:03:38 -08:00
Erik Corry
12868bf6c0 [lib][heap] Add Cmpctmalloc as an alternative malloc implementation
From scratch simple binning heap. Complexity wise in the middle
between miniheap and dlmalloc. Generally much faster than miniheap
with a small amount of memory overhead. Performs similarly to
dlmalloc.
2015-11-05 16:47:03 -08:00
Travis Geiselbrecht
2526e28809 [lib][heap] add a command to toggle heap tracing
The code is only built on debug builds.
2015-10-22 16:42:21 -07:00
Travis Geiselbrecht
619f916716 [lib][miniheap] add trim function
Add miniheap trim routine, which will attempt to free pages back to the
page allocator when called. Currently not called by anyone, unless
MINIHEAP_AUTOTRIM is set.
2015-10-22 13:28:18 -07:00
Travis Geiselbrecht
24bf6c850e [lib][heap] use absolute path in the heap rules.mk
Fixes a bug when using the LKROOT based split repository.
2015-10-21 16:47:40 -07:00
Travis Geiselbrecht
35ebee0e40 [merge] branch 'heapswitch'
This picks up the major work of allowing multiple heap implementations
and enable dlmalloc as an alternate heap to the simple existing one
(now called 'miniheap').

Also added a novm page allocator for memory management on systems too small
or missing an mmu to have a vm. Not much more than a simple bitmap allocator
that the heap pulls from. Allows for other heaps and/or users of physical
memory to coexist and span multiple banks of memory.
2015-10-20 16:53:00 -07:00
Travis Geiselbrecht
8d49a21989 [kernel][novm] refactor the novm code to handle multiple installable arenas
Only initialize the first arena, and allow installing more from platform code
as more memory banks are brought up.
Move novm into a separate module.
2015-10-20 16:18:57 -07:00
Travis Geiselbrecht
1485131d00 [lib][heap] refactor top level malloc/free into lib/heap
Flatten a level by moving malloc/free/new and friends into lib/heap.
Punch realloc and a few others directly through into the underlying
heap implementation. Remove heap_alloc and heap_free entirely.
2015-10-19 14:57:51 -07:00
Travis Geiselbrecht
1c6e80f171 [lib][heap] factor out the heap_grow api and have miniheap & dlmalloc call page_alloc directly 2015-10-19 14:02:30 -07:00
Travis Geiselbrecht
65de7f865c [lib][heap] fix crash when page allocator runs out of memory 2015-10-19 13:02:19 -07:00
Travis Geiselbrecht
38f20ec0a1 [lib][console] add pointer type arg, switch some users to it.
Patch courtesy Erik Corry
2015-10-19 12:49:20 -07:00
Travis Geiselbrecht
fab92f3179 [lib][heap] have novm initialize itself, rename novm 'heap' to 'arena' to be less confusing 2015-10-15 18:15:45 -07:00
Travis Geiselbrecht
e9a6bd0ea1 WIP get the heap code pointing at the new page allocator 2015-10-15 16:52:02 -07:00
Travis Geiselbrecht
80bf0a48b4 [lib][heap] fix some formatting and a bug or two in the novm and page alloc stuff 2015-10-15 15:46:35 -07:00
Travis Geiselbrecht
3bbc7ac101 WIP patch from erik 2015-10-15 15:30:49 -07:00
Travis Geiselbrecht
6b06d322a2 [lib][heap] add info dump for dlmalloc, wire in heap trimming code 2015-10-15 15:22:30 -07:00
Travis Geiselbrecht
6bd49c3917 [lib][heap] more WIP on heap stuffs 2015-10-15 14:53:00 -07:00
Travis Geiselbrecht
1193213dfd WIP get dlmalloc working with a mmap() style allocator out of the heap wrapper 2015-10-14 19:56:24 -07:00
Travis Geiselbrecht
30bfd752b1 [lib][heap] first stab at breaking the heap into a generic heap layer and a specific implementation
The old implementation is now called 'miniheap'
2015-10-14 18:14:30 -07:00
Arve Hjønnevåg
f84c38287c [lib][heap] Print error message when heap_grow fails.
Change-Id: Idf6d0e1c6cf638c3fe1ef02560c27028b6eef99d
2015-05-13 20:20:39 -07:00
Travis Geiselbrecht
8fb2c54304 [kernel] remove critical_section, move everything to spinlocks 2015-03-10 16:43:54 -07:00
Arve Hjønnevåg
efe4f94bbf [lib][heap] Fix alignment rounding to not truncate address to 32 bit on lp64 systems.
Change-Id: I69f84e3cdd715824db3eae24ed0c2c4aff1cf959
2015-03-08 19:05:11 -07:00
Travis Geiselbrecht
25a78c5225 [lib][heap] have the heap pull pages out of the vm, if present 2014-07-11 18:11:58 -07:00
Travis Geiselbrecht
5d0f6f1bf1 [lib][heap] add routine to add new free block to an existing heap 2014-01-27 00:00:43 -08:00
Travis Geiselbrecht
f4952a0e69 [lib][heap] fix fatal crash with DEBUG_HEAP on
DEBUG_HEAP would wipe out the allocated block immediately,
which would crash heap_delayed_free(). Add boolean to allow this
behavior to be skipped during delayed free. Also causes initial
bootstrap of heap to go faster by not completely filling it.
2014-01-26 23:26:07 -08:00
Travis Geiselbrecht
78d5223945 [lib][heap] make the heap 64bit safe, only put magic value if needed 2014-01-26 22:46:39 -08:00