From f154da9e12608589e8d5f0508f908a0c3e88a1bb Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Thu, 15 Jan 2015 11:54:00 -0700 Subject: Imported Upstream version 1.4 --- src/runtime/runtime.c | 399 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 399 insertions(+) create mode 100644 src/runtime/runtime.c (limited to 'src/runtime/runtime.c') diff --git a/src/runtime/runtime.c b/src/runtime/runtime.c new file mode 100644 index 000000000..c823691ec --- /dev/null +++ b/src/runtime/runtime.c @@ -0,0 +1,399 @@ +// 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" +#include "stack.h" +#include "arch_GOARCH.h" +#include "textflag.h" +#include "malloc.h" + +// Keep a cached value to make gotraceback fast, +// since we call it on every call to gentraceback. +// The cached value is a uint32 in which the low bit +// is the "crash" setting and the top 31 bits are the +// gotraceback value. +static uint32 traceback_cache = 2<<1; + +// The GOTRACEBACK environment variable controls the +// behavior of a Go program that is crashing and exiting. +// GOTRACEBACK=0 suppress all tracebacks +// GOTRACEBACK=1 default behavior - show tracebacks but exclude runtime frames +// GOTRACEBACK=2 show tracebacks including runtime frames +// GOTRACEBACK=crash show tracebacks including runtime frames, then crash (core dump etc) +#pragma textflag NOSPLIT +int32 +runtime·gotraceback(bool *crash) +{ + if(crash != nil) + *crash = false; + if(g->m->traceback != 0) + return g->m->traceback; + if(crash != nil) + *crash = traceback_cache&1; + return traceback_cache>>1; +} + +int32 +runtime·mcmp(byte *s1, byte *s2, uintptr n) +{ + uintptr i; + byte c1, c2; + + for(i=0; i c2) + return +1; + } + return 0; +} + + +byte* +runtime·mchr(byte *p, byte c, byte *ep) +{ + for(; p < ep; p++) + if(*p == c) + return p; + return nil; +} + +static int32 argc; + +#pragma dataflag NOPTR /* argv not a heap pointer */ +static uint8** argv; + +extern Slice runtime·argslice; +extern Slice runtime·envs; + +void (*runtime·sysargs)(int32, uint8**); + +void +runtime·args(int32 c, uint8 **v) +{ + argc = c; + argv = v; + if(runtime·sysargs != nil) + runtime·sysargs(c, v); +} + +int32 runtime·isplan9; +int32 runtime·issolaris; +int32 runtime·iswindows; + +// Information about what cpu features are available. +// Set on startup in asm_{x86/amd64}.s. +uint32 runtime·cpuid_ecx; +uint32 runtime·cpuid_edx; + +void +runtime·goargs(void) +{ + String *s; + int32 i; + + // for windows implementation see "os" package + if(Windows) + return; + + runtime·argslice = runtime·makeStringSlice(argc); + s = (String*)runtime·argslice.array; + for(i=0; i= 0; bit--) { + if(v >= ((int64)div<= (int64)div) { + if(rem != nil) + *rem = 0; + return 0x7fffffff; + } + if(rem != nil) + *rem = v; + return res; +} + +// Helpers for Go. Must be NOSPLIT, must only call NOSPLIT functions, and must not block. + +#pragma textflag NOSPLIT +G* +runtime·getg(void) +{ + return g; +} + +#pragma textflag NOSPLIT +M* +runtime·acquirem(void) +{ + g->m->locks++; + return g->m; +} + +#pragma textflag NOSPLIT +void +runtime·releasem(M *mp) +{ + mp->locks--; + if(mp->locks == 0 && g->preempt) { + // restore the preemption request in case we've cleared it in newstack + g->stackguard0 = StackPreempt; + } +} + +#pragma textflag NOSPLIT +MCache* +runtime·gomcache(void) +{ + return g->m->mcache; +} + +#pragma textflag NOSPLIT +Slice +reflect·typelinks(void) +{ + extern Type *runtime·typelink[], *runtime·etypelink[]; + Slice ret; + + ret.array = (byte*)runtime·typelink; + ret.len = runtime·etypelink - runtime·typelink; + ret.cap = ret.len; + return ret; +} -- cgit v1.2.3