github.com/varialus/godfly@v0.0.0-20130904042352-1934f9f095ab/src/pkg/runtime/mem_darwin.c (about) 1 // Copyright 2010 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 #include "runtime.h" 6 #include "arch_GOARCH.h" 7 #include "defs_GOOS_GOARCH.h" 8 #include "os_GOOS.h" 9 #include "malloc.h" 10 11 void* 12 runtime·SysAlloc(uintptr n) 13 { 14 void *v; 15 16 mstats.sys += n; 17 v = runtime·mmap(nil, n, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0); 18 if(v < (void*)4096) 19 return nil; 20 return v; 21 } 22 23 void 24 runtime·SysUnused(void *v, uintptr n) 25 { 26 // Linux's MADV_DONTNEED is like BSD's MADV_FREE. 27 runtime·madvise(v, n, MADV_FREE); 28 } 29 30 void 31 runtime·SysUsed(void *v, uintptr n) 32 { 33 USED(v); 34 USED(n); 35 } 36 37 void 38 runtime·SysFree(void *v, uintptr n) 39 { 40 mstats.sys -= n; 41 runtime·munmap(v, n); 42 } 43 44 void* 45 runtime·SysReserve(void *v, uintptr n) 46 { 47 void *p; 48 49 p = runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0); 50 if(p < (void*)4096) 51 return nil; 52 return p; 53 } 54 55 enum 56 { 57 ENOMEM = 12, 58 }; 59 60 void 61 runtime·SysMap(void *v, uintptr n) 62 { 63 void *p; 64 65 mstats.sys += n; 66 p = runtime·mmap(v, n, PROT_READ|PROT_WRITE, MAP_ANON|MAP_FIXED|MAP_PRIVATE, -1, 0); 67 if(p == (void*)ENOMEM) 68 runtime·throw("runtime: out of memory"); 69 if(p != v) 70 runtime·throw("runtime: cannot map pages in arena address space"); 71 }