summaryrefslogtreecommitdiffstats
path: root/arch/sandbox
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2020-07-06 08:28:05 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2020-07-14 20:28:09 +0200
commit94fb245bd6946b24639e5c374b36bc41d8833fdb (patch)
tree31b49fc693f5e61c19fca3d7d050fe7110f86dc7 /arch/sandbox
parent4c0809a21073af2d482683ec5327f59b31c355ff (diff)
downloadbarebox-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>
Diffstat (limited to 'arch/sandbox')
-rw-r--r--arch/sandbox/Makefile1
-rw-r--r--arch/sandbox/os/Makefile1
-rw-r--r--arch/sandbox/os/libc_malloc.c36
3 files changed, 38 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);
+}