// Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. #include "runtime.h" int32 panicking = 0; int32 maxround = sizeof(uintptr); int32 fd = 1; int32 gotraceback(void) { byte *p; p = getenv("GOTRACEBACK"); if(p == nil || p[0] == '\0') return 1; // default is on return atoi(p); } void panic(int32 unused) { uint8 *sp; fd = 2; if(panicking) { printf("double panic\n"); exit(3); } panicking++; printf("\npanic PC=%X\n", (uint64)(uintptr)&unused); if(gotraceback()){ traceback(·getcallerpc(&unused), getcallersp(&unused), 0, g); tracebackothers(g); } breakpoint(); // so we can grab it in a debugger exit(2); } void ·panicindex(void) { panicstring("index out of range"); } void ·panicslice(void) { panicstring("slice bounds out of range"); } void ·throwreturn(void) { // can only happen if compiler is broken throw("no return at end of a typed function - compiler is broken"); } void ·throwinit(void) { // can only happen with linker skew throw("recursive call during initialization - linker skew"); } void throw(int8 *s) { fd = 2; printf("throw: %s\n", s); panic(-1); *(int32*)0 = 0; // not reached exit(1); // even more not reached } void panicstring(int8 *s) { Eface err; ·newErrorString(gostring((byte*)s), &err); ·panic(err); } void mcpy(byte *t, byte *f, uint32 n) { while(n > 0) { *t = *f; t++; f++; n--; } } int32 mcmp(byte *s1, byte *s2, uint32 n) { uint32 i; byte c1, c2; for(i=0; i c2) return +1; } return 0; } byte* mchr(byte *p, byte c, byte *ep) { for(; p < ep; p++) if(*p == c) return p; return nil; } uint32 rnd(uint32 n, uint32 m) { uint32 r; if(m > maxround) m = maxround; r = n % m; if(r) n += m-r; return n; } static int32 argc; static uint8** argv; Slice os·Args; Slice os·Envs; void args(int32 c, uint8 **v) { argc = c; argv = v; } void goargs(void) { String *gargv; String *genvv; int32 i, envc; for(envc=0; argv[argc+1+envc] != 0; envc++) ; gargv = malloc(argc*sizeof gargv[0]); genvv = malloc(envc*sizeof genvv[0]); for(i=0; i 0) { if(sizeof(hash) == 4) hash = (hash ^ *b) * 3267000013UL; else hash = (hash ^ *b) * 23344194077549503ULL; b++; s--; } return hash; } static uint32 memequal(uint32 s, void *a, void *b) { byte *ba, *bb; uint32 i; ba = a; bb = b; for(i=0; isrc; retline = funcline(f, retpc-1); retbool = true; } FLUSH(&retfile); FLUSH(&retline); FLUSH(&retbool); } void ·Callers(int32 skip, Slice pc, int32 retn) { retn = callers(skip, (uintptr*)pc.array, pc.len); FLUSH(&retn); } void ·FuncForPC(uintptr pc, void *retf) { retf = findfunc(pc); FLUSH(&retf); }