diff options
Diffstat (limited to 'src/pkg/runtime/tiny/mem.c')
-rw-r--r-- | src/pkg/runtime/tiny/mem.c | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/src/pkg/runtime/tiny/mem.c b/src/pkg/runtime/tiny/mem.c index a66a4a731..7abecfba0 100644 --- a/src/pkg/runtime/tiny/mem.c +++ b/src/pkg/runtime/tiny/mem.c @@ -8,34 +8,43 @@ // Assume there's an arbitrary amount of memory starting at "end". // Sizing PC memory is beyond the scope of this demo. +static byte *allocp; + void* -SysAlloc(uintptr ask) +runtime·SysAlloc(uintptr ask) { - static byte *p; extern byte end[]; byte *q; - if(p == nil) { - p = end; - p += 7 & -(uintptr)p; + if(allocp == nil) { + allocp = end; + allocp += 7 & -(uintptr)allocp; } ask += 7 & -ask; - q = p; - p += ask; - ·memclr(q, ask); + q = allocp; + allocp += ask; + runtime·memclr(q, ask); return q; } void -SysFree(void *v, uintptr n) +runtime·SysFree(void *v, uintptr n) { - USED(v, n); + // Push pointer back if this is a free + // of the most recent SysAlloc. + n += 7 & -n; + if(allocp == (byte*)v+n) + allocp -= n; } void -SysUnused(void *v, uintptr n) +runtime·SysUnused(void *v, uintptr n) { USED(v, n); } +void +runtime·SysMemInit(void) +{ +} |