From 5c262e9444e555c78381c008c3fabd2637e57859 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 14 Nov 2011 22:26:45 +0000 Subject: runtime: Use some of 6g runtime.c for easier merging. From-SVN: r181368 --- libgo/runtime/runtime.c | 174 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 libgo/runtime/runtime.c (limited to 'libgo/runtime/runtime.c') diff --git a/libgo/runtime/runtime.c b/libgo/runtime/runtime.c new file mode 100644 index 0000000..d598f79 --- /dev/null +++ b/libgo/runtime/runtime.c @@ -0,0 +1,174 @@ +// 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 + +#include "runtime.h" +#include "array.h" +#include "go-panic.h" +#include "go-string.h" + +uint32 runtime_panicking; + +static Lock paniclk; + +void +runtime_initpanic(void) +{ + runtime_initlock(&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 __attribute__ ((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(!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_initlock(&deadlock); + runtime_lock(&deadlock); + runtime_lock(&deadlock); + } + + runtime_exit(2); +} + +void +runtime_throw(const char *s) +{ + runtime_startpanic(); + runtime_printf("throw: %s\n", s); + runtime_dopanic(0); + *(int32*)0 = 0; // not reached + runtime_exit(1); // even more not reached +} + +static int32 argc; +static byte** argv; + +extern Slice os_Args asm ("libgo_os.os.Args"); +extern Slice os_Envs asm ("libgo_os.os.Envs"); + +void +runtime_args(int32 c, byte **v) +{ + argc = c; + argv = v; +} + +void +runtime_goargs(void) +{ + String *s; + int32 i; + + // for windows implementation see "os" package + if(Windows) + return; + + s = runtime_malloc(argc*sizeof s[0]); + for(i=0; ifastrand; + x += x; + if(x & 0x80000000L) + x ^= 0x88888eefUL; + m->fastrand = x; + return x; +} -- cgit v1.1