LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2010 The Go Authors. All rights reserved. | 1 // Copyright 2010 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 #include "runtime.h" | 5 #include "runtime.h" |
6 #include "arch_GOARCH.h" | 6 #include "arch_GOARCH.h" |
7 #include "defs_GOOS_GOARCH.h" | 7 #include "defs_GOOS_GOARCH.h" |
8 #include "os_GOOS.h" | 8 #include "os_GOOS.h" |
9 #include "malloc.h" | 9 #include "malloc.h" |
10 | 10 |
11 enum | 11 enum |
12 { | 12 { |
13 ENOMEM = 12, | 13 ENOMEM = 12, |
14 }; | 14 }; |
15 | 15 |
16 void* | 16 void* |
17 runtime·SysAlloc(uintptr n) | 17 runtime·SysAlloc(uintptr n) |
18 { | 18 { |
19 void *v; | 19 void *v; |
20 | 20 |
21 mstats.sys += n; | 21 mstats.sys += n; |
22 » v = runtime·mmap(nil, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PR
IVATE, -1, 0); | 22 » v = runtime·mmap(nil, n, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1,
0); |
23 if(v < (void*)4096) | 23 if(v < (void*)4096) |
24 return nil; | 24 return nil; |
25 return v; | 25 return v; |
26 } | 26 } |
27 | 27 |
28 void | 28 void |
29 runtime·SysUnused(void *v, uintptr n) | 29 runtime·SysUnused(void *v, uintptr n) |
30 { | 30 { |
31 runtime·madvise(v, n, MADV_FREE); | 31 runtime·madvise(v, n, MADV_FREE); |
32 } | 32 } |
(...skipping 25 matching lines...) Expand all Loading... |
58 | 58 |
59 void | 59 void |
60 runtime·SysMap(void *v, uintptr n) | 60 runtime·SysMap(void *v, uintptr n) |
61 { | 61 { |
62 void *p; | 62 void *p; |
63 ········ | 63 ········ |
64 mstats.sys += n; | 64 mstats.sys += n; |
65 | 65 |
66 // On 64-bit, we don't actually have v reserved, so tread carefully. | 66 // On 64-bit, we don't actually have v reserved, so tread carefully. |
67 if(sizeof(void*) == 8) { | 67 if(sizeof(void*) == 8) { |
68 » » p = runtime·mmap(v, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|
MAP_PRIVATE, -1, 0); | 68 » » p = runtime·mmap(v, n, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVAT
E, -1, 0); |
69 if(p == (void*)-ENOMEM) | 69 if(p == (void*)-ENOMEM) |
70 runtime·throw("runtime: out of memory"); | 70 runtime·throw("runtime: out of memory"); |
71 if(p != v) { | 71 if(p != v) { |
72 runtime·printf("runtime: address space conflict: map(%p)
= %p\n", v, p); | 72 runtime·printf("runtime: address space conflict: map(%p)
= %p\n", v, p); |
73 runtime·throw("runtime: address space conflict"); | 73 runtime·throw("runtime: address space conflict"); |
74 } | 74 } |
75 return; | 75 return; |
76 } | 76 } |
77 | 77 |
78 » p = runtime·mmap(v, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_FIXE
D|MAP_PRIVATE, -1, 0); | 78 » p = runtime·mmap(v, n, PROT_READ|PROT_WRITE, MAP_ANON|MAP_FIXED|MAP_PRIV
ATE, -1, 0); |
79 if(p == (void*)-ENOMEM) | 79 if(p == (void*)-ENOMEM) |
80 runtime·throw("runtime: out of memory"); | 80 runtime·throw("runtime: out of memory"); |
81 if(p != v) | 81 if(p != v) |
82 runtime·throw("runtime: cannot map pages in arena address space"
); | 82 runtime·throw("runtime: cannot map pages in arena address space"
); |
83 } | 83 } |
LEFT | RIGHT |