summaryrefslogtreecommitdiff
path: root/src/pkg/runtime/mem_linux.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/runtime/mem_linux.c')
-rw-r--r--src/pkg/runtime/mem_linux.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/pkg/runtime/mem_linux.c b/src/pkg/runtime/mem_linux.c
index 1bae755fa..b0f295633 100644
--- a/src/pkg/runtime/mem_linux.c
+++ b/src/pkg/runtime/mem_linux.c
@@ -50,11 +50,10 @@ mmap_fixed(byte *v, uintptr n, int32 prot, int32 flags, int32 fd, uint32 offset)
}
void*
-runtime·SysAlloc(uintptr n)
+runtime·SysAlloc(uintptr n, uint64 *stat)
{
void *p;
- mstats.sys += n;
p = runtime·mmap(nil, n, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0);
if(p < (void*)4096) {
if(p == (void*)EACCES) {
@@ -68,6 +67,7 @@ runtime·SysAlloc(uintptr n)
}
return nil;
}
+ runtime·xadd64(stat, n);
return p;
}
@@ -78,9 +78,16 @@ runtime·SysUnused(void *v, uintptr n)
}
void
-runtime·SysFree(void *v, uintptr n)
+runtime·SysUsed(void *v, uintptr n)
{
- mstats.sys -= n;
+ USED(v);
+ USED(n);
+}
+
+void
+runtime·SysFree(void *v, uintptr n, uint64 *stat)
+{
+ runtime·xadd64(stat, -(uint64)n);
runtime·munmap(v, n);
}
@@ -95,24 +102,27 @@ runtime·SysReserve(void *v, uintptr n)
// Only user-mode Linux (UML) rejects these requests.
if(sizeof(void*) == 8 && (uintptr)v >= 0xffffffffU) {
p = mmap_fixed(v, 64<<10, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0);
- if (p != v)
+ if (p != v) {
+ if(p >= (void*)4096)
+ runtime·munmap(p, 64<<10);
return nil;
+ }
runtime·munmap(p, 64<<10);
return v;
}
-
+
p = runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0);
- if((uintptr)p < 4096 || -(uintptr)p < 4096)
+ if((uintptr)p < 4096)
return nil;
return p;
}
void
-runtime·SysMap(void *v, uintptr n)
+runtime·SysMap(void *v, uintptr n, uint64 *stat)
{
void *p;
- mstats.sys += n;
+ runtime·xadd64(stat, n);
// On 64-bit, we don't actually have v reserved, so tread carefully.
if(sizeof(void*) == 8 && (uintptr)v >= 0xffffffffU) {