LEFT | RIGHT |
(no file at all) | |
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 #include "../../cmd/ld/textflag.h" | 9 #include "../../cmd/ld/textflag.h" |
10 | 10 |
| 11 #pragma dynimport runtime·AddVectoredExceptionHandler AddVectoredExceptionHandle
r "kernel32.dll" |
11 #pragma dynimport runtime·CloseHandle CloseHandle "kernel32.dll" | 12 #pragma dynimport runtime·CloseHandle CloseHandle "kernel32.dll" |
12 #pragma dynimport runtime·CreateEvent CreateEventA "kernel32.dll" | 13 #pragma dynimport runtime·CreateEvent CreateEventA "kernel32.dll" |
13 #pragma dynimport runtime·CreateThread CreateThread "kernel32.dll" | 14 #pragma dynimport runtime·CreateThread CreateThread "kernel32.dll" |
14 #pragma dynimport runtime·CreateWaitableTimer CreateWaitableTimerA "kernel32.dll
" | 15 #pragma dynimport runtime·CreateWaitableTimer CreateWaitableTimerA "kernel32.dll
" |
15 #pragma dynimport runtime·CryptAcquireContextW CryptAcquireContextW "advapi32.dl
l" | 16 #pragma dynimport runtime·CryptAcquireContextW CryptAcquireContextW "advapi32.dl
l" |
16 #pragma dynimport runtime·CryptGenRandom CryptGenRandom "advapi32.dll" | 17 #pragma dynimport runtime·CryptGenRandom CryptGenRandom "advapi32.dll" |
17 #pragma dynimport runtime·CryptReleaseContext CryptReleaseContext "advapi32.dll" | 18 #pragma dynimport runtime·CryptReleaseContext CryptReleaseContext "advapi32.dll" |
18 #pragma dynimport runtime·DuplicateHandle DuplicateHandle "kernel32.dll" | 19 #pragma dynimport runtime·DuplicateHandle DuplicateHandle "kernel32.dll" |
19 #pragma dynimport runtime·ExitProcess ExitProcess "kernel32.dll" | 20 #pragma dynimport runtime·ExitProcess ExitProcess "kernel32.dll" |
20 #pragma dynimport runtime·FreeEnvironmentStringsW FreeEnvironmentStringsW "kerne
l32.dll" | 21 #pragma dynimport runtime·FreeEnvironmentStringsW FreeEnvironmentStringsW "kerne
l32.dll" |
21 #pragma dynimport runtime·GetEnvironmentStringsW GetEnvironmentStringsW "kernel3
2.dll" | 22 #pragma dynimport runtime·GetEnvironmentStringsW GetEnvironmentStringsW "kernel3
2.dll" |
22 #pragma dynimport runtime·GetProcAddress GetProcAddress "kernel32.dll" | 23 #pragma dynimport runtime·GetProcAddress GetProcAddress "kernel32.dll" |
| 24 #pragma dynimport runtime·GetQueuedCompletionStatusEx GetQueuedCompletionStatusE
x "kernel32.dll" |
23 #pragma dynimport runtime·GetStdHandle GetStdHandle "kernel32.dll" | 25 #pragma dynimport runtime·GetStdHandle GetStdHandle "kernel32.dll" |
24 #pragma dynimport runtime·GetSystemInfo GetSystemInfo "kernel32.dll" | 26 #pragma dynimport runtime·GetSystemInfo GetSystemInfo "kernel32.dll" |
25 #pragma dynimport runtime·GetSystemTimeAsFileTime GetSystemTimeAsFileTime "kerne
l32.dll" | 27 #pragma dynimport runtime·GetSystemTimeAsFileTime GetSystemTimeAsFileTime "kerne
l32.dll" |
26 #pragma dynimport runtime·GetThreadContext GetThreadContext "kernel32.dll" | 28 #pragma dynimport runtime·GetThreadContext GetThreadContext "kernel32.dll" |
27 #pragma dynimport runtime·LoadLibrary LoadLibraryW "kernel32.dll" | 29 #pragma dynimport runtime·LoadLibrary LoadLibraryW "kernel32.dll" |
28 #pragma dynimport runtime·LoadLibraryA LoadLibraryA "kernel32.dll" | 30 #pragma dynimport runtime·LoadLibraryA LoadLibraryA "kernel32.dll" |
| 31 #pragma dynimport runtime·NtWaitForSingleObject NtWaitForSingleObject "ntdll.dll
" |
29 #pragma dynimport runtime·ResumeThread ResumeThread "kernel32.dll" | 32 #pragma dynimport runtime·ResumeThread ResumeThread "kernel32.dll" |
30 #pragma dynimport runtime·SetConsoleCtrlHandler SetConsoleCtrlHandler "kernel32.
dll" | 33 #pragma dynimport runtime·SetConsoleCtrlHandler SetConsoleCtrlHandler "kernel32.
dll" |
31 #pragma dynimport runtime·SetEvent SetEvent "kernel32.dll" | 34 #pragma dynimport runtime·SetEvent SetEvent "kernel32.dll" |
| 35 #pragma dynimport runtime·SetProcessPriorityBoost SetProcessPriorityBoost "kerne
l32.dll" |
32 #pragma dynimport runtime·SetThreadPriority SetThreadPriority "kernel32.dll" | 36 #pragma dynimport runtime·SetThreadPriority SetThreadPriority "kernel32.dll" |
33 #pragma dynimport runtime·SetWaitableTimer SetWaitableTimer "kernel32.dll" | 37 #pragma dynimport runtime·SetWaitableTimer SetWaitableTimer "kernel32.dll" |
34 #pragma dynimport runtime·Sleep Sleep "kernel32.dll" | 38 #pragma dynimport runtime·Sleep Sleep "kernel32.dll" |
35 #pragma dynimport runtime·SuspendThread SuspendThread "kernel32.dll" | 39 #pragma dynimport runtime·SuspendThread SuspendThread "kernel32.dll" |
36 #pragma dynimport runtime·timeBeginPeriod timeBeginPeriod "winmm.dll" | |
37 #pragma dynimport runtime·WaitForSingleObject WaitForSingleObject "kernel32.dll" | 40 #pragma dynimport runtime·WaitForSingleObject WaitForSingleObject "kernel32.dll" |
38 #pragma dynimport runtime·WriteFile WriteFile "kernel32.dll" | 41 #pragma dynimport runtime·WriteFile WriteFile "kernel32.dll" |
39 #pragma dynimport runtime·NtWaitForSingleObject NtWaitForSingleObject "ntdll.dll
" | 42 #pragma dynimport runtime·timeBeginPeriod timeBeginPeriod "winmm.dll" |
40 | 43 |
41 extern void *runtime·NtWaitForSingleObject; | 44 extern void *runtime·AddVectoredExceptionHandler; |
42 | |
43 extern void *runtime·CloseHandle; | 45 extern void *runtime·CloseHandle; |
44 extern void *runtime·CreateEvent; | 46 extern void *runtime·CreateEvent; |
45 extern void *runtime·CreateThread; | 47 extern void *runtime·CreateThread; |
46 extern void *runtime·CreateWaitableTimer; | 48 extern void *runtime·CreateWaitableTimer; |
47 extern void *runtime·CryptAcquireContextW; | 49 extern void *runtime·CryptAcquireContextW; |
48 extern void *runtime·CryptGenRandom; | 50 extern void *runtime·CryptGenRandom; |
49 extern void *runtime·CryptReleaseContext; | 51 extern void *runtime·CryptReleaseContext; |
50 extern void *runtime·DuplicateHandle; | 52 extern void *runtime·DuplicateHandle; |
51 extern void *runtime·ExitProcess; | 53 extern void *runtime·ExitProcess; |
52 extern void *runtime·FreeEnvironmentStringsW; | 54 extern void *runtime·FreeEnvironmentStringsW; |
53 extern void *runtime·GetEnvironmentStringsW; | 55 extern void *runtime·GetEnvironmentStringsW; |
54 extern void *runtime·GetProcAddress; | 56 extern void *runtime·GetProcAddress; |
| 57 extern void *runtime·GetQueuedCompletionStatusEx; |
55 extern void *runtime·GetStdHandle; | 58 extern void *runtime·GetStdHandle; |
56 extern void *runtime·GetSystemInfo; | 59 extern void *runtime·GetSystemInfo; |
57 extern void *runtime·GetSystemTimeAsFileTime; | 60 extern void *runtime·GetSystemTimeAsFileTime; |
58 extern void *runtime·GetThreadContext; | 61 extern void *runtime·GetThreadContext; |
59 extern void *runtime·LoadLibrary; | 62 extern void *runtime·LoadLibrary; |
60 extern void *runtime·LoadLibraryA; | 63 extern void *runtime·LoadLibraryA; |
| 64 extern void *runtime·NtWaitForSingleObject; |
61 extern void *runtime·ResumeThread; | 65 extern void *runtime·ResumeThread; |
62 extern void *runtime·SetConsoleCtrlHandler; | 66 extern void *runtime·SetConsoleCtrlHandler; |
63 extern void *runtime·SetEvent; | 67 extern void *runtime·SetEvent; |
| 68 extern void *runtime·SetProcessPriorityBoost; |
64 extern void *runtime·SetThreadPriority; | 69 extern void *runtime·SetThreadPriority; |
65 extern void *runtime·SetWaitableTimer; | 70 extern void *runtime·SetWaitableTimer; |
66 extern void *runtime·Sleep; | 71 extern void *runtime·Sleep; |
67 extern void *runtime·SuspendThread; | 72 extern void *runtime·SuspendThread; |
68 extern void *runtime·timeBeginPeriod; | |
69 extern void *runtime·WaitForSingleObject; | 73 extern void *runtime·WaitForSingleObject; |
70 extern void *runtime·WriteFile; | 74 extern void *runtime·WriteFile; |
71 | 75 extern void *runtime·timeBeginPeriod; |
72 void *runtime·GetQueuedCompletionStatusEx; | |
73 | 76 |
74 extern uintptr runtime·externalthreadhandlerp; | 77 extern uintptr runtime·externalthreadhandlerp; |
75 void runtime·externalthreadhandler(void); | 78 void runtime·externalthreadhandler(void); |
| 79 void runtime·sigtramp(void); |
76 | 80 |
77 static int32 | 81 static int32 |
78 getproccount(void) | 82 getproccount(void) |
79 { | 83 { |
80 SystemInfo info; | 84 SystemInfo info; |
81 | 85 |
82 runtime·stdcall(runtime·GetSystemInfo, 1, &info); | 86 runtime·stdcall(runtime·GetSystemInfo, 1, &info); |
83 return info.dwNumberOfProcessors; | 87 return info.dwNumberOfProcessors; |
84 } | 88 } |
85 | 89 |
86 void | 90 void |
87 runtime·osinit(void) | 91 runtime·osinit(void) |
88 { | 92 { |
89 void *kernel32; | |
90 void *SetProcessPriorityBoost; | |
91 | |
92 runtime·externalthreadhandlerp = (uintptr)runtime·externalthreadhandler; | 93 runtime·externalthreadhandlerp = (uintptr)runtime·externalthreadhandler; |
93 | 94 |
| 95 runtime·stdcall(runtime·AddVectoredExceptionHandler, 2, (uintptr)1, (uin
tptr)runtime·sigtramp); |
94 runtime·stdcall(runtime·SetConsoleCtrlHandler, 2, runtime·ctrlhandler, (
uintptr)1); | 96 runtime·stdcall(runtime·SetConsoleCtrlHandler, 2, runtime·ctrlhandler, (
uintptr)1); |
95 runtime·stdcall(runtime·timeBeginPeriod, 1, (uintptr)1); | 97 runtime·stdcall(runtime·timeBeginPeriod, 1, (uintptr)1); |
96 runtime·ncpu = getproccount(); | 98 runtime·ncpu = getproccount(); |
97 | 99 » |
98 » kernel32 = runtime·stdcall(runtime·LoadLibraryA, 1, "kernel32.dll"); | 100 » // Windows dynamic priority boosting assumes that a process has differen
t types |
99 » if(kernel32 != nil) { | 101 » // of dedicated threads -- GUI, IO, computational, etc. Go processes use |
100 » » // Windows dynamic priority boosting assumes that a process has
different types | 102 » // equivalent threads that all do a mix of GUI, IO, computations, etc. |
101 » » // of dedicated threads -- GUI, IO, computational, etc. Go proce
sses use | 103 » // In such context dynamic priority boosting does nothing but harm, so w
e turn it off. |
102 » » // equivalent threads that all do a mix of GUI, IO, computations
, etc. | 104 » runtime·stdcall(runtime·SetProcessPriorityBoost, 2, (uintptr)-1, (uintpt
r)1); |
103 » » // In such context dynamic priority boosting does nothing but ha
rm, so we turn it off. | |
104 » » SetProcessPriorityBoost = runtime·stdcall(runtime·GetProcAddress
, 2, kernel32, "SetProcessPriorityBoost"); | |
105 » » if(SetProcessPriorityBoost != nil) // supported since Windows X
P | |
106 » » » runtime·stdcall(SetProcessPriorityBoost, 2, (uintptr)-1,
(uintptr)1); | |
107 » » runtime·GetQueuedCompletionStatusEx = runtime·stdcall(runtime·Ge
tProcAddress, 2, kernel32, "GetQueuedCompletionStatusEx"); | |
108 » } | |
109 } | 105 } |
110 | 106 |
111 void | 107 void |
112 runtime·get_random_data(byte **rnd, int32 *rnd_len) | 108 runtime·get_random_data(byte **rnd, int32 *rnd_len) |
113 { | 109 { |
114 uintptr handle; | 110 uintptr handle; |
115 *rnd = nil; | 111 *rnd = nil; |
116 *rnd_len = 0; | 112 *rnd_len = 0; |
117 if(runtime·stdcall(runtime·CryptAcquireContextW, 5, &handle, nil, nil, | 113 if(runtime·stdcall(runtime·CryptAcquireContextW, 5, &handle, nil, nil, |
118 (uintptr)1 /* PROV_RSA_FULL */, | 114 (uintptr)1 /* PROV_RSA_FULL */, |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 case EXCEPTION_FLT_DENORMAL_OPERAND: | 358 case EXCEPTION_FLT_DENORMAL_OPERAND: |
363 case EXCEPTION_FLT_DIVIDE_BY_ZERO: | 359 case EXCEPTION_FLT_DIVIDE_BY_ZERO: |
364 case EXCEPTION_FLT_INEXACT_RESULT: | 360 case EXCEPTION_FLT_INEXACT_RESULT: |
365 case EXCEPTION_FLT_OVERFLOW: | 361 case EXCEPTION_FLT_OVERFLOW: |
366 case EXCEPTION_FLT_UNDERFLOW: | 362 case EXCEPTION_FLT_UNDERFLOW: |
367 runtime·panicstring("floating point error"); | 363 runtime·panicstring("floating point error"); |
368 } | 364 } |
369 runtime·throw("fault"); | 365 runtime·throw("fault"); |
370 } | 366 } |
371 | 367 |
372 extern void *runtime·sigtramp; | |
373 | |
374 void | 368 void |
375 runtime·initsig(void) | 369 runtime·initsig(void) |
376 { | 370 { |
377 // following line keeps sigtramp alive at link stage | 371 // following line keeps sigtramp alive at link stage |
378 // if there's a better way please write it here | 372 // if there's a better way please write it here |
379 void *p = runtime·sigtramp; | 373 void *p = runtime·sigtramp; |
380 USED(p); | 374 USED(p); |
381 } | 375 } |
382 | 376 |
383 uint32 | 377 uint32 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 { | 499 { |
506 // TODO: This routine should do whatever is needed | 500 // TODO: This routine should do whatever is needed |
507 // to make the Windows program abort/crash as it | 501 // to make the Windows program abort/crash as it |
508 // would if Go was not intercepting signals. | 502 // would if Go was not intercepting signals. |
509 // On Unix the routine would remove the custom signal | 503 // On Unix the routine would remove the custom signal |
510 // handler and then raise a signal (like SIGABRT). | 504 // handler and then raise a signal (like SIGABRT). |
511 // Something like that should happen here. | 505 // Something like that should happen here. |
512 // It's okay to leave this empty for now: if crash returns | 506 // It's okay to leave this empty for now: if crash returns |
513 // the ordinary exit-after-panic happens. | 507 // the ordinary exit-after-panic happens. |
514 } | 508 } |
LEFT | RIGHT |