X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=BlackBox%2F_Linux_%2FLin%2FRsrc%2Fblackbox.c;h=2ebff30021b4ca3d26c2f21e6612d7adda2f1ed0;hb=70a3562c0ad2b415f21357415ca6087e0bd12f92;hp=50dab7321053814bd9b0aada642cf4cec58c964c;hpb=cce27fb37654feaf4afd261687dbd897972d1340;p=bbcp.git diff --git a/BlackBox/_Linux_/Lin/Rsrc/blackbox.c b/BlackBox/_Linux_/Lin/Rsrc/blackbox.c index 50dab73..2ebff30 100644 --- a/BlackBox/_Linux_/Lin/Rsrc/blackbox.c +++ b/BlackBox/_Linux_/Lin/Rsrc/blackbox.c @@ -11,15 +11,14 @@ #include #include #include -#include +#include +#include /* the exact size (in bytes) of the executable part of the file. */ /* this constant needs to be updated everytime a change is made to this file */ -#define exeSize 16860 +#define exeSize 17008 -#define pageSize 4096 - /* fixup types */ #define absolute 100 #define relative 101 @@ -116,6 +115,8 @@ BootInfo* bootInfo; int newRecAdr, newArrAdr; int newRecFP, newArrFP; +int zerofd; + int donothing(char* fmt, ...) { } @@ -355,6 +356,19 @@ int ReadBootHeader() return 1; } +void * MemAlloc (size_t len) +{ + void * res; + + res = mmap(0, len, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANON, zerofd, 0); + if (res == MAP_FAILED) { + res = NULL; + } else { + bzero(res, len); + } + return res; +} + int ReadHeader () { int ofTag, i, nofImps, processor; @@ -385,7 +399,7 @@ int ReadHeader () mod.imp = NULL; for (i = 0; i < nofImps; i++) { - imp = (ImpList*)calloc(1, sizeof(ImpList)); + imp = (ImpList*)MemAlloc(sizeof(ImpList)); ReadName(imp->name); if (mod.imp == NULL) mod.imp = imp; @@ -421,8 +435,8 @@ int ReadModule () int isLib; char* im; - mod.dad = (int) calloc(1, mod.ds); - mod.mad = (int) calloc(1, mod.ms + mod.cs + mod.vs); + mod.dad = (int) MemAlloc(mod.ds); + mod.mad = (int) MemAlloc(mod.ms + mod.cs + mod.vs); if ((mod.dad == 0) || (mod.mad == 0)) { printf("BootLoader: Couldn't initalize heap\n"); @@ -551,18 +565,6 @@ int ReadModule () return 1; } -int MOD (int x, int y) -{ - int res; - - if (x >= 0) { - res = x % y; - } else { - res = x - y * ((x + 1) / y - 1); - } - return res; -} - int main (int argc, char *argv[]) { int i, ok; @@ -570,6 +572,12 @@ int main (int argc, char *argv[]) int callBackAdr; Module *k, *m; + zerofd = open("/dev/zero", O_RDWR); + if (zerofd == -1) { + printf("open /dev/zero failed: %s\n", strerror(errno)); + return 101; + } + modlist = NULL; dprintf("initializing BlackBox for Linux...\n"); /*f = fopen(bbfile, "rb");*/ @@ -604,7 +612,7 @@ int main (int argc, char *argv[]) else { /* assign the boot info to first variable in Kernel */ - bootInfo = calloc(1, sizeof(BootInfo)); + bootInfo = MemAlloc(sizeof(BootInfo)); bootInfo->modList = modlist; bootInfo->argc = argc; bootInfo->argv = argv; @@ -612,14 +620,6 @@ int main (int argc, char *argv[]) dprintf("before body\n"); body = (BodyProc)(m->code); k->opts = k->opts | init; /* include init in opts */ - ok = mprotect( - (void *)(((m->code) / pageSize) * pageSize), - (((m->csize) + MOD(m->code, pageSize) - 1) / pageSize) * pageSize + pageSize, - PROT_READ|PROT_WRITE|PROT_EXEC); - if (ok != 0){ - printf("mprotect failed!\n"); - return 100; - } body(); dprintf("after body\n"); }