diff options
| author | Russ Cox <rsc@golang.org> | 2010-11-04 14:00:19 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2010-11-04 14:00:19 -0400 |
| commit | 68b4255a9644a838898bfc6567bae97585c2e871 (patch) | |
| tree | 6ba0f08e7aa2c5e8c3f883aeab0b79ae8efd4859 /src/pkg/runtime/runtime.c | |
| parent | 3b6ddd9bceb1e3c56f6cbfc28d51481a3036c653 (diff) | |
| download | go-68b4255a9644a838898bfc6567bae97585c2e871.tar.xz | |
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
Diffstat (limited to 'src/pkg/runtime/runtime.c')
| -rw-r--r-- | src/pkg/runtime/runtime.c | 207 |
1 files changed, 101 insertions, 106 deletions
diff --git a/src/pkg/runtime/runtime.c b/src/pkg/runtime/runtime.c index 9b874cec8d..0b19e108ed 100644 --- a/src/pkg/runtime/runtime.c +++ b/src/pkg/runtime/runtime.c @@ -4,87 +4,90 @@ #include "runtime.h" -int32 panicking = 0; -int32 maxround = sizeof(uintptr); -int32 fd = 1; +enum { + maxround = sizeof(uintptr), +}; + +int32 runtime·panicking = 0; +int32 runtime·fd = 1; int32 -gotraceback(void) +runtime·gotraceback(void) { byte *p; - p = getenv("GOTRACEBACK"); + p = runtime·getenv("GOTRACEBACK"); if(p == nil || p[0] == '\0') return 1; // default is on - return atoi(p); + return runtime·atoi(p); } void -panic(int32 unused) +runtime·dopanic(int32 unused) { - fd = 2; - if(panicking) { - printf("double panic\n"); - exit(3); + runtime·fd = 2; + if(runtime·panicking) { + runtime·printf("double panic\n"); + runtime·exit(3); } - panicking++; + runtime·panicking++; - printf("\npanic PC=%X\n", (uint64)(uintptr)&unused); - if(gotraceback()){ - traceback(·getcallerpc(&unused), getcallersp(&unused), 0, g); - tracebackothers(g); + runtime·printf("\npanic PC=%X\n", (uint64)(uintptr)&unused); + if(runtime·gotraceback()){ + runtime·traceback(runtime·getcallerpc(&unused), runtime·getcallersp(&unused), 0, g); + runtime·tracebackothers(g); } - breakpoint(); // so we can grab it in a debugger - exit(2); + runtime·breakpoint(); // so we can grab it in a debugger + runtime·exit(2); } void -·panicindex(void) +runtime·panicindex(void) { - panicstring("index out of range"); + runtime·panicstring("index out of range"); } void -·panicslice(void) +runtime·panicslice(void) { - panicstring("slice bounds out of range"); + runtime·panicstring("slice bounds out of range"); } void -·throwreturn(void) +runtime·throwreturn(void) { // can only happen if compiler is broken - throw("no return at end of a typed function - compiler is broken"); + runtime·throw("no return at end of a typed function - compiler is broken"); } void -·throwinit(void) +runtime·throwinit(void) { // can only happen with linker skew - throw("recursive call during initialization - linker skew"); + runtime·throw("recursive call during initialization - linker skew"); } void -throw(int8 *s) +runtime·throw(int8 *s) { - fd = 2; - printf("throw: %s\n", s); - panic(-1); + runtime·fd = 2; + runtime·printf("throw: %s\n", s); + runtime·dopanic(0); *(int32*)0 = 0; // not reached - exit(1); // even more not reached + runtime·exit(1); // even more not reached } void -panicstring(int8 *s) +runtime·panicstring(int8 *s) { Eface err; - ·newErrorString(gostringnocopy((byte*)s), &err); - ·panic(err); + runtime·newErrorString(runtime·gostringnocopy((byte*)s), &err); + runtime·panic(err); } void -mcpy(byte *t, byte *f, uint32 n) +runtime·mcpy(byte *t, byte *f, uint32 n) { while(n > 0) { *t = *f; @@ -95,7 +98,7 @@ mcpy(byte *t, byte *f, uint32 n) } int32 -mcmp(byte *s1, byte *s2, uint32 n) +runtime·mcmp(byte *s1, byte *s2, uint32 n) { uint32 i; byte c1, c2; @@ -113,7 +116,7 @@ mcmp(byte *s1, byte *s2, uint32 n) byte* -mchr(byte *p, byte c, byte *ep) +runtime·mchr(byte *p, byte c, byte *ep) { for(; p < ep; p++) if(*p == c) @@ -122,7 +125,7 @@ mchr(byte *p, byte c, byte *ep) } uint32 -rnd(uint32 n, uint32 m) +runtime·rnd(uint32 n, uint32 m) { uint32 r; @@ -141,38 +144,38 @@ Slice os·Args; Slice os·Envs; void -args(int32 c, uint8 **v) +runtime·args(int32 c, uint8 **v) { argc = c; argv = v; } -int32 isplan9; +int32 runtime·isplan9; void -goargs(void) +runtime·goargs(void) { String *gargv; String *genvv; int32 i, envc; - if(isplan9) + if(runtime·isplan9) envc=0; else for(envc=0; argv[argc+1+envc] != 0; envc++) ; - gargv = malloc(argc*sizeof gargv[0]); - genvv = malloc(envc*sizeof genvv[0]); + gargv = runtime·malloc(argc*sizeof gargv[0]); + genvv = runtime·malloc(envc*sizeof genvv[0]); for(i=0; i<argc; i++) - gargv[i] = gostringnocopy(argv[i]); + gargv[i] = runtime·gostringnocopy(argv[i]); os·Args.array = (byte*)gargv; os·Args.len = argc; os·Args.cap = argc; for(i=0; i<envc; i++) - genvv[i] = gostringnocopy(argv[argc+1+i]); + genvv[i] = runtime·gostringnocopy(argv[argc+1+i]); os·Envs.array = (byte*)genvv; os·Envs.len = envc; os·Envs.cap = envc; @@ -180,20 +183,20 @@ goargs(void) // Atomic add and return new value. uint32 -xadd(uint32 volatile *val, int32 delta) +runtime·xadd(uint32 volatile *val, int32 delta) { uint32 oval, nval; for(;;){ oval = *val; nval = oval + delta; - if(cas(val, oval, nval)) + if(runtime·cas(val, oval, nval)) return nval; } } byte* -getenv(int8 *s) +runtime·getenv(int8 *s) { int32 i, j, len; byte *v, *bs; @@ -201,7 +204,7 @@ getenv(int8 *s) int32 envc; bs = (byte*)s; - len = findnull(bs); + len = runtime·findnull(bs); envv = (String*)os·Envs.array; envc = os·Envs.len; for(i=0; i<envc; i++){ @@ -220,17 +223,17 @@ getenv(int8 *s) } void -·getgoroot(String out) +runtime·getgoroot(String out) { byte *p; - p = getenv("GOROOT"); - out = gostringnocopy(p); + p = runtime·getenv("GOROOT"); + out = runtime·gostringnocopy(p); FLUSH(&out); } int32 -atoi(byte *p) +runtime·atoi(byte *p) { int32 n; @@ -241,7 +244,7 @@ atoi(byte *p) } void -check(void) +runtime·check(void) { int8 a; uint8 b; @@ -256,34 +259,34 @@ check(void) void* k; uint16* l; - if(sizeof(a) != 1) throw("bad a"); - if(sizeof(b) != 1) throw("bad b"); - if(sizeof(c) != 2) throw("bad c"); - if(sizeof(d) != 2) throw("bad d"); - if(sizeof(e) != 4) throw("bad e"); - if(sizeof(f) != 4) throw("bad f"); - if(sizeof(g) != 8) throw("bad g"); - if(sizeof(h) != 8) throw("bad h"); - if(sizeof(i) != 4) throw("bad i"); - if(sizeof(j) != 8) throw("bad j"); - if(sizeof(k) != sizeof(uintptr)) throw("bad k"); - if(sizeof(l) != sizeof(uintptr)) throw("bad l"); + if(sizeof(a) != 1) runtime·throw("bad a"); + if(sizeof(b) != 1) runtime·throw("bad b"); + if(sizeof(c) != 2) runtime·throw("bad c"); + if(sizeof(d) != 2) runtime·throw("bad d"); + if(sizeof(e) != 4) runtime·throw("bad e"); + if(sizeof(f) != 4) runtime·throw("bad f"); + if(sizeof(g) != 8) runtime·throw("bad g"); + if(sizeof(h) != 8) runtime·throw("bad h"); + if(sizeof(i) != 4) runtime·throw("bad i"); + if(sizeof(j) != 8) runtime·throw("bad j"); + if(sizeof(k) != sizeof(uintptr)) runtime·throw("bad k"); + if(sizeof(l) != sizeof(uintptr)) runtime·throw("bad l"); // prints(1"check ok\n"); uint32 z; z = 1; - if(!cas(&z, 1, 2)) - throw("cas1"); + if(!runtime·cas(&z, 1, 2)) + runtime·throw("cas1"); if(z != 2) - throw("cas2"); + runtime·throw("cas2"); z = 4; - if(cas(&z, 5, 6)) - throw("cas3"); + if(runtime·cas(&z, 5, 6)) + runtime·throw("cas3"); if(z != 4) - throw("cas4"); + runtime·throw("cas4"); - initsig(0); + runtime·initsig(0); } /* @@ -316,7 +319,6 @@ static uint32 memequal(uint32 s, void *a, void *b) { byte *ba, *bb, *aend; - uint32 i; ba = a; bb = b; @@ -350,7 +352,7 @@ memprint(uint32 s, void *a) v = *(uint64*)a; break; } - ·printint(v); + runtime·printint(v); } static void @@ -411,112 +413,105 @@ static void strprint(uint32 s, String *a) { USED(s); - ·printstring(*a); + runtime·printstring(*a); } static uintptr interhash(uint32 s, Iface *a) { USED(s); - return ifacehash(*a); + return runtime·ifacehash(*a); } static void interprint(uint32 s, Iface *a) { USED(s); - ·printiface(*a); + runtime·printiface(*a); } static uint32 interequal(uint32 s, Iface *a, Iface *b) { USED(s); - return ifaceeq(*a, *b); + return runtime·ifaceeq_c(*a, *b); } static uintptr nilinterhash(uint32 s, Eface *a) { USED(s); - return efacehash(*a); + return runtime·efacehash(*a); } static void nilinterprint(uint32 s, Eface *a) { USED(s); - ·printeface(*a); + runtime·printeface(*a); } static uint32 nilinterequal(uint32 s, Eface *a, Eface *b) { USED(s); - return efaceeq(*a, *b); + return runtime·efaceeq_c(*a, *b); } uintptr -nohash(uint32 s, void *a) +runtime·nohash(uint32 s, void *a) { USED(s); USED(a); - panicstring("hash of unhashable type"); + runtime·panicstring("hash of unhashable type"); return 0; } uint32 -noequal(uint32 s, void *a, void *b) +runtime·noequal(uint32 s, void *a, void *b) { USED(s); USED(a); USED(b); - panicstring("comparing uncomparable types"); + runtime·panicstring("comparing uncomparable types"); return 0; } Alg -algarray[] = +runtime·algarray[] = { [AMEM] { memhash, memequal, memprint, memcopy }, -[ANOEQ] { nohash, noequal, memprint, memcopy }, +[ANOEQ] { runtime·nohash, runtime·noequal, memprint, memcopy }, [ASTRING] { strhash, strequal, strprint, memcopy }, [AINTER] { interhash, interequal, interprint, memcopy }, [ANILINTER] { nilinterhash, nilinterequal, nilinterprint, memcopy }, [AMEMWORD] { memhash, memwordequal, memprint, memwordcopy }, }; -#pragma textflag 7 -void -FLUSH(void *v) -{ - USED(v); -} - int64 -nanotime(void) +runtime·nanotime(void) { int64 sec; int32 usec; sec = 0; usec = 0; - gettime(&sec, &usec); + runtime·gettime(&sec, &usec); return sec*1000000000 + (int64)usec*1000; } void -·Caller(int32 skip, uintptr retpc, String retfile, int32 retline, bool retbool) +runtime·Caller(int32 skip, uintptr retpc, String retfile, int32 retline, bool retbool) { Func *f; - if(callers(1+skip, &retpc, 1) == 0 || (f = findfunc(retpc-1)) == nil) { - retfile = emptystring; + if(runtime·callers(1+skip, &retpc, 1) == 0 || (f = runtime·findfunc(retpc-1)) == nil) { + retfile = runtime·emptystring; retline = 0; retbool = false; } else { retfile = f->src; - retline = funcline(f, retpc-1); + retline = runtime·funcline(f, retpc-1); retbool = true; } FLUSH(&retfile); @@ -525,15 +520,15 @@ void } void -·Callers(int32 skip, Slice pc, int32 retn) +runtime·Callers(int32 skip, Slice pc, int32 retn) { - retn = callers(skip, (uintptr*)pc.array, pc.len); + retn = runtime·callers(skip, (uintptr*)pc.array, pc.len); FLUSH(&retn); } void -·FuncForPC(uintptr pc, void *retf) +runtime·FuncForPC(uintptr pc, void *retf) { - retf = findfunc(pc); + retf = runtime·findfunc(pc); FLUSH(&retf); } |
