summaryrefslogtreecommitdiff
path: root/src/pkg/runtime/runtime.c
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2011-08-03 17:26:15 +0200
committerOndřej Surý <ondrej@sury.org>2011-08-03 17:31:49 +0200
commitb757d264230d65f988e08158e096a09497d39eb4 (patch)
treee20ec608a2ec8ebf603fa7aa060eb9723c4780b9 /src/pkg/runtime/runtime.c
parent5976088995f5c0d0bcada7d491fda4b6245e54e0 (diff)
downloadgolang-b757d264230d65f988e08158e096a09497d39eb4.tar.gz
Imported Upstream version 2011.07.29
Diffstat (limited to 'src/pkg/runtime/runtime.c')
-rw-r--r--src/pkg/runtime/runtime.c79
1 files changed, 39 insertions, 40 deletions
diff --git a/src/pkg/runtime/runtime.c b/src/pkg/runtime/runtime.c
index 1a3653f10..c572897d2 100644
--- a/src/pkg/runtime/runtime.c
+++ b/src/pkg/runtime/runtime.c
@@ -11,6 +11,14 @@ enum {
uint32 runtime·panicking;
+/*
+ * We assume that all architectures turn faults and the like
+ * into apparent calls to runtime.sigpanic. If we see a "call"
+ * to runtime.sigpanic, we do not back up the PC to find the
+ * line number of the CALL instruction, because there is no CALL.
+ */
+void runtime·sigpanic(void);
+
int32
runtime·gotraceback(void)
{
@@ -116,17 +124,6 @@ runtime·panicstring(int8 *s)
runtime·panic(err);
}
-void
-runtime·mcpy(byte *t, byte *f, uint32 n)
-{
- while(n > 0) {
- *t = *f;
- t++;
- f++;
- n--;
- }
-}
-
int32
runtime·mcmp(byte *s1, byte *s2, uint32 n)
{
@@ -218,20 +215,6 @@ runtime·goenvs_unix(void)
os·Envs.cap = n;
}
-// Atomic add and return new value.
-uint32
-runtime·xadd(uint32 volatile *val, int32 delta)
-{
- uint32 oval, nval;
-
- for(;;){
- oval = *val;
- nval = oval + delta;
- if(runtime·cas(val, oval, nval))
- return nval;
- }
-}
-
byte*
runtime·getenv(int8 *s)
{
@@ -406,18 +389,11 @@ memprint(uint32 s, void *a)
static void
memcopy(uint32 s, void *a, void *b)
{
- byte *ba, *bb;
- uint32 i;
-
- ba = a;
- bb = b;
- if(bb == nil) {
- for(i=0; i<s; i++)
- ba[i] = 0;
+ if(b == nil) {
+ runtime·memclr(a,s);
return;
}
- for(i=0; i<s; i++)
- ba[i] = bb[i];
+ runtime·memmove(a,b,s);
}
static uint32
@@ -551,25 +527,35 @@ runtime·nanotime(void)
void
runtime·Caller(int32 skip, uintptr retpc, String retfile, int32 retline, bool retbool)
{
- Func *f;
+ Func *f, *g;
uintptr pc;
-
- if(runtime·callers(1+skip, &retpc, 1) == 0) {
+ uintptr rpc[2];
+
+ /*
+ * Ask for two PCs: the one we were asked for
+ * and what it called, so that we can see if it
+ * "called" sigpanic.
+ */
+ retpc = 0;
+ if(runtime·callers(1+skip-1, rpc, 2) < 2) {
retfile = runtime·emptystring;
retline = 0;
retbool = false;
- } else if((f = runtime·findfunc(retpc)) == nil) {
+ } else if((f = runtime·findfunc(rpc[1])) == nil) {
retfile = runtime·emptystring;
retline = 0;
retbool = true; // have retpc at least
} else {
+ retpc = rpc[1];
retfile = f->src;
pc = retpc;
- if(pc > f->entry)
+ g = runtime·findfunc(rpc[0]);
+ if(pc > f->entry && (g == nil || g->entry != (uintptr)runtime·sigpanic))
pc--;
retline = runtime·funcline(f, pc);
retbool = true;
}
+ FLUSH(&retpc);
FLUSH(&retfile);
FLUSH(&retline);
FLUSH(&retbool);
@@ -588,3 +574,16 @@ runtime·FuncForPC(uintptr pc, void *retf)
retf = runtime·findfunc(pc);
FLUSH(&retf);
}
+
+uint32
+runtime·fastrand1(void)
+{
+ uint32 x;
+
+ x = m->fastrand;
+ x += x;
+ if(x & 0x80000000L)
+ x ^= 0x88888eefUL;
+ m->fastrand = x;
+ return x;
+}