add dummy_malloc functions
For some environments the dummy malloc functions offer a very small alternative implementation. malloc will get its memory from sbrk() and never frees memory again. This of course is not suitable for interactive environments and thus depends on CONFIG_SHELL_NONE Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
2a37624950
commit
523daf675a
|
@ -148,6 +148,22 @@ config EXPERIMENTAL
|
|||
bool
|
||||
prompt "Prompt for experimental code"
|
||||
|
||||
choice
|
||||
prompt "malloc implementation"
|
||||
|
||||
config MALLOC_DLMALLOC
|
||||
bool "dlmalloc"
|
||||
|
||||
config MALLOC_DUMMY
|
||||
bool "dummy malloc"
|
||||
depends on SHELL_NONE
|
||||
help
|
||||
select this option to use a dummy malloc implementation. With this
|
||||
memory is never freed. This is suitable for well tested noninteractive
|
||||
environments only.
|
||||
|
||||
endchoice
|
||||
|
||||
config MODULES
|
||||
depends on HAS_MODULES
|
||||
depends on EXPERIMENTAL
|
||||
|
|
|
@ -9,7 +9,8 @@ obj-$(CONFIG_POLLER) += poller.o
|
|||
obj-$(CONFIG_BLOCK) += block.o
|
||||
|
||||
obj-y += memory.o
|
||||
obj-y += dlmalloc.o
|
||||
obj-$(CONFIG_MALLOC_DLMALLOC) += dlmalloc.o
|
||||
obj-$(CONFIG_MALLOC_DUMMY) += dummy_malloc.o
|
||||
obj-y += clock.o
|
||||
obj-y += version.o
|
||||
obj-$(CONFIG_COMMAND_SUPPORT) += command.o
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
#include <common.h>
|
||||
#include <malloc.h>
|
||||
|
||||
void *memalign(size_t alignment, size_t bytes)
|
||||
{
|
||||
unsigned long mem = (unsigned long)sbrk(bytes + alignment);
|
||||
|
||||
mem = (mem + alignment) & ~(alignment - 1);
|
||||
|
||||
return (void *)mem;
|
||||
}
|
||||
|
||||
void *malloc(size_t size)
|
||||
{
|
||||
return memalign(8, size);
|
||||
}
|
||||
|
||||
void free(void *ptr)
|
||||
{
|
||||
}
|
||||
|
||||
void *realloc(void *ptr, size_t size)
|
||||
{
|
||||
BUG();
|
||||
}
|
||||
|
Loading…
Reference in New Issue