21
18
void runtime·sigpanic(void);
20
// The GOTRACEBACK environment variable controls the
21
// behavior of a Go program that is crashing and exiting.
22
// GOTRACEBACK=0 suppress all tracebacks
23
// GOTRACEBACK=1 default behavior - show tracebacks but exclude runtime frames
24
// GOTRACEBACK=2 show tracebacks including runtime frames
25
// GOTRACEBACK=crash show tracebacks including runtime frames, then crash (core dump etc)
24
runtime·gotraceback(void)
27
runtime·gotraceback(bool *crash)
28
33
p = runtime·getenv("GOTRACEBACK");
29
34
if(p == nil || p[0] == '\0')
30
35
return 1; // default is on
36
if(runtime·strcmp(p, (byte*)"crash") == 0) {
39
return 2; // extra information
31
41
return runtime·atoi(p);
37
runtime·startpanic(void)
40
runtime·printf("panic during panic\n");
44
runtime·xadd(&runtime·panicking, 1);
45
runtime·lock(&paniclk);
49
runtime·dopanic(int32 unused)
51
static bool didothers;
54
runtime·printf("[signal %x code=%p addr=%p pc=%p]\n",
55
g->sig, g->sigcode0, g->sigcode1, g->sigpc);
57
if(runtime·gotraceback()){
60
runtime·goroutineheader(g);
61
runtime·traceback(runtime·getcallerpc(&unused), runtime·getcallersp(&unused), 0, g);
65
runtime·tracebackothers(g);
68
runtime·unlock(&paniclk);
69
if(runtime·xadd(&runtime·panicking, -1) != 0) {
70
// Some other m is panicking too.
71
// Let it print what it needs to print.
72
// Wait forever without chewing up cpu.
73
// It will exit when it's done.
75
runtime·lock(&deadlock);
76
runtime·lock(&deadlock);
83
runtime·panicindex(void)
85
runtime·panicstring("index out of range");
89
runtime·panicslice(void)
91
runtime·panicstring("slice bounds out of range");
95
runtime·throwreturn(void)
97
// can only happen if compiler is broken
98
runtime·throw("no return at end of a typed function - compiler is broken");
102
runtime·throwinit(void)
104
// can only happen with linker skew
105
runtime·throw("recursive call during initialization - linker skew");
109
runtime·throw(int8 *s)
111
runtime·startpanic();
112
runtime·printf("throw: %s\n", s);
114
*(int32*)0 = 0; // not reached
115
runtime·exit(1); // even more not reached
119
runtime·panicstring(int8 *s)
124
runtime·printf("panic: %s\n", s);
125
runtime·throw("panic during gc");
127
runtime·newErrorString(runtime·gostringnocopy((byte*)s), &err);
132
runtime·mcmp(byte *s1, byte *s2, uint32 n)
45
runtime·mcmp(byte *s1, byte *s2, uintptr n)
137
50
for(i=0; i<n; i++) {
159
runtime·rnd(uint32 n, uint32 m)
171
71
static int32 argc;
172
72
static uint8** argv;
175
75
Slice syscall·envs;
77
void (*runtime·sysargs)(int32, uint8**);
178
80
runtime·args(int32 c, uint8 **v)
84
if(runtime·sysargs != nil)
85
runtime·sysargs(c, v);
184
88
int32 runtime·isplan9;
185
89
int32 runtime·iswindows;
91
// Information about what cpu features are available.
92
// Set on startup in asm_{x86/amd64}.s.
93
uint32 runtime·cpuid_ecx;
94
uint32 runtime·cpuid_edx;
188
97
runtime·goargs(void)
160
if(runtime·cas64(&z64, &x64, 1))
161
runtime·throw("cas64 failed");
163
runtime·throw("cas64 failed");
164
if(!runtime·cas64(&z64, &x64, 1))
165
runtime·throw("cas64 failed");
166
if(x64 != 42 || z64 != 1)
167
runtime·throw("cas64 failed");
168
if(runtime·atomicload64(&z64) != 1)
169
runtime·throw("load64 failed");
170
runtime·atomicstore64(&z64, (1ull<<40)+1);
171
if(runtime·atomicload64(&z64) != (1ull<<40)+1)
172
runtime·throw("store64 failed");
173
if(runtime·xadd64(&z64, (1ull<<40)+1) != (2ull<<40)+2)
174
runtime·throw("xadd64 failed");
175
if(runtime·atomicload64(&z64) != (2ull<<40)+2)
176
runtime·throw("xadd64 failed");
177
if(runtime·xchg64(&z64, (3ull<<40)+3) != (2ull<<40)+2)
178
runtime·throw("xchg64 failed");
179
if(runtime·atomicload64(&z64) != (3ull<<40)+3)
180
runtime·throw("xchg64 failed");
271
184
runtime·check(void)
342
255
runtime·throw("float32nan2");
344
257
runtime·throw("float32nan3");
348
runtime·Caller(int32 skip, uintptr retpc, String retfile, int32 retline, bool retbool)
263
runtime·Caller(intgo skip, uintptr retpc, String retfile, intgo retline, bool retbool)
332
static Lock ticksLock;
336
runtime·tickspersecond(void)
338
int64 res, t0, t1, c0, c1;
340
res = (int64)runtime·atomicload64((uint64*)&ticks);
343
runtime·lock(&ticksLock);
346
t0 = runtime·nanotime();
347
c0 = runtime·cputicks();
348
runtime·usleep(100*1000);
349
t1 = runtime·nanotime();
350
c1 = runtime·cputicks();
353
res = (c1-c0)*1000*1000*1000/(t1-t0);
356
runtime·atomicstore64((uint64*)&ticks, res);
358
runtime·unlock(&ticksLock);
363
runtime∕pprof·runtime_cyclesPerSecond(int64 res)
365
res = runtime·tickspersecond();