diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2019-05-13 19:12:41 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2019-05-13 19:12:41 +0200 |
commit | 3b36daa2bb8c0f4169455baf829b9695b520c5fc (patch) | |
tree | 9da4980fe24b4464e4e8d4c9698afcd1b9549c0e /sys/src/9/bcm/bootargs.c | |
parent | 157d7ebdbd7479b271e7b1df744b2dfc6b5816e9 (diff) |
bcm, bcm64: preserve memsize across reboots, avoid trashing atags while parsing cmdline
we override atag memory on reboot, so preserve
the memsize learned from atag as *maxmem plan9
variable. the global memsize variable is not
needed anymore.
avoid trashing the following atag when zero
terminating the cmdline string.
zero memory after plan9.ini variables.
Diffstat (limited to 'sys/src/9/bcm/bootargs.c')
-rw-r--r-- | sys/src/9/bcm/bootargs.c | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/sys/src/9/bcm/bootargs.c b/sys/src/9/bcm/bootargs.c index a361f2828..830e9bc65 100644 --- a/sys/src/9/bcm/bootargs.c +++ b/sys/src/9/bcm/bootargs.c @@ -88,34 +88,37 @@ plan9iniinit(char *s, int cmdline) void bootargsinit(void) { + static char maxmem[11]; + char x, *e; Atag *a; - int n; - a = (Atag*)BOOTARGS; + e = BOOTARGS; + a = (Atag*)e; if(a->tag != AtagCore){ - plan9iniinit((char*)a, 0); + plan9iniinit(e, 0); return; } - while(a->tag != AtagNone && a->size != 0){ + while(a->tag != AtagNone){ + e += a->size * sizeof(u32int); + if(a->size < 2 || e < (char*)a || e > &BOOTARGS[BOOTARGSLEN]) + break; switch(a->tag){ case AtagMem: - /* use only first bank */ - if(conf.mem[0].limit == 0 && a->mem.size != 0){ - memsize = a->mem.size; - conf.mem[0].base = a->mem.base; - conf.mem[0].limit = a->mem.base + memsize; + if(findconf("*maxmem") < 0){ + snprint(maxmem, sizeof(maxmem), "%ud", a->mem.base+a->mem.size); + addconf("*maxmem", maxmem); } break; case AtagCmdline: - n = (a->size * sizeof(u32int)) - offsetof(Atag, cmdline[0]); - if(a->cmdline + n < BOOTARGS + BOOTARGSLEN) - a->cmdline[n] = 0; - else - BOOTARGS[BOOTARGSLEN-1] = 0; + x = *e; + *e = 0; plan9iniinit(a->cmdline, 1); + *e = x; break; } - a = (Atag*)((u32int*)a + a->size); + if(e > &BOOTARGS[BOOTARGSLEN-8]) + break; + a = (Atag*)e; } } @@ -164,6 +167,7 @@ writeconf(void) if(n >= BOOTARGSLEN) error("kernel configuration too large"); memmove(BOOTARGS, p, n); + memset(BOOTARGS+n, 0, BOOTARGSLEN-n); poperror(); free(p); } |