summaryrefslogtreecommitdiffstats
path: root/arch/sandbox
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2020-07-27 21:58:41 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2020-07-27 21:58:41 +0200
commit8b0bf1ee077715ceb0535fbda799038ea62baef8 (patch)
tree2ef39a48cc78e4b2ec9d37643d4f7c6c320f0341 /arch/sandbox
parent67f0e7aedefcb06b38ef50ddd32b0a280bbb10e8 (diff)
parenta66ffa8dab14b82f9f9edddb03d6358b861ff5c0 (diff)
downloadbarebox-8b0bf1ee077715ceb0535fbda799038ea62baef8.tar.gz
barebox-8b0bf1ee077715ceb0535fbda799038ea62baef8.tar.xz
Merge branch 'for-next/misc'
Diffstat (limited to 'arch/sandbox')
-rw-r--r--arch/sandbox/Kconfig5
-rw-r--r--arch/sandbox/Makefile1
-rw-r--r--arch/sandbox/include/asm/elf.h1
-rw-r--r--arch/sandbox/include/asm/types.h19
-rw-r--r--arch/sandbox/os/Makefile6
-rw-r--r--arch/sandbox/os/common.c8
-rw-r--r--arch/sandbox/os/libc_malloc.c36
7 files changed, 57 insertions, 19 deletions
diff --git a/arch/sandbox/Kconfig b/arch/sandbox/Kconfig
index 3f10709021..40e04919d2 100644
--- a/arch/sandbox/Kconfig
+++ b/arch/sandbox/Kconfig
@@ -24,6 +24,9 @@ config SANDBOX_UNWIND
select ARCH_HAS_STACK_DUMP
depends on UBSAN || KASAN
+config PHYS_ADDR_T_64BIT
+ bool
+
config CC_IS_64BIT
def_bool $(success,$(srctree)/scripts/gcc-64bitptr.sh $(CC))
@@ -34,6 +37,8 @@ config 64BIT
bool
default n if SANDBOX_LINUX_I386
default CC_IS_64BIT
+ select ARCH_DMA_ADDR_T_64BIT
+ select PHYS_ADDR_T_64BIT
config SANDBOX_LINUX_I386
bool "32-bit x86 barebox" if CC_HAS_LINUX_I386_SUPPORT
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/include/asm/elf.h b/arch/sandbox/include/asm/elf.h
index 3939336ccb..e71a60aeb9 100644
--- a/arch/sandbox/include/asm/elf.h
+++ b/arch/sandbox/include/asm/elf.h
@@ -3,7 +3,6 @@
#if __SIZEOF_POINTER__ == 8
#define ELF_CLASS ELFCLASS64
-#define CONFIG_PHYS_ADDR_T_64BIT
#else
#define ELF_CLASS ELFCLASS32
#endif
diff --git a/arch/sandbox/include/asm/types.h b/arch/sandbox/include/asm/types.h
index 3e4a8f7ba3..7b356a99eb 100644
--- a/arch/sandbox/include/asm/types.h
+++ b/arch/sandbox/include/asm/types.h
@@ -1,21 +1,6 @@
-#ifndef __ASM_I386_TYPES_H
-#define __ASM_I386_TYPES_H
+#ifndef __ASM_SANDBOX_TYPES_H
+#define __ASM_SANDBOX_TYPES_H
#include <asm-generic/int-ll64.h>
-#ifdef __x86_64__
-/*
- * This is used in dlmalloc. On X86_64 we need it to be
- * 64 bit
- */
-#define INTERNAL_SIZE_T unsigned long
-
-/*
- * This is a Kconfig variable in the Kernel, but we want to detect
- * this during compile time, so we set it here.
- */
-#define CONFIG_PHYS_ADDR_T_64BIT
-
-#endif
-
#endif
diff --git a/arch/sandbox/os/Makefile b/arch/sandbox/os/Makefile
index b2f95087dc..b2bd768bcb 100644
--- a/arch/sandbox/os/Makefile
+++ b/arch/sandbox/os/Makefile
@@ -7,6 +7,11 @@ KBUILD_CPPFLAGS = $(patsubst %,-I$(srctree)/%include,$(machdirs))
KBUILD_CPPFLAGS += -DCONFIG_MALLOC_SIZE=$(CONFIG_MALLOC_SIZE)
KBUILD_CFLAGS := -Wall
+
+ifeq ($(CONFIG_KASAN),y)
+KBUILD_CPPFLAGS += -DCONFIG_KASAN=1
+endif
+
NOSTDINC_FLAGS :=
ifeq ($(CONFIG_SANDBOX_LINUX_I386),y)
@@ -14,6 +19,7 @@ KBUILD_CFLAGS += -m32
endif
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/common.c b/arch/sandbox/os/common.c
index 382a923040..69fadb3b47 100644
--- a/arch/sandbox/os/common.c
+++ b/arch/sandbox/os/common.c
@@ -44,6 +44,8 @@
#include <mach/linux.h>
#include <mach/hostfile.h>
+void __sanitizer_set_death_callback(void (*callback)(void));
+
int sdl_xres;
int sdl_yres;
@@ -268,7 +270,7 @@ static int add_image(char *str, char *devname_template, int *devname_number)
hf->base = (unsigned long)mmap(NULL, hf->size,
PROT_READ | (readonly ? 0 : PROT_WRITE),
MAP_SHARED, fd, 0);
- if ((void *)hf->base == MAP_FAILED)
+ if (hf->base == (unsigned long)MAP_FAILED)
printf("warning: mmapping %s failed: %s\n", filename, strerror(errno));
ret = barebox_register_filedev(hf);
@@ -345,6 +347,10 @@ int main(int argc, char *argv[])
int fdno = 0, envno = 0, option_index = 0;
char *aux;
+#ifdef CONFIG_KASAN
+ __sanitizer_set_death_callback(cookmode);
+#endif
+
while (1) {
option_index = 0;
opt = getopt_long(argc, argv, optstring,
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);
+}