// 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 runtime·panicl(int32 lno) { uint8 *sp; fd = 2; if(panicking) { printf("double panic\n"); exit(3); } panicking++; printf("\npanic PC=%X\n", (uint64)(uintptr)&lno); sp = (uint8*)&lno; if(gotraceback()){ traceback(runtime·getcallerpc(&lno), sp, g); tracebackothers(g); } breakpoint(); // so we can grab it in a debugger exit(2); } void runtime·throwindex(void) { throw("index out of range"); } void runtime·throwslice(void) { throw("slice out of range"); } void runtime·throwreturn(void) { throw("no return at end of a typed function"); } void runtime·throwinit(void) { throw("recursive call during initialization"); } void throw(int8 *s) { fd = 2; printf("throw: %s\n", s); runtime·panicl(-1); *(int32*)0 = 0; // not reached exit(1); // even more not reached } 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; i