Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2)

Delta Between Two Patch Sets: src/pkg/runtime/windows/mem.c

Issue 4058046: code review 4058046: windows: multiple improvements and cleanups (Closed)
Left Patch Set: Created 14 years, 1 month ago
Right Patch Set: code review 4058046: windows: multiple improvements and cleanups Created 14 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/runtime/windows/386/sys.s ('k') | src/pkg/runtime/windows/os.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 "os.h" 6 #include "os.h"
7 #include "defs.h" 7 #include "defs.h"
8 #include "malloc.h" 8 #include "malloc.h"
9 9
10 enum { 10 enum {
11 MEM_COMMIT = 0x1000, 11 MEM_COMMIT = 0x1000,
12 MEM_RESERVE = 0x2000, 12 MEM_RESERVE = 0x2000,
13 MEM_RELEASE = 0x8000, 13 MEM_RELEASE = 0x8000,
14 ········ 14 ········
15 PAGE_EXECUTE_READWRITE = 0x40, 15 PAGE_EXECUTE_READWRITE = 0x40,
16 }; 16 };
17
18 static void
19 abort(int8 *name)
20 {
21 uintptr errno;
22
23 errno = runtime·getlasterror();
24 runtime·printf("%s failed with errno=%d\n", name, errno);
25 runtime·throw(name);
26 }
27 17
28 #pragma dynimport runtime·VirtualAlloc VirtualAlloc "kernel32.dll" 18 #pragma dynimport runtime·VirtualAlloc VirtualAlloc "kernel32.dll"
29 #pragma dynimport runtime·VirtualFree VirtualFree "kernel32.dll" 19 #pragma dynimport runtime·VirtualFree VirtualFree "kernel32.dll"
30 extern void *runtime·VirtualAlloc; 20 extern void *runtime·VirtualAlloc;
31 extern void *runtime·VirtualFree; 21 extern void *runtime·VirtualFree;
32 22
33 void* 23 void*
34 runtime·SysAlloc(uintptr n) 24 runtime·SysAlloc(uintptr n)
35 { 25 {
36 mstats.sys += n; 26 mstats.sys += n;
37 return runtime·stdcall(runtime·VirtualAlloc, 4, nil, n, MEM_COMMIT | MEM _RESERVE, PAGE_EXECUTE_READWRITE); 27 return runtime·stdcall(runtime·VirtualAlloc, 4, nil, n, MEM_COMMIT | MEM _RESERVE, PAGE_EXECUTE_READWRITE);
38 } 28 }
39 29
40 void 30 void
41 runtime·SysUnused(void *v, uintptr n) 31 runtime·SysUnused(void *v, uintptr n)
42 { 32 {
43 USED(v); 33 USED(v);
44 USED(n); 34 USED(n);
45 } 35 }
46 36
47 void 37 void
48 runtime·SysFree(void *v, uintptr n) 38 runtime·SysFree(void *v, uintptr n)
49 { 39 {
50 uintptr r; 40 uintptr r;
51 41
52 mstats.sys -= n; 42 mstats.sys -= n;
53 r = (uintptr)runtime·stdcall(runtime·VirtualFree, 3, v, 0, MEM_RELEASE); 43 r = (uintptr)runtime·stdcall(runtime·VirtualFree, 3, v, 0, MEM_RELEASE);
54 if(r == 0) 44 if(r == 0)
55 » » abort("VirtualFree"); 45 » » runtime·throw("runtime: failed to release pages");
56 } 46 }
57 47
58 void* 48 void*
59 runtime·SysReserve(void *v, uintptr n) 49 runtime·SysReserve(void *v, uintptr n)
60 { 50 {
61 return runtime·stdcall(runtime·VirtualAlloc, 4, v, n, MEM_RESERVE, 0); 51 return runtime·stdcall(runtime·VirtualAlloc, 4, v, n, MEM_RESERVE, 0);
62 } 52 }
63 53
64 void 54 void
65 runtime·SysMap(void *v, uintptr n) 55 runtime·SysMap(void *v, uintptr n)
66 { 56 {
67 void *p; 57 void *p;
68 ········ 58 ········
69 mstats.sys += n; 59 mstats.sys += n;
70 p = runtime·stdcall(runtime·VirtualAlloc, 4, v, n, MEM_COMMIT, PAGE_EXEC UTE_READWRITE); 60 p = runtime·stdcall(runtime·VirtualAlloc, 4, v, n, MEM_COMMIT, PAGE_EXEC UTE_READWRITE);
71 if(p != v) 61 if(p != v)
72 runtime·throw("runtime: cannot map pages in arena address space" ); 62 runtime·throw("runtime: cannot map pages in arena address space" );
73 } 63 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b