1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-12-25 04:38:05 +11:00

cvm: initialize memory with random garbage

This should help spot bugs due to bad initialization.
This commit is contained in:
Virgil Dupras 2020-08-15 14:06:29 -04:00
parent ddb934813e
commit ba8a9c2647
2 changed files with 16 additions and 9 deletions

View File

@ -1,3 +1,4 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "vm.h"
@ -284,8 +285,6 @@ VM* VM_init() {
return NULL;
}
fseek(blkfp, 0, SEEK_SET);
// initialize memory
memset(vm.mem, 0, 0x10000);
FILE *bfp = fopen(FBIN_PATH, "r");
if (!bfp) {
fprintf(stderr, "Can't open forth.bin\n");
@ -298,6 +297,13 @@ VM* VM_init() {
c = getc(bfp);
}
fclose(bfp);
// initialize rest of memory with random data. Many, many bugs we've seen in
// Collapse OS were caused by bad initialization and weren't reproducable
// in CVM because it has a neat zeroed-out memory. Let's make bugs easier
// to spot.
while (i<0x10000) {
vm.mem[i++] = random();
}
vm.SP = SP_ADDR;
vm.RS = RS_ADDR;
vm.minSP = SP_ADDR;

View File

@ -6,23 +6,24 @@ RS_ADDR 0x80 - CONSTANT SYSVARS
VARIABLE ORG
CREATE BIN( 0 ,
: PC H@ ORG @ - ;
155 LOAD ( ALLOT0 )
262 LOAD ( xcomp )
270 LOAD ( xcomp overrides )
H@ ORG !
ORG @ 0x0b + HERE !
0x0b ALLOT0
0 C, 0 C, ( EXIT )
ORG @ 0x23 + HERE !
0x16 ALLOT0
0 C, 0x05 C, ( (n) )
ORG @ 0x2b + HERE !
0x6 ALLOT0
0 C, 0x06 C, ( (s) )
ORG @ 0x33 + HERE !
0x6 ALLOT0
0 C, 0x04 C, ( 2>R )
ORG @ 0x3b + HERE !
0x6 ALLOT0
0 C, 0x01 C, ( (br) )
ORG @ 0x3f + HERE !
0x2 ALLOT0
0 C, 0x02 C, ( (?br) )
ORG @ 0x43 + HERE !
0x2 ALLOT0
0 C, 0x03 C, ( (loop) )
( END OF STABLE ABI )
H@ 4 + XCURRENT ! ( make next CODE have 0 prev field )