LEFT | RIGHT |
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 "malloc.h" | 6 #include "malloc.h" |
7 | 7 |
8 extern int8 end[]; | 8 extern byte end[]; |
9 static int8 *bloc = { end }; | 9 static byte *bloc = { end }; |
10 | 10 |
11 enum | 11 enum |
12 { | 12 { |
13 Round = 7 | 13 Round = 7 |
14 }; | 14 }; |
15 | 15 |
16 void* | 16 void* |
17 SysAlloc(uintptr ask) | 17 SysAlloc(uintptr ask) |
18 { | 18 { |
19 uintptr bl; | 19 » uintptr bl; |
20 | 20 » |
21 // Plan 9 sbrk from /sys/src/libc/9sys/sbrk.c | 21 » // Plan 9 sbrk from /sys/src/libc/9sys/sbrk.c |
22 bl = ((uintptr)bloc + Round) & ~Round; | 22 » bl = ((uintptr)bloc + Round) & ~Round; |
23 if(brk_((void*)(bl + ask)) < 0) | 23 » if(brk_((void*)(bl + ask)) < 0) |
24 return (void*)-1; | 24 » » return (void*)-1; |
25 bloc = (int8*)bl + ask; | 25 » bloc = (byte*)bl + ask; |
26 return (void*)bl; | 26 » return (void*)bl; |
27 } | 27 } |
28 | 28 |
29 void | 29 void |
30 SysFree(void *v, uintptr n) | 30 SysFree(void *v, uintptr n) |
31 { | 31 { |
32 // from tiny/mem.c | 32 // from tiny/mem.c |
33 // Push pointer back if this is a free | 33 // Push pointer back if this is a free |
34 // of the most recent SysAlloc. | 34 // of the most recent SysAlloc. |
35 n += (n + Round) & ~Round; | 35 n += (n + Round) & ~Round; |
36 » if(bloc == (int8*)v+n) | 36 » if(bloc == (byte*)v+n) |
37 bloc -= n;······ | 37 bloc -= n;······ |
38 } | 38 } |
39 | 39 |
40 void | 40 void |
41 SysUnused(void *v, uintptr n) | 41 SysUnused(void *v, uintptr n) |
42 { | 42 { |
43 USED(v, n); | 43 USED(v, n); |
44 } | 44 } |
45 | 45 |
| 46 void |
| 47 SysMemInit(void) |
| 48 { |
| 49 } |
LEFT | RIGHT |