diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2020-07-06 08:28:05 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2020-07-14 20:28:09 +0200 |
commit | 94fb245bd6946b24639e5c374b36bc41d8833fdb (patch) | |
tree | 31b49fc693f5e61c19fca3d7d050fe7110f86dc7 | |
parent | 4c0809a21073af2d482683ec5327f59b31c355ff (diff) | |
download | barebox-94fb245bd6946b24639e5c374b36bc41d8833fdb.tar.gz barebox-94fb245bd6946b24639e5c374b36bc41d8833fdb.tar.xz |
sandbox: add libc memory allocator
While we typically want to reuse as much barebox functionality as
possible in sandbox, using system malloc(3) instead can be very
useful when using external memory integrity tools. This is even
useful for AddressSanitizer, because the reports resulting from
the memory poisoning API are less detailed than the built-in
support for the libc malloc(3).
Note that a barebox "heap" is still allocated upfront. It's only
used for request_sdram_region now though. Whatever is allocated by
means of malloc and memalign will be ina disjunct heap.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | arch/sandbox/Makefile | 1 | ||||
-rw-r--r-- | arch/sandbox/os/Makefile | 1 | ||||
-rw-r--r-- | arch/sandbox/os/libc_malloc.c | 36 | ||||
-rw-r--r-- | common/Kconfig | 7 |
4 files changed, 45 insertions, 0 deletions
diff --git a/arch/sandbox/Makefile b/arch/sandbox/Makefile index c08ea0cf83..27021222dc 100644 --- a/arch/sandbox/Makefile +++ b/arch/sandbox/Makefile @@ -12,6 +12,7 @@ lds-y := $(BOARD)/barebox.lds 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 ed921443e0..df6d597e78 100644 --- a/arch/sandbox/os/Makefile +++ b/arch/sandbox/os/Makefile @@ -10,6 +10,7 @@ KBUILD_CFLAGS += -Wall 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 0000000000..74e3e26805 --- /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 <a.fatoum@pengutronix.de> + */ + +#include <stdlib.h> +#include <malloc.h> + +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 ac282d8955..4bd4a09738 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -313,6 +313,13 @@ config MALLOC_DUMMY 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 |