@@ -32,45 +32,76 @@ runtime·dumpregs(Context *r)
32
32
runtime·printf ("gs %X\n" , (uint64 )r -> SegGs );
33
33
}
34
34
35
- // Called by sigtramp from Windows VEH handler.
36
- // Return value signals whether the exception has been handled (-1)
37
- // or should be made available to other handlers in the chain (0).
38
- uint32
39
- runtime·sighandler (ExceptionRecord * info , Context * r , G * gp )
35
+ bool
36
+ runtime·isgoexception (ExceptionRecord * info , Context * r )
40
37
{
41
- bool crash ;
42
- uintptr * sp ;
43
38
extern byte runtime·text [], runtime·etext [];
44
39
45
40
// Only handle exception if executing instructions in Go binary
46
41
// (not Windows library code).
47
42
if (r -> Rip < (uint64 )runtime·text || (uint64 )runtime·etext < r -> Rip )
48
- return 0 ;
49
-
50
- if (gp != nil && runtime·issigpanic (info -> ExceptionCode )) {
51
- // Make it look like a call to the signal func.
52
- // Have to pass arguments out of band since
53
- // augmenting the stack frame would break
54
- // the unwinding code.
55
- gp -> sig = info -> ExceptionCode ;
56
- gp -> sigcode0 = info -> ExceptionInformation [0 ];
57
- gp -> sigcode1 = info -> ExceptionInformation [1 ];
58
- gp -> sigpc = r -> Rip ;
59
-
60
- // Only push runtime·sigpanic if r->rip != 0.
61
- // If r->rip == 0, probably panicked because of a
62
- // call to a nil func. Not pushing that onto sp will
63
- // make the trace look like a call to runtime·sigpanic instead.
64
- // (Otherwise the trace will end at runtime·sigpanic and we
65
- // won't get to see who faulted.)
66
- if (r -> Rip != 0 ) {
67
- sp = (uintptr * )r -> Rsp ;
68
- * -- sp = r -> Rip ;
69
- r -> Rsp = (uintptr )sp ;
70
- }
71
- r -> Rip = (uintptr )runtime·sigpanic ;
72
- return -1 ;
43
+ return false;
44
+
45
+ if (!runtime·issigpanic (info -> ExceptionCode ))
46
+ return false;
47
+
48
+ return true;
49
+ }
50
+
51
+ // Called by sigtramp from Windows VEH handler.
52
+ // Return value signals whether the exception has been handled (EXCEPTION_CONTINUE_EXECUTION)
53
+ // or should be made available to other handlers in the chain (EXCEPTION_CONTINUE_SEARCH).
54
+ uint32
55
+ runtime·exceptionhandler (ExceptionRecord * info , Context * r , G * gp )
56
+ {
57
+ uintptr * sp ;
58
+
59
+ if (!runtime·isgoexception (info , r ))
60
+ return EXCEPTION_CONTINUE_SEARCH ;
61
+
62
+ // Make it look like a call to the signal func.
63
+ // Have to pass arguments out of band since
64
+ // augmenting the stack frame would break
65
+ // the unwinding code.
66
+ gp -> sig = info -> ExceptionCode ;
67
+ gp -> sigcode0 = info -> ExceptionInformation [0 ];
68
+ gp -> sigcode1 = info -> ExceptionInformation [1 ];
69
+ gp -> sigpc = r -> Rip ;
70
+
71
+ // Only push runtime·sigpanic if r->rip != 0.
72
+ // If r->rip == 0, probably panicked because of a
73
+ // call to a nil func. Not pushing that onto sp will
74
+ // make the trace look like a call to runtime·sigpanic instead.
75
+ // (Otherwise the trace will end at runtime·sigpanic and we
76
+ // won't get to see who faulted.)
77
+ if (r -> Rip != 0 ) {
78
+ sp = (uintptr * )r -> Rsp ;
79
+ * -- sp = r -> Rip ;
80
+ r -> Rsp = (uintptr )sp ;
73
81
}
82
+ r -> Rip = (uintptr )runtime·sigpanic ;
83
+ return EXCEPTION_CONTINUE_EXECUTION ;
84
+ }
85
+
86
+ // It seems Windows searches ContinueHandler's list even
87
+ // if ExceptionHandler returns EXCEPTION_CONTINUE_EXECUTION.
88
+ // firstcontinuehandler will stop that search,
89
+ // if exceptionhandler did the same earlier.
90
+ uint32
91
+ runtime·firstcontinuehandler (ExceptionRecord * info , Context * r , G * gp )
92
+ {
93
+ USED (gp );
94
+ if (!runtime·isgoexception (info , r ))
95
+ return EXCEPTION_CONTINUE_SEARCH ;
96
+ return EXCEPTION_CONTINUE_EXECUTION ;
97
+ }
98
+
99
+ // lastcontinuehandler is reached, because runtime cannot handle
100
+ // current exception. lastcontinuehandler will print crash info and exit.
101
+ uint32
102
+ runtime·lastcontinuehandler (ExceptionRecord * info , Context * r , G * gp )
103
+ {
104
+ bool crash ;
74
105
75
106
if (runtime·panicking ) // traceback already printed
76
107
runtime·exit (2 );
@@ -97,7 +128,7 @@ runtime·sighandler(ExceptionRecord *info, Context *r, G *gp)
97
128
runtime·crash ();
98
129
99
130
runtime·exit (2 );
100
- return -1 ; // not reached
131
+ return 0 ; // not reached
101
132
}
102
133
103
134
void
0 commit comments