diff --git a/arch/sandbox/Makefile b/arch/sandbox/Makefile index c08ea0c..2702122 100644 --- a/arch/sandbox/Makefile +++ b/arch/sandbox/Makefile @@ -12,6 +12,7 @@ TEXT_BASE = $(CONFIG_TEXT_BASE) KBUILD_CFLAGS += -Dmalloc=barebox_malloc -Dcalloc=barebox_calloc \ + -Dmalloc_stats=barebox_malloc_stats -Dmemalign=barebox_memalign \ -Dfree=barebox_free -Drealloc=barebox_realloc \ -Dread=barebox_read -Dwrite=barebox_write \ -Dopen=barebox_open -Dclose=barebox_close \ diff --git a/arch/sandbox/os/Makefile b/arch/sandbox/os/Makefile index ed92144..df6d597 100644 --- a/arch/sandbox/os/Makefile +++ b/arch/sandbox/os/Makefile @@ -10,6 +10,7 @@ NOSTDINC_FLAGS := obj-y = common.o tap.o +obj-$(CONFIG_MALLOC_LIBC) += libc_malloc.o CFLAGS_sdl.o = $(shell pkg-config sdl --cflags) obj-$(CONFIG_DRIVER_VIDEO_SDL) += sdl.o diff --git a/arch/sandbox/os/libc_malloc.c b/arch/sandbox/os/libc_malloc.c new file mode 100644 index 0000000..74e3e26 --- /dev/null +++ b/arch/sandbox/os/libc_malloc.c @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2020 Ahmad Fatoum + */ + +#include +#include + +void barebox_malloc_stats(void) +{ +} + +void *barebox_memalign(size_t alignment, size_t bytes) +{ + return memalign(alignment, bytes); +} + +void *barebox_malloc(size_t size) +{ + return malloc(size); +} + +void barebox_free(void *ptr) +{ + free(ptr); +} + +void *barebox_realloc(void *ptr, size_t size) +{ + return realloc(ptr, size); +} + +void *barebox_calloc(size_t n, size_t elem_size) +{ + return calloc(n, elem_size); +} diff --git a/common/Kconfig b/common/Kconfig index ac282d8..4bd4a09 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -313,6 +313,13 @@ memory is never freed. This is suitable for well tested noninteractive environments only. +config MALLOC_LIBC + bool "libc malloc" + depends on SANDBOX + help + select this option to use the libc malloc implementation in the sandbox. + This is benefecial for testing with external memory integrity tools. + endchoice config MODULES