LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 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 "type.h" | 6 #include "type.h" |
7 #include "defs_GOOS_GOARCH.h" | 7 #include "defs_GOOS_GOARCH.h" |
8 #include "os_GOOS.h" | 8 #include "os_GOOS.h" |
9 | 9 |
10 #pragma dynimport runtime·CloseHandle CloseHandle "kernel32.dll" | 10 #pragma dynimport runtime·CloseHandle CloseHandle "kernel32.dll" |
11 #pragma dynimport runtime·CreateEvent CreateEventA "kernel32.dll" | 11 #pragma dynimport runtime·CreateEvent CreateEventA "kernel32.dll" |
12 #pragma dynimport runtime·CreateThread CreateThread "kernel32.dll" | 12 #pragma dynimport runtime·CreateThread CreateThread "kernel32.dll" |
13 #pragma dynimport runtime·CreateWaitableTimer CreateWaitableTimerA "kernel32.dll
" | 13 #pragma dynimport runtime·CreateWaitableTimer CreateWaitableTimerA "kernel32.dll
" |
| 14 #pragma dynimport runtime·CryptAcquireContextW CryptAcquireContextW "advapi32.dl
l" |
| 15 #pragma dynimport runtime·CryptGenRandom CryptGenRandom "advapi32.dll" |
| 16 #pragma dynimport runtime·CryptReleaseContext CryptReleaseContext "advapi32.dll" |
14 #pragma dynimport runtime·DuplicateHandle DuplicateHandle "kernel32.dll" | 17 #pragma dynimport runtime·DuplicateHandle DuplicateHandle "kernel32.dll" |
15 #pragma dynimport runtime·ExitProcess ExitProcess "kernel32.dll" | 18 #pragma dynimport runtime·ExitProcess ExitProcess "kernel32.dll" |
16 #pragma dynimport runtime·FreeEnvironmentStringsW FreeEnvironmentStringsW "kerne
l32.dll" | 19 #pragma dynimport runtime·FreeEnvironmentStringsW FreeEnvironmentStringsW "kerne
l32.dll" |
17 #pragma dynimport runtime·GetEnvironmentStringsW GetEnvironmentStringsW "kernel3
2.dll" | 20 #pragma dynimport runtime·GetEnvironmentStringsW GetEnvironmentStringsW "kernel3
2.dll" |
18 #pragma dynimport runtime·GetProcAddress GetProcAddress "kernel32.dll" | 21 #pragma dynimport runtime·GetProcAddress GetProcAddress "kernel32.dll" |
19 #pragma dynimport runtime·GetStdHandle GetStdHandle "kernel32.dll" | 22 #pragma dynimport runtime·GetStdHandle GetStdHandle "kernel32.dll" |
20 #pragma dynimport runtime·GetSystemInfo GetSystemInfo "kernel32.dll" | 23 #pragma dynimport runtime·GetSystemInfo GetSystemInfo "kernel32.dll" |
21 #pragma dynimport runtime·GetSystemTimeAsFileTime GetSystemTimeAsFileTime "kerne
l32.dll" | 24 #pragma dynimport runtime·GetSystemTimeAsFileTime GetSystemTimeAsFileTime "kerne
l32.dll" |
22 #pragma dynimport runtime·GetThreadContext GetThreadContext "kernel32.dll" | 25 #pragma dynimport runtime·GetThreadContext GetThreadContext "kernel32.dll" |
23 #pragma dynimport runtime·LoadLibrary LoadLibraryW "kernel32.dll" | 26 #pragma dynimport runtime·LoadLibrary LoadLibraryW "kernel32.dll" |
24 #pragma dynimport runtime·ResumeThread ResumeThread "kernel32.dll" | 27 #pragma dynimport runtime·ResumeThread ResumeThread "kernel32.dll" |
25 #pragma dynimport runtime·SetConsoleCtrlHandler SetConsoleCtrlHandler "kernel32.
dll" | 28 #pragma dynimport runtime·SetConsoleCtrlHandler SetConsoleCtrlHandler "kernel32.
dll" |
26 #pragma dynimport runtime·SetEvent SetEvent "kernel32.dll" | 29 #pragma dynimport runtime·SetEvent SetEvent "kernel32.dll" |
27 #pragma dynimport runtime·SetThreadPriority SetThreadPriority "kernel32.dll" | 30 #pragma dynimport runtime·SetThreadPriority SetThreadPriority "kernel32.dll" |
28 #pragma dynimport runtime·SetWaitableTimer SetWaitableTimer "kernel32.dll" | 31 #pragma dynimport runtime·SetWaitableTimer SetWaitableTimer "kernel32.dll" |
29 #pragma dynimport runtime·Sleep Sleep "kernel32.dll" | 32 #pragma dynimport runtime·Sleep Sleep "kernel32.dll" |
30 #pragma dynimport runtime·SuspendThread SuspendThread "kernel32.dll" | 33 #pragma dynimport runtime·SuspendThread SuspendThread "kernel32.dll" |
31 #pragma dynimport runtime·timeBeginPeriod timeBeginPeriod "winmm.dll" | 34 #pragma dynimport runtime·timeBeginPeriod timeBeginPeriod "winmm.dll" |
32 #pragma dynimport runtime·WaitForSingleObject WaitForSingleObject "kernel32.dll" | 35 #pragma dynimport runtime·WaitForSingleObject WaitForSingleObject "kernel32.dll" |
33 #pragma dynimport runtime·WriteFile WriteFile "kernel32.dll" | 36 #pragma dynimport runtime·WriteFile WriteFile "kernel32.dll" |
34 #pragma dynimport runtime·CryptAcquireContextW CryptAcquireContextW "advapi32.dl
l" | 37 #pragma dynimport runtime·NtWaitForSingleObject NtWaitForSingleObject "ntdll.dll
" |
35 #pragma dynimport runtime·CryptGenRandom CryptGenRandom "advapi32.dll" | 38 |
36 #pragma dynimport runtime·CryptReleaseContext CryptReleaseContext "advapi32.dll" | 39 extern void *runtime·NtWaitForSingleObject; |
37 | 40 |
38 extern void *runtime·CloseHandle; | 41 extern void *runtime·CloseHandle; |
39 extern void *runtime·CreateEvent; | 42 extern void *runtime·CreateEvent; |
40 extern void *runtime·CreateThread; | 43 extern void *runtime·CreateThread; |
41 extern void *runtime·CreateWaitableTimer; | 44 extern void *runtime·CreateWaitableTimer; |
| 45 extern void *runtime·CryptAcquireContextW; |
| 46 extern void *runtime·CryptGenRandom; |
| 47 extern void *runtime·CryptReleaseContext; |
42 extern void *runtime·DuplicateHandle; | 48 extern void *runtime·DuplicateHandle; |
43 extern void *runtime·ExitProcess; | 49 extern void *runtime·ExitProcess; |
44 extern void *runtime·FreeEnvironmentStringsW; | 50 extern void *runtime·FreeEnvironmentStringsW; |
45 extern void *runtime·GetEnvironmentStringsW; | 51 extern void *runtime·GetEnvironmentStringsW; |
46 extern void *runtime·GetProcAddress; | 52 extern void *runtime·GetProcAddress; |
47 extern void *runtime·GetStdHandle; | 53 extern void *runtime·GetStdHandle; |
48 extern void *runtime·GetSystemInfo; | 54 extern void *runtime·GetSystemInfo; |
49 extern void *runtime·GetSystemTimeAsFileTime; | 55 extern void *runtime·GetSystemTimeAsFileTime; |
50 extern void *runtime·GetThreadContext; | 56 extern void *runtime·GetThreadContext; |
51 extern void *runtime·LoadLibrary; | 57 extern void *runtime·LoadLibrary; |
52 extern void *runtime·ResumeThread; | 58 extern void *runtime·ResumeThread; |
53 extern void *runtime·SetConsoleCtrlHandler; | 59 extern void *runtime·SetConsoleCtrlHandler; |
54 extern void *runtime·SetEvent; | 60 extern void *runtime·SetEvent; |
55 extern void *runtime·SetThreadPriority; | 61 extern void *runtime·SetThreadPriority; |
56 extern void *runtime·SetWaitableTimer; | 62 extern void *runtime·SetWaitableTimer; |
57 extern void *runtime·Sleep; | 63 extern void *runtime·Sleep; |
58 extern void *runtime·SuspendThread; | 64 extern void *runtime·SuspendThread; |
59 extern void *runtime·timeBeginPeriod; | 65 extern void *runtime·timeBeginPeriod; |
60 extern void *runtime·WaitForSingleObject; | 66 extern void *runtime·WaitForSingleObject; |
61 extern void *runtime·WriteFile; | 67 extern void *runtime·WriteFile; |
62 extern void *runtime·CryptAcquireContextW; | |
63 extern void *runtime·CryptGenRandom; | |
64 extern void *runtime·CryptReleaseContext; | |
65 | 68 |
66 static int32 | 69 static int32 |
67 getproccount(void) | 70 getproccount(void) |
68 { | 71 { |
69 SystemInfo info; | 72 SystemInfo info; |
70 | 73 |
71 runtime·stdcall(runtime·GetSystemInfo, 1, &info); | 74 runtime·stdcall(runtime·GetSystemInfo, 1, &info); |
72 return info.dwNumberOfProcessors; | 75 return info.dwNumberOfProcessors; |
73 } | 76 } |
74 | 77 |
75 void | 78 void |
76 runtime·osinit(void) | 79 runtime·osinit(void) |
77 { | 80 { |
78 uint8 randomdata[HashRandomBytes]; | |
79 uintptr handle; | |
80 | |
81 // -1 = current process, -2 = current thread | 81 // -1 = current process, -2 = current thread |
82 runtime·stdcall(runtime·DuplicateHandle, 7, | 82 runtime·stdcall(runtime·DuplicateHandle, 7, |
83 (uintptr)-1, (uintptr)-2, (uintptr)-1, &m->thread, | 83 (uintptr)-1, (uintptr)-2, (uintptr)-1, &m->thread, |
84 (uintptr)0, (uintptr)0, (uintptr)DUPLICATE_SAME_ACCESS); | 84 (uintptr)0, (uintptr)0, (uintptr)DUPLICATE_SAME_ACCESS); |
85 runtime·stdcall(runtime·SetConsoleCtrlHandler, 2, runtime·ctrlhandler, (
uintptr)1); | 85 runtime·stdcall(runtime·SetConsoleCtrlHandler, 2, runtime·ctrlhandler, (
uintptr)1); |
86 runtime·stdcall(runtime·timeBeginPeriod, 1, (uintptr)1); | 86 runtime·stdcall(runtime·timeBeginPeriod, 1, (uintptr)1); |
87 runtime·ncpu = getproccount(); | 87 runtime·ncpu = getproccount(); |
88 | 88 } |
89 » runtime·memclr(randomdata, HashRandomBytes); | 89 |
90 » if (runtime·stdcall(runtime·CryptAcquireContextW, 5, &handle, nil, nil, | 90 void |
91 » » » (uintptr)1 /* PROV_RSA_FULL */, | 91 runtime·get_random_data(byte **rnd, int32 *rnd_len) |
92 » » » (uintptr)0xf0000000U /* CRYPT_VERIFYCONTEXT */) != 0
) { | 92 { |
93 » » runtime·stdcall(runtime·CryptGenRandom, 3, handle, (uintptr)Hash
RandomBytes, randomdata); | 93 » uintptr handle; |
| 94 » *rnd = nil; |
| 95 » *rnd_len = 0; |
| 96 » if(runtime·stdcall(runtime·CryptAcquireContextW, 5, &handle, nil, nil, |
| 97 » » » (uintptr)1 /* PROV_RSA_FULL */, |
| 98 » » » (uintptr)0xf0000000U /* CRYPT_VERIFYCONTEXT */) != 0)
{ |
| 99 » » static byte random_data[HashRandomBytes]; |
| 100 » » if(runtime·stdcall(runtime·CryptGenRandom, 3, handle, (uintptr)H
ashRandomBytes, random_data)) { |
| 101 » » » *rnd = random_data; |
| 102 » » » *rnd_len = HashRandomBytes; |
| 103 » » } |
94 runtime·stdcall(runtime·CryptReleaseContext, 2, handle, (uintptr
)0); | 104 runtime·stdcall(runtime·CryptReleaseContext, 2, handle, (uintptr
)0); |
95 } | 105 } |
96 runtime·hashinit(randomdata); | |
97 } | 106 } |
98 | 107 |
99 void | 108 void |
100 runtime·goenvs(void) | 109 runtime·goenvs(void) |
101 { | 110 { |
102 extern Slice syscall·envs; | 111 extern Slice syscall·envs; |
103 | 112 |
104 uint16 *env; | 113 uint16 *env; |
105 String *s; | 114 String *s; |
106 int32 i, n; | 115 int32 i, n; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 handle = runtime·stdcall(runtime·GetStdHandle, 1, (uintptr)-11); | 153 handle = runtime·stdcall(runtime·GetStdHandle, 1, (uintptr)-11); |
145 break; | 154 break; |
146 case 2: | 155 case 2: |
147 handle = runtime·stdcall(runtime·GetStdHandle, 1, (uintptr)-12); | 156 handle = runtime·stdcall(runtime·GetStdHandle, 1, (uintptr)-12); |
148 break; | 157 break; |
149 default: | 158 default: |
150 return -1; | 159 return -1; |
151 } | 160 } |
152 runtime·stdcall(runtime·WriteFile, 5, handle, buf, (uintptr)n, &written,
(uintptr)0); | 161 runtime·stdcall(runtime·WriteFile, 5, handle, buf, (uintptr)n, &written,
(uintptr)0); |
153 return written; | 162 return written; |
154 } | |
155 | |
156 #pragma textflag 7 | |
157 void | |
158 runtime·osyield(void) | |
159 { | |
160 runtime·stdcall(runtime·Sleep, 1, (uintptr)0); | |
161 } | |
162 | |
163 void | |
164 runtime·usleep(uint32 us) | |
165 { | |
166 us /= 1000; | |
167 if(us == 0) | |
168 us = 1; | |
169 runtime·stdcall(runtime·Sleep, 1, (uintptr)us); | |
170 } | 163 } |
171 | 164 |
172 #define INFINITE ((uintptr)0xFFFFFFFF) | 165 #define INFINITE ((uintptr)0xFFFFFFFF) |
173 | 166 |
174 int32 | 167 int32 |
175 runtime·semasleep(int64 ns) | 168 runtime·semasleep(int64 ns) |
176 { | 169 { |
177 uintptr ms; | 170 uintptr ms; |
178 | 171 |
179 if(ns < 0) | 172 if(ns < 0) |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 runtime·setprof(bool on) | 448 runtime·setprof(bool on) |
456 { | 449 { |
457 USED(on); | 450 USED(on); |
458 } | 451 } |
459 | 452 |
460 int8 runtime·badcallbackmsg[] = "runtime: cgo callback on thread not created by
Go.\n"; | 453 int8 runtime·badcallbackmsg[] = "runtime: cgo callback on thread not created by
Go.\n"; |
461 int32 runtime·badcallbacklen = sizeof runtime·badcallbackmsg - 1; | 454 int32 runtime·badcallbacklen = sizeof runtime·badcallbackmsg - 1; |
462 | 455 |
463 int8 runtime·badsignalmsg[] = "runtime: signal received on thread not created by
Go.\n"; | 456 int8 runtime·badsignalmsg[] = "runtime: signal received on thread not created by
Go.\n"; |
464 int32 runtime·badsignallen = sizeof runtime·badsignalmsg - 1; | 457 int32 runtime·badsignallen = sizeof runtime·badsignalmsg - 1; |
LEFT | RIGHT |