github.com/spotify/syslog-redirector-golang@v0.0.0-20140320174030-4859f03d829a/src/pkg/runtime/mem_netbsd.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 enum 12 { 13 ENOMEM = 12, 14 }; 15 16 void* 17 runtime·SysAlloc(uintptr n, uint64 *stat) 18 { 19 void *v; 20 21 v = runtime·mmap(nil, n, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0); 22 if(v < (void*)4096) 23 return nil; 24 runtime·xadd64(stat, n); 25 return v; 26 } 27 28 void 29 runtime·SysUnused(void *v, uintptr n) 30 { 31 runtime·madvise(v, n, MADV_FREE); 32 } 33 34 void 35 runtime·SysUsed(void *v, uintptr n) 36 { 37 USED(v); 38 USED(n); 39 } 40 41 void 42 runtime·SysFree(void *v, uintptr n, uint64 *stat) 43 { 44 runtime·xadd64(stat, -(uint64)n); 45 runtime·munmap(v, n); 46 } 47 48 void* 49 runtime·SysReserve(void *v, uintptr n) 50 { 51 void *p; 52 53 // On 64-bit, people with ulimit -v set complain if we reserve too 54 // much address space. Instead, assume that the reservation is okay 55 // and check the assumption in SysMap. 56 if(sizeof(void*) == 8) 57 return v; 58 59 p = runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0); 60 if(p < (void*)4096) 61 return nil; 62 return p; 63 } 64 65 void 66 runtime·SysMap(void *v, uintptr n, uint64 *stat) 67 { 68 void *p; 69 70 runtime·xadd64(stat, n); 71 72 // On 64-bit, we don't actually have v reserved, so tread carefully. 73 if(sizeof(void*) == 8) { 74 p = runtime·mmap(v, n, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0); 75 if(p == (void*)ENOMEM) 76 runtime·throw("runtime: out of memory"); 77 if(p != v) { 78 runtime·printf("runtime: address space conflict: map(%p) = %p\n", v, p); 79 runtime·throw("runtime: address space conflict"); 80 } 81 return; 82 } 83 84 p = runtime·mmap(v, n, PROT_READ|PROT_WRITE, MAP_ANON|MAP_FIXED|MAP_PRIVATE, -1, 0); 85 if(p == (void*)ENOMEM) 86 runtime·throw("runtime: out of memory"); 87 if(p != v) 88 runtime·throw("runtime: cannot map pages in arena address space"); 89 }