LEFT | RIGHT |
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 "defs_GOOS_GOARCH.h" | 6 #include "defs_GOOS_GOARCH.h" |
7 #include "os_GOOS.h" | 7 #include "os_GOOS.h" |
8 #include "arch_GOARCH.h" | |
9 #include "signals_GOOS.h" | 8 #include "signals_GOOS.h" |
10 | 9 |
11 void | 10 void |
12 runtime·dumpregs(Ureg *u) | 11 runtime·dumpregs(Ureg *u) |
13 { | 12 { |
14 » runtime·printf("ax %X\n", u->ax); | 13 » runtime·printf("ax» %X\n", u->ax); |
15 » runtime·printf("bx %X\n", u->bx); | 14 » runtime·printf("bx» %X\n", u->bx); |
16 » runtime·printf("cx %X\n", u->cx); | 15 » runtime·printf("cx» %X\n", u->cx); |
17 » runtime·printf("dx %X\n", u->dx); | 16 » runtime·printf("dx» %X\n", u->dx); |
18 » runtime·printf("di %X\n", u->di); | 17 » runtime·printf("di» %X\n", u->di); |
19 » runtime·printf("si %X\n", u->si); | 18 » runtime·printf("si» %X\n", u->si); |
20 » runtime·printf("bp %X\n", u->bp); | 19 » runtime·printf("bp» %X\n", u->bp); |
21 » runtime·printf("sp %X\n", u->sp); | 20 » runtime·printf("sp» %X\n", u->sp); |
22 » runtime·printf("r8 %X\n", u->r8); | 21 » runtime·printf("r8» %X\n", u->r8); |
23 » runtime·printf("r9 %X\n", u->r9); | 22 » runtime·printf("r9» %X\n", u->r9); |
24 » runtime·printf("r10 %X\n", u->r10); | 23 » runtime·printf("r10» %X\n", u->r10); |
25 » runtime·printf("r11 %X\n", u->r11); | 24 » runtime·printf("r11» %X\n", u->r11); |
26 » runtime·printf("r12 %X\n", u->r12); | 25 » runtime·printf("r12» %X\n", u->r12); |
27 » runtime·printf("r13 %X\n", u->r13); | 26 » runtime·printf("r13» %X\n", u->r13); |
28 » runtime·printf("r14 %X\n", u->r14); | 27 » runtime·printf("r14» %X\n", u->r14); |
29 » runtime·printf("r15 %X\n", u->r15); | 28 » runtime·printf("r15» %X\n", u->r15); |
30 » runtime·printf("ip %X\n", u->ip); | 29 » runtime·printf("ip» %X\n", u->ip); |
31 » runtime·printf("flags %X\n", u->flags); | 30 » runtime·printf("flags» %X\n", u->flags); |
32 » runtime·printf("cs %X\n", (uint64)u->cs); | 31 » runtime·printf("cs» %X\n", (uint64)u->cs); |
33 » runtime·printf("fs %X\n", (uint64)u->fs); | 32 » runtime·printf("fs» %X\n", (uint64)u->fs); |
34 » runtime·printf("gs %X\n", (uint64)u->gs); | 33 » runtime·printf("gs» %X\n", (uint64)u->gs); |
35 } | 34 } |
36 | 35 |
37 int32 | 36 int32 |
38 runtime·sighandler(void *v, int8 *s, G *gp) | 37 runtime·sighandler(void *v, int8 *s, G *gp) |
39 { | 38 { |
40 Ureg *ureg; | 39 Ureg *ureg; |
| 40 uintptr *sp; |
41 SigTab *sig, *nsig; | 41 SigTab *sig, *nsig; |
42 int8 *err[NERRMAX]; | |
43 int32 len, i; | 42 int32 len, i; |
44 | 43 |
45 if(!s) | 44 if(!s) |
46 return NCONT; | 45 return NCONT; |
47 | |
48 if(s && *s == 0) | |
49 runtime·exits(nil); | |
50 ························ | 46 ························ |
51 len = runtime·findnull((byte*)s); | 47 len = runtime·findnull((byte*)s); |
52 if(len <= 4 || runtime·mcmp((byte*)s, (byte*)"sys:", 4) != 0) | 48 if(len <= 4 || runtime·mcmp((byte*)s, (byte*)"sys:", 4) != 0) |
53 » » runtime·exits(s); | 49 » » return NDFLT; |
54 | 50 |
55 nsig = nil; | 51 nsig = nil; |
56 sig = runtime·sigtab; | 52 sig = runtime·sigtab; |
57 for(i=0; i < NSIG; i++) { | 53 for(i=0; i < NSIG; i++) { |
58 if(runtime·strstr((byte*)s, (byte*)sig->name)) { | 54 if(runtime·strstr((byte*)s, (byte*)sig->name)) { |
59 nsig = sig; | 55 nsig = sig; |
60 break; | 56 break; |
61 } | 57 } |
62 sig++; | 58 sig++; |
63 } | 59 } |
64 | 60 |
65 if(nsig == nil) | 61 if(nsig == nil) |
66 » » runtime·exits(s); | 62 » » return NDFLT; |
67 | 63 |
68 ureg = v; | 64 ureg = v; |
69 if(nsig->flags & SigPanic) { | 65 if(nsig->flags & SigPanic) { |
70 » » if(gp == nil) | 66 » » if(gp == nil || m->notesig == 0) |
71 goto Throw; | 67 goto Throw; |
72 | 68 |
73 » » // Save error string from sigtramp's stack | 69 » » // Save error string from sigtramp's stack, |
74 » » // so we can reliably access it from the | 70 » » // into gsignal->sigcode0, so we can reliably |
75 » » // panic routines. | 71 » » // access it from the panic routines. |
76 » » runtime·memmove((void*)err, (void*)s, len); | 72 » » if(len > ERRMAX) |
| 73 » » » len = ERRMAX; |
| 74 » » runtime·memmove((void*)m->notesig, (void*)s, len); |
77 | 75 |
78 gp->sig = i; | 76 gp->sig = i; |
79 gp->sigcode0 = (uintptr)err; | |
80 gp->sigpc = ureg->ip; | 77 gp->sigpc = ureg->ip; |
81 | 78 |
| 79 // Only push runtime·sigpanic if ureg->ip != 0. |
| 80 // If ureg->ip == 0, probably panicked because of a |
| 81 // call to a nil func. Not pushing that onto sp will |
| 82 // make the trace look like a call to runtime·sigpanic instead. |
| 83 // (Otherwise the trace will end at runtime·sigpanic and we |
| 84 // won't get to see who faulted.) |
| 85 if(ureg->ip != 0) { |
| 86 sp = (uintptr*)ureg->sp; |
| 87 *--sp = ureg->ip; |
| 88 ureg->sp = (uint64)sp; |
| 89 } |
82 ureg->ip = (uintptr)runtime·sigpanic; | 90 ureg->ip = (uintptr)runtime·sigpanic; |
83 return NCONT; | 91 return NCONT; |
84 } | 92 } |
85 | 93 |
86 if(!(nsig->flags & SigThrow)) | 94 if(!(nsig->flags & SigThrow)) |
87 return NDFLT; | 95 return NDFLT; |
88 | 96 |
89 Throw: | 97 Throw: |
90 runtime·startpanic(); | 98 runtime·startpanic(); |
91 | 99 |
(...skipping 18 matching lines...) Expand all Loading... |
110 USED(sig); | 118 USED(sig); |
111 } | 119 } |
112 | 120 |
113 void | 121 void |
114 runtime·resetcpuprofiler(int32 hz) | 122 runtime·resetcpuprofiler(int32 hz) |
115 { | 123 { |
116 // TODO: Enable profiling interrupts. | 124 // TODO: Enable profiling interrupts. |
117 ········ | 125 ········ |
118 m->profilehz = hz; | 126 m->profilehz = hz; |
119 } | 127 } |
LEFT | RIGHT |