aboutsummaryrefslogtreecommitdiff
path: root/libgo/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/runtime')
-rw-r--r--libgo/runtime/mprof.goc12
-rw-r--r--libgo/runtime/panic.c9
-rw-r--r--libgo/runtime/print.c301
-rw-r--r--libgo/runtime/proc.c5
-rw-r--r--libgo/runtime/runtime.h29
5 files changed, 82 insertions, 274 deletions
diff --git a/libgo/runtime/mprof.goc b/libgo/runtime/mprof.goc
index bb3f9e8..be2c17e 100644
--- a/libgo/runtime/mprof.goc
+++ b/libgo/runtime/mprof.goc
@@ -419,17 +419,19 @@ func Stack(b Slice, all bool) (n int) {
n = 0;
else{
G* g = runtime_g();
- g->writebuf = (byte*)b.__values;
- g->writenbuf = b.__count;
+ g->writebuf.__values = b.__values;
+ g->writebuf.__count = 0;
+ g->writebuf.__capacity = b.__count;
USED(pc);
runtime_goroutineheader(g);
runtime_traceback();
runtime_printcreatedby(g);
if(all)
runtime_tracebackothers(g);
- n = b.__count - g->writenbuf;
- g->writebuf = nil;
- g->writenbuf = 0;
+ n = g->writebuf.__count;
+ g->writebuf.__values = nil;
+ g->writebuf.__count = 0;
+ g->writebuf.__capacity = 0;
}
if(all) {
diff --git a/libgo/runtime/panic.c b/libgo/runtime/panic.c
index d493b54..cd1ae96 100644
--- a/libgo/runtime/panic.c
+++ b/libgo/runtime/panic.c
@@ -72,9 +72,11 @@ __go_rundefer(void)
void
runtime_startpanic(void)
{
+ G *g;
M *m;
- m = runtime_m();
+ g = runtime_g();
+ m = g->m;
if(runtime_mheap.cachealloc.size == 0) { // very early
runtime_printf("runtime: panic before malloc heap initialized\n");
m->mallocing = 1; // tell rest of panic not to try to malloc
@@ -83,8 +85,9 @@ runtime_startpanic(void)
switch(m->dying) {
case 0:
m->dying = 1;
- if(runtime_g() != nil)
- runtime_g()->writebuf = nil;
+ g->writebuf.__values = nil;
+ g->writebuf.__count = 0;
+ g->writebuf.__capacity = 0;
runtime_xadd(&runtime_panicking, 1);
runtime_lock(&paniclk);
if(runtime_debug.schedtrace > 0 || runtime_debug.scheddetail > 0)
diff --git a/libgo/runtime/print.c b/libgo/runtime/print.c
index 69b1f81..4da8796 100644
--- a/libgo/runtime/print.c
+++ b/libgo/runtime/print.c
@@ -9,58 +9,60 @@
#include "array.h"
#include "go-type.h"
-//static Lock debuglock;
+extern void runtime_printlock(void)
+ __asm__(GOSYM_PREFIX "runtime.printlock");
+extern void runtime_printunlock(void)
+ __asm__(GOSYM_PREFIX "runtime.printunlock");
+extern void gwrite(Slice)
+ __asm__(GOSYM_PREFIX "runtime.gwrite");
+extern void runtime_printint(int64)
+ __asm__(GOSYM_PREFIX "runtime.printint");
+extern void runtime_printuint(uint64)
+ __asm__(GOSYM_PREFIX "runtime.printuint");
+extern void runtime_printhex(uint64)
+ __asm__(GOSYM_PREFIX "runtime.printhex");
+extern void runtime_printfloat(float64)
+ __asm__(GOSYM_PREFIX "runtime.printfloat");
+extern void runtime_printcomplex(complex double)
+ __asm__(GOSYM_PREFIX "runtime.printcomplex");
+extern void runtime_printbool(_Bool)
+ __asm__(GOSYM_PREFIX "runtime.printbool");
+extern void runtime_printstring(String)
+ __asm__(GOSYM_PREFIX "runtime.printstring");
+extern void runtime_printpointer(void *)
+ __asm__(GOSYM_PREFIX "runtime.printpointer");
+extern void runtime_printslice(Slice)
+ __asm__(GOSYM_PREFIX "runtime.printslice");
+extern void runtime_printeface(Eface)
+ __asm__(GOSYM_PREFIX "runtime.printeface");
+extern void runtime_printiface(Iface)
+ __asm__(GOSYM_PREFIX "runtime.printiface");
// Clang requires this function to not be inlined (see below).
static void go_vprintf(const char*, va_list)
__attribute__((noinline));
-// write to goroutine-local buffer if diverting output,
-// or else standard error.
static void
-gwrite(const void *v, intgo n)
+runtime_prints(const char *s)
{
- G* g = runtime_g();
-
- if(g == nil || g->writebuf == nil) {
- // Avoid -D_FORTIFY_SOURCE problems.
- int rv __attribute__((unused));
-
- rv = runtime_write(2, v, n);
- return;
- }
-
- if(g->writenbuf == 0)
- return;
+ Slice sl;
- if(n > g->writenbuf)
- n = g->writenbuf;
- runtime_memmove(g->writebuf, v, n);
- g->writebuf += n;
- g->writenbuf -= n;
+ // Use memcpy to avoid const-cast warning.
+ memcpy(&sl.__values, &s, sizeof(char*));
+ sl.__count = runtime_findnull((const byte*)s);
+ sl.__capacity = sl.__count;
+ gwrite(sl);
}
-void
-runtime_dump(byte *p, int32 n)
+static void
+runtime_printbyte(int8 c)
{
- int32 i;
-
- for(i=0; i<n; i++) {
- runtime_printpointer((byte*)(uintptr)(p[i]>>4));
- runtime_printpointer((byte*)(uintptr)(p[i]&0xf));
- if((i&15) == 15)
- runtime_prints("\n");
- else
- runtime_prints(" ");
- }
- if(n & 15)
- runtime_prints("\n");
-}
+ Slice sl;
-void
-runtime_prints(const char *s)
-{
- gwrite(s, runtime_findnull((const byte*)s));
+ sl.__values = &c;
+ sl.__count = 1;
+ sl.__capacity = 1;
+ gwrite(sl);
}
#if defined (__clang__) && (defined (__i386__) || defined (__x86_64__))
@@ -104,15 +106,17 @@ runtime_snprintf(byte *buf, int32 n, const char *s, ...)
va_list va;
int32 m;
- g->writebuf = buf;
- g->writenbuf = n-1;
+ g->writebuf.__values = buf;
+ g->writebuf.__count = 0;
+ g->writebuf.__capacity = n-1;
va_start(va, s);
go_vprintf(s, va);
va_end(va);
- *g->writebuf = '\0';
- m = g->writebuf - buf;
- g->writenbuf = 0;
- g->writebuf = nil;
+ m = g->writebuf.__count;
+ ((byte*)g->writebuf.__values)[m] = '\0';
+ g->writebuf.__values = nil;
+ g->writebuf.__count = 0;
+ g->writebuf.__capacity = 0;
return m;
}
@@ -122,15 +126,21 @@ static void
go_vprintf(const char *s, va_list va)
{
const char *p, *lp;
+ Slice sl;
- //runtime_lock(&debuglock);
+ runtime_printlock();
lp = p = s;
for(; *p; p++) {
if(*p != '%')
continue;
- if(p > lp)
- gwrite(lp, p-lp);
+ if(p > lp) {
+ // Use memcpy to avoid const-cast warning.
+ memcpy(&sl.__values, &lp, sizeof(char*));
+ sl.__count = p - lp;
+ sl.__capacity = p - lp;
+ gwrite(sl);
+ }
p++;
switch(*p) {
case 'a':
@@ -181,192 +191,13 @@ go_vprintf(const char *s, va_list va)
}
lp = p+1;
}
- if(p > lp)
- gwrite(lp, p-lp);
-
- //runtime_unlock(&debuglock);
-}
-
-void
-runtime_printpc(void *p __attribute__ ((unused)))
-{
- runtime_prints("PC=");
- runtime_printhex((uint64)(uintptr)runtime_getcallerpc(p));
-}
-
-void
-runtime_printbool(_Bool v)
-{
- if(v) {
- gwrite("true", 4);
- return;
- }
- gwrite("false", 5);
-}
-
-void
-runtime_printbyte(int8 c)
-{
- gwrite(&c, 1);
-}
-
-void
-runtime_printfloat(double v)
-{
- byte buf[20];
- int32 e, s, i, n;
- float64 h;
-
- if(ISNAN(v)) {
- gwrite("NaN", 3);
- return;
- }
- if(isinf(v)) {
- if(signbit(v)) {
- gwrite("-Inf", 4);
- } else {
- gwrite("+Inf", 4);
- }
- return;
+ if(p > lp) {
+ // Use memcpy to avoid const-cast warning.
+ memcpy(&sl.__values, &lp, sizeof(char*));
+ sl.__count = p - lp;
+ sl.__capacity = p - lp;
+ gwrite(sl);
}
- n = 7; // digits printed
- e = 0; // exp
- s = 0; // sign
- if(v == 0) {
- if(isinf(1/v) && 1/v < 0)
- s = 1;
- } else {
- // sign
- if(v < 0) {
- v = -v;
- s = 1;
- }
-
- // normalize
- while(v >= 10) {
- e++;
- v /= 10;
- }
- while(v < 1) {
- e--;
- v *= 10;
- }
-
- // round
- h = 5;
- for(i=0; i<n; i++)
- h /= 10;
-
- v += h;
- if(v >= 10) {
- e++;
- v /= 10;
- }
- }
-
- // format +d.dddd+edd
- buf[0] = '+';
- if(s)
- buf[0] = '-';
- for(i=0; i<n; i++) {
- s = v;
- buf[i+2] = s+'0';
- v -= s;
- v *= 10.;
- }
- buf[1] = buf[2];
- buf[2] = '.';
-
- buf[n+2] = 'e';
- buf[n+3] = '+';
- if(e < 0) {
- e = -e;
- buf[n+3] = '-';
- }
-
- buf[n+4] = (e/100) + '0';
- buf[n+5] = (e/10)%10 + '0';
- buf[n+6] = (e%10) + '0';
- gwrite(buf, n+7);
-}
-
-void
-runtime_printcomplex(complex double v)
-{
- gwrite("(", 1);
- runtime_printfloat(creal(v));
- runtime_printfloat(cimag(v));
- gwrite("i)", 2);
-}
-
-void
-runtime_printuint(uint64 v)
-{
- byte buf[100];
- int32 i;
-
- for(i=nelem(buf)-1; i>0; i--) {
- buf[i] = v%10 + '0';
- if(v < 10)
- break;
- v = v/10;
- }
- gwrite(buf+i, nelem(buf)-i);
-}
-
-void
-runtime_printint(int64 v)
-{
- if(v < 0) {
- gwrite("-", 1);
- v = -v;
- }
- runtime_printuint(v);
-}
-
-void
-runtime_printhex(uint64 v)
-{
- static const char *dig = "0123456789abcdef";
- byte buf[100];
- int32 i;
-
- i=nelem(buf);
- for(; v>0; v/=16)
- buf[--i] = dig[v%16];
- if(i == nelem(buf))
- buf[--i] = '0';
- buf[--i] = 'x';
- buf[--i] = '0';
- gwrite(buf+i, nelem(buf)-i);
-}
-
-void
-runtime_printpointer(void *p)
-{
- runtime_printhex((uintptr)p);
-}
-
-void
-runtime_printstring(String v)
-{
- // if(v.len > runtime_maxstring) {
- // gwrite("[string too long]", 17);
- // return;
- // }
- if(v.len > 0)
- gwrite(v.str, v.len);
-}
-
-void
-__go_print_space(void)
-{
- gwrite(" ", 1);
-}
-
-void
-__go_print_nl(void)
-{
- gwrite("\n", 1);
+ runtime_printunlock();
}
diff --git a/libgo/runtime/proc.c b/libgo/runtime/proc.c
index 02b62be..98c18a7 100644
--- a/libgo/runtime/proc.c
+++ b/libgo/runtime/proc.c
@@ -2037,8 +2037,9 @@ goexit0(G *gp)
gp->paniconfault = 0;
gp->_defer = nil; // should be true already but just in case.
gp->_panic = nil; // non-nil for Goexit during panic. points at stack-allocated data.
- gp->writenbuf = 0;
- gp->writebuf = nil;
+ gp->writebuf.__values = nil;
+ gp->writebuf.__count = 0;
+ gp->writebuf.__capacity = 0;
gp->waitreason = runtime_gostringnocopy(nil);
gp->param = nil;
m->curg = nil;
diff --git a/libgo/runtime/runtime.h b/libgo/runtime/runtime.h
index 6f96b2b..3304215 100644
--- a/libgo/runtime/runtime.h
+++ b/libgo/runtime/runtime.h
@@ -309,7 +309,6 @@ extern bool runtime_isarchive;
#define runtime_strstr(s1, s2) __builtin_strstr((s1), (s2))
intgo runtime_findnull(const byte*);
intgo runtime_findnullw(const uint16*);
-void runtime_dump(byte*, int32);
void runtime_gogo(G*);
struct __go_func_type;
@@ -324,7 +323,6 @@ void runtime_goenvs_unix(void)
void runtime_throw(const char*) __attribute__ ((noreturn));
void runtime_panicstring(const char*) __attribute__ ((noreturn));
bool runtime_canpanic(G*);
-void runtime_prints(const char*);
void runtime_printf(const char*, ...);
int32 runtime_snprintf(byte*, int32, const char*, ...);
#define runtime_mcmp(a, b, s) __builtin_memcmp((a), (b), (s))
@@ -534,35 +532,8 @@ void __wrap_rtems_task_variable_add(void **);
#endif
/*
- * Names generated by gccgo.
- */
-#define runtime_printbool __go_print_bool
-#define runtime_printfloat __go_print_double
-#define runtime_printint __go_print_int64
-#define runtime_printiface __go_print_interface
-#define runtime_printeface __go_print_empty_interface
-#define runtime_printstring __go_print_string
-#define runtime_printpointer __go_print_pointer
-#define runtime_printuint __go_print_uint64
-#define runtime_printslice __go_print_slice
-#define runtime_printcomplex __go_print_complex
-
-/*
* runtime go-called
*/
-void runtime_printbool(_Bool);
-void runtime_printbyte(int8);
-void runtime_printfloat(double);
-void runtime_printint(int64);
-void runtime_printiface(Iface);
-void runtime_printeface(Eface);
-void runtime_printstring(String);
-void runtime_printpc(void*);
-void runtime_printpointer(void*);
-void runtime_printuint(uint64);
-void runtime_printhex(uint64);
-void runtime_printslice(Slice);
-void runtime_printcomplex(complex double);
void reflect_call(const struct __go_func_type *, FuncVal *, _Bool, _Bool,
void **, void **)
__asm__ (GOSYM_PREFIX "reflect.call");