diff options
| author | Dmitriy Vyukov <dvyukov@google.com> | 2012-07-04 14:52:51 +0400 |
|---|---|---|
| committer | Dmitriy Vyukov <dvyukov@google.com> | 2012-07-04 14:52:51 +0400 |
| commit | a54f920bfe473721ef98d94feb88f395cb642cd4 (patch) | |
| tree | 95935080b2399bec29e615c7db0411dad7463b2e /src/pkg/runtime/runtime.c | |
| parent | 6044dbdf1b627fc1f30422add87216137b709bae (diff) | |
| download | go-a54f920bfe473721ef98d94feb88f395cb642cd4.tar.xz | |
runtime: move panic/defer/recover-related stuff to a separate file
Move panic/defer/recover-related stuff from proc.c/runtime.c to a new file panic.c.
No semantic changes.
proc.c is 1800+ LOC and is a bit difficult to work with.
R=golang-dev, dave, r
CC=golang-dev
https://golang.org/cl/6343071
Diffstat (limited to 'src/pkg/runtime/runtime.c')
| -rw-r--r-- | src/pkg/runtime/runtime.c | 126 |
1 files changed, 25 insertions, 101 deletions
diff --git a/src/pkg/runtime/runtime.c b/src/pkg/runtime/runtime.c index cca061be79..08477e461a 100644 --- a/src/pkg/runtime/runtime.c +++ b/src/pkg/runtime/runtime.c @@ -3,16 +3,12 @@ // license that can be found in the LICENSE file. #include "runtime.h" -#include "stack.h" #include "arch_GOARCH.h" enum { maxround = sizeof(uintptr), }; -uint32 runtime·panicking; -void (*runtime·destroylock)(Lock*); - /* * We assume that all architectures turn faults and the like * into apparent calls to runtime.sigpanic. If we see a "call" @@ -32,103 +28,6 @@ runtime·gotraceback(void) return runtime·atoi(p); } -static Lock paniclk; - -void -runtime·startpanic(void) -{ - if(m->dying) { - runtime·printf("panic during panic\n"); - runtime·exit(3); - } - m->dying = 1; - runtime·xadd(&runtime·panicking, 1); - runtime·lock(&paniclk); -} - -void -runtime·dopanic(int32 unused) -{ - static bool didothers; - - if(g->sig != 0) - runtime·printf("[signal %x code=%p addr=%p pc=%p]\n", - g->sig, g->sigcode0, g->sigcode1, g->sigpc); - - if(runtime·gotraceback()){ - if(g != m->g0) { - runtime·printf("\n"); - runtime·goroutineheader(g); - runtime·traceback(runtime·getcallerpc(&unused), runtime·getcallersp(&unused), 0, g); - } - if(!didothers) { - didothers = true; - runtime·tracebackothers(g); - } - } - runtime·unlock(&paniclk); - if(runtime·xadd(&runtime·panicking, -1) != 0) { - // Some other m is panicking too. - // Let it print what it needs to print. - // Wait forever without chewing up cpu. - // It will exit when it's done. - static Lock deadlock; - runtime·lock(&deadlock); - runtime·lock(&deadlock); - } - - runtime·exit(2); -} - -void -runtime·panicindex(void) -{ - runtime·panicstring("index out of range"); -} - -void -runtime·panicslice(void) -{ - runtime·panicstring("slice bounds out of range"); -} - -void -runtime·throwreturn(void) -{ - // can only happen if compiler is broken - runtime·throw("no return at end of a typed function - compiler is broken"); -} - -void -runtime·throwinit(void) -{ - // can only happen with linker skew - runtime·throw("recursive call during initialization - linker skew"); -} - -void -runtime·throw(int8 *s) -{ - runtime·startpanic(); - runtime·printf("throw: %s\n", s); - runtime·dopanic(0); - *(int32*)0 = 0; // not reached - runtime·exit(1); // even more not reached -} - -void -runtime·panicstring(int8 *s) -{ - Eface err; - - if(m->gcing) { - runtime·printf("panic: %s\n", s); - runtime·throw("panic during gc"); - } - runtime·newErrorString(runtime·gostringnocopy((byte*)s), &err); - runtime·panic(err); -} - int32 runtime·mcmp(byte *s1, byte *s2, uint32 n) { @@ -234,6 +133,31 @@ runtime·getenv(int8 *s) return nil; } +void (*libcgo_setenv)(byte**); + +// Update the C environment if cgo is loaded. +// Called from syscall.Setenv. +void +syscall·setenv_c(String k, String v) +{ + byte *arg[2]; + + if(libcgo_setenv == nil) + return; + + arg[0] = runtime·malloc(k.len + 1); + runtime·memmove(arg[0], k.str, k.len); + arg[0][k.len] = 0; + + arg[1] = runtime·malloc(v.len + 1); + runtime·memmove(arg[1], v.str, v.len); + arg[1][v.len] = 0; + + runtime·asmcgocall((void*)libcgo_setenv, arg); + runtime·free(arg[0]); + runtime·free(arg[1]); +} + void runtime·getgoroot(String out) { |
