diff options
Diffstat (limited to 'src/pkg/runtime/mem.c')
-rw-r--r-- | src/pkg/runtime/mem.c | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/src/pkg/runtime/mem.c b/src/pkg/runtime/mem.c index 3cb59700f..f2796b729 100644 --- a/src/pkg/runtime/mem.c +++ b/src/pkg/runtime/mem.c @@ -13,67 +13,6 @@ enum NHUNK = 20<<20, }; -// Convenient wrapper around mmap. -static void* -brk(uint32 n) -{ - byte *v; - - v = runtime_mmap(nil, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, 0, 0); - if(v < (void *)4096) { - printf("mmap: errno=%p\n", v); - exit(2); - } - m->mem.nmmap += n; - return v; -} - -// Allocate n bytes of memory. Note that this gets used -// to allocate new stack segments, so at each call to a function -// you have to ask yourself "would it be okay to call mal recursively -// right here?" The answer is yes unless we're in the middle of -// editing the malloc state in m->mem. -void* -oldmal(uint32 n) -{ - byte* v; - - // round to keep everything 64-bit aligned - n = rnd(n, 8); - - // be careful. calling any function might invoke - // mal to allocate more stack. - if(n > NHUNK) { - v = brk(n); - } else { - // allocate a new hunk if this one is too small - if(n > m->mem.nhunk) { - // here we're in the middle of editing m->mem - // (we're about to overwrite m->mem.hunk), - // so we can't call brk - it might call mal to grow the - // stack, and the recursive call would allocate a new - // hunk, and then once brk returned we'd immediately - // overwrite that hunk with our own. - // (the net result would be a memory leak, not a crash.) - // so we have to call runtime_mmap directly - it is written - // in assembly and tagged not to grow the stack. - m->mem.hunk = - runtime_mmap(nil, NHUNK, PROT_READ|PROT_WRITE|PROT_EXEC, - MAP_ANON|MAP_PRIVATE, 0, 0); - if(m->mem.hunk < (void*)4096) { - *(uint32*)0xf1 = 0; - } - m->mem.nhunk = NHUNK; - m->mem.nmmap += NHUNK; - } - v = m->mem.hunk; - m->mem.hunk += n; - m->mem.nhunk -= n; - } - m->mem.nmal += n; - return v; -} - void runtimeĀ·mal(uint32 n, uint8 *ret) { |