9os

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 64762c83f7aa8b11202a2c3584e3ca4f25326a43
parent 4d650d8e49e406f1f2f1dba6caa63b530dcf5788
Author: Roberto Vargas <roberto.vargas@arm.com>
Date:   Mon, 26 Nov 2018 11:34:07 +0000

[native/rom] Check correct size of bss static structures

Change-Id: I09f20458822c08d1be4a7a0a01003ce598a1a331

Diffstat:
Mtarget/native/rom.c | 20++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/target/native/rom.c b/target/native/rom.c @@ -1,3 +1,5 @@ +#include <errno.h> +#include <stdlib.h> #include <string.h> #include <libk.h> @@ -10,7 +12,8 @@ #define ENVPOS 7 #define ENVSIZ (sizeof(struct _Env) + ENVPOS*sizeof(char *)) -#define BSSSIZ 1024 +#define BSSSIZ 2048 +#define STACKSIZ 1024 typedef struct mach Mach; @@ -59,6 +62,17 @@ imach(Mach *mp, void *txt, size_t txtsiz, void *ram, size_t ramsiz) mp->bss_ = (bp -= BSSSIZ); mp->sp = bp - 16; + wsysreg(TPIDR_R, (uintptr_t) mp->bss_); + + /* + * At this moment we can panic safely + * but we will not see any message + * because we don't have configured + * a console + */ + if (ENVSIZ + BSSSIZ + STACKSIZ > ramsiz) + panic("imach"); + mp->stacksiz = bp - ramp; mp->envsiz = ENVSIZ; mp->bsssiz = BSSSIZ; @@ -76,7 +90,9 @@ ibss(Mach *mp) { struct _Env *envp; - wsysreg(TPIDR_R, (uintptr_t) mp->bss_); + if (sizeof(struct bssmap) > BSSSIZ) + panic("ibss"); + bss->text = mp->txt; bss->backtrace = 1; bss->dumpstack = 1;