34
34
#pragma dynimport runtime·SetEvent SetEvent "kernel32.dll"
35
35
#pragma dynimport runtime·SetProcessPriorityBoost SetProcessPriorityBoost "kernel32.dll"
36
36
#pragma dynimport runtime·SetThreadPriority SetThreadPriority "kernel32.dll"
37
+ #pragma dynimport runtime·SetUnhandledExceptionFilter SetUnhandledExceptionFilter "kernel32.dll"
37
38
#pragma dynimport runtime·SetWaitableTimer SetWaitableTimer "kernel32.dll"
38
39
#pragma dynimport runtime·Sleep Sleep "kernel32.dll"
39
40
#pragma dynimport runtime·SuspendThread SuspendThread "kernel32.dll"
@@ -65,6 +66,7 @@ extern void *runtime·SetConsoleCtrlHandler;
65
66
extern void * runtime·SetEvent ;
66
67
extern void * runtime·SetProcessPriorityBoost ;
67
68
extern void * runtime·SetThreadPriority ;
69
+ extern void * runtime·SetUnhandledExceptionFilter ;
68
70
extern void * runtime·SetWaitableTimer ;
69
71
extern void * runtime·Sleep ;
70
72
extern void * runtime·SuspendThread ;
@@ -77,7 +79,9 @@ void *runtime·GetQueuedCompletionStatusEx;
77
79
78
80
extern uintptr runtime·externalthreadhandlerp ;
79
81
void runtime·externalthreadhandler (void );
80
- void runtime·sigtramp (void );
82
+ void runtime·exceptiontramp (void );
83
+ void runtime·firstcontinuetramp (void );
84
+ void runtime·lastcontinuetramp (void );
81
85
82
86
#pragma textflag NOSPLIT
83
87
uintptr
@@ -106,12 +110,30 @@ void
106
110
runtime·osinit (void )
107
111
{
108
112
void * kernel32 ;
113
+ void * addVectoredContinueHandler ;
114
+
115
+ kernel32 = runtime·stdcall1 (runtime·LoadLibraryA , (uintptr )"kernel32.dll" );
109
116
110
117
runtime·externalthreadhandlerp = (uintptr )runtime·externalthreadhandler ;
111
118
112
- runtime·stdcall2 (runtime·AddVectoredExceptionHandler , 1 , (uintptr )runtime·sigtramp );
119
+ runtime·stdcall2 (runtime·AddVectoredExceptionHandler , 1 , (uintptr )runtime·exceptiontramp );
120
+ addVectoredContinueHandler = nil ;
121
+ if (kernel32 != nil )
122
+ addVectoredContinueHandler = runtime·stdcall2 (runtime·GetProcAddress , (uintptr )kernel32 , (uintptr )"AddVectoredContinueHandler" );
123
+ if (addVectoredContinueHandler == nil || sizeof (void * ) == 4 ) {
124
+ // use SetUnhandledExceptionFilter for windows-386 or
125
+ // if VectoredContinueHandler is unavailable.
126
+ // note: SetUnhandledExceptionFilter handler won't be called, if debugging.
127
+ runtime·stdcall1 (runtime·SetUnhandledExceptionFilter , (uintptr )runtime·lastcontinuetramp );
128
+ } else {
129
+ runtime·stdcall2 (addVectoredContinueHandler , 1 , (uintptr )runtime·firstcontinuetramp );
130
+ runtime·stdcall2 (addVectoredContinueHandler , 0 , (uintptr )runtime·lastcontinuetramp );
131
+ }
132
+
113
133
runtime·stdcall2 (runtime·SetConsoleCtrlHandler , (uintptr )runtime·ctrlhandler , 1 );
134
+
114
135
runtime·stdcall1 (runtime·timeBeginPeriod , 1 );
136
+
115
137
runtime·ncpu = getproccount ();
116
138
117
139
// Windows dynamic priority boosting assumes that a process has different types
@@ -120,7 +142,6 @@ runtime·osinit(void)
120
142
// In such context dynamic priority boosting does nothing but harm, so we turn it off.
121
143
runtime·stdcall2 (runtime·SetProcessPriorityBoost , -1 , 1 );
122
144
123
- kernel32 = runtime·stdcall1 (runtime·LoadLibraryA , (uintptr )"kernel32.dll" );
124
145
if (kernel32 != nil ) {
125
146
runtime·GetQueuedCompletionStatusEx = runtime·stdcall2 (runtime·GetProcAddress , (uintptr )kernel32 , (uintptr )"GetQueuedCompletionStatusEx" );
126
147
}
@@ -467,6 +488,7 @@ runtime·issigpanic(uint32 code)
467
488
case EXCEPTION_FLT_INEXACT_RESULT :
468
489
case EXCEPTION_FLT_OVERFLOW :
469
490
case EXCEPTION_FLT_UNDERFLOW :
491
+ case EXCEPTION_BREAKPOINT :
470
492
return 1 ;
471
493
}
472
494
return 0 ;
@@ -475,10 +497,14 @@ runtime·issigpanic(uint32 code)
475
497
void
476
498
runtime·initsig (void )
477
499
{
478
- // following line keeps sigtramp alive at link stage
500
+ // following line keeps these functions alive at link stage
479
501
// if there's a better way please write it here
480
- void * p = runtime·sigtramp ;
481
- USED (p );
502
+ void * e = runtime·exceptiontramp ;
503
+ void * f = runtime·firstcontinuetramp ;
504
+ void * l = runtime·lastcontinuetramp ;
505
+ USED (e );
506
+ USED (f );
507
+ USED (l );
482
508
}
483
509
484
510
uint32
0 commit comments