int32 runtime·postnote(int32 pid, int8* msg) { int32 fd, len; uint8 buf[128]; uint8 tmp[16]; uint8 *p, *q; runtime·memclr(buf, sizeof buf); /* build path string /proc/pid/note */ q = tmp; p = buf; runtime·itoa(pid, tmp, sizeof tmp); runtime·memmove((void*)p, (void*)"/proc/", 6); for(p += 6; *p++ = *q++; ); p--; runtime·memmove((void*)p, (void*)"/note", 5); fd = runtime·open((int8*)buf, OWRITE, 0); if(fd < 0) return -1; len = runtime·findnull((byte*)msg); if(runtime·write(fd, msg, len) != len) { runtime·close(fd); return -1; } runtime·close(fd); return 0; }
runtime·getenv(int8 *s) { int32 fd, n, r; intgo len; byte file[128]; byte *p; len = runtime·findnull((byte*)s); if(len > sizeof file-6) return nil; runtime·memclr(file, sizeof file); runtime·memmove((void*)file, (void*)"/env/", 5); runtime·memmove((void*)(file+5), (void*)s, len); fd = runtime·open((int8*)file, OREAD, 0); if(fd < 0) return nil; n = runtime·seek(fd, 0, 2); p = runtime·malloc(n+1); r = runtime·pread(fd, p, n, 0); runtime·close(fd); if(r < 0) return nil; return p; }
runtime·getenv(int8 *s) { int32 i, j; intgo len; byte *v, *bs; String* envv; int32 envc; bs = (byte*)s; len = runtime·findnull(bs); envv = (String*)syscall·envs.array; envc = syscall·envs.len; for(i=0; i<envc; i++) { if(envv[i].len <= len) continue; v = envv[i].str; for(j=0; j<len; j++) if(bs[j] != v[j]) goto nomatch; if(v[len] != '=') goto nomatch; return v+len+1; nomatch: ; } return nil; }
static int32 getproccount(void) { int32 fd, rd, cnt, cpustrlen; byte *cpustr, *pos, *bufpos; byte buf[256]; fd = runtime·open((byte*)"/proc/stat", O_RDONLY|O_CLOEXEC, 0); if(fd == -1) return 1; cnt = 0; bufpos = buf; cpustr = (byte*)"\ncpu"; cpustrlen = runtime·findnull(cpustr); for(;;) { rd = runtime·read(fd, bufpos, sizeof(buf)-cpustrlen); if(rd == -1) break; bufpos[rd] = 0; for(pos=buf; pos=runtime·strstr(pos, cpustr); cnt++, pos++) { } if(rd < cpustrlen) break; runtime·memmove(buf, bufpos+rd-cpustrlen+1, cpustrlen-1); bufpos = buf+cpustrlen-1; } runtime·close(fd); return cnt ? cnt : 1; }
// put together the path name for a z entry. // the f entries have been accumulated into fname already. static void makepath(byte *buf, int32 nbuf, byte *path) { int32 n, len; byte *p, *ep, *q; if(nbuf <= 0) return; p = buf; ep = buf + nbuf; *p = '\0'; for(;;) { if(path[0] == 0 && path[1] == 0) break; n = (path[0]<<8) | path[1]; path += 2; if(n >= nfname) break; q = fname[n]; len = runtime·findnull(q); if(p+1+len >= ep) break; if(p > buf && p[-1] != '/') *p++ = '/'; runtime·memmove(p, q, len+1); p += len; } }
String runtime·gostringnocopy ( byte *str ) { String s; #line 100 "/home/pi/go_build/go/src/pkg/runtime/string.goc" s.str = str; s.len = runtime·findnull ( str ) ; return s; }
String runtime·gostringnocopy ( byte *str ) { String s; #line 3415 "C:\Go\src\pkg\runtime\string.goc" s.str = str; s.len = runtime·findnull ( str ) ; return s; }
String runtime·gostringnocopy ( byte *str ) { String s; #line 99 "/home/14/ren/source/golang/go/src/pkg/runtime/string.goc" s.str = str; s.len = runtime·findnull ( str ) ; return s; }
String runtime·gostring ( byte *str ) { intgo l; String s; #line 65 "/home/14/ren/source/golang/go/src/pkg/runtime/string.goc" l = runtime·findnull ( str ) ; s = gostringsize ( l ) ; runtime·memmove ( s.str , str , l ) ; return s; }
String runtime·gostring ( byte *str ) { intgo l; String s; #line 67 "/home/pi/go_build/go/src/pkg/runtime/string.goc" l = runtime·findnull ( str ) ; s = gostringsize ( l ) ; runtime·memmove ( s.str , str , l ) ; return s; }
String runtime·gostring ( byte *str ) { int32 l; String s; #line 3382 "C:\Go\src\pkg\runtime\string.goc" l = runtime·findnull ( str ) ; s = gostringsize ( l ) ; runtime·memmove ( s.str , str , l ) ; return s; }
void runtime·gonote(void*, byte *s) { uint8 buf[128]; int32 l; l = runtime·findnull(s); if(l > 4 && runtime·mcmp(s, (byte*)"sys:", 4) == 0) { runtime·memclr(buf, sizeof buf); runtime·memmove((void*)buf, (void*)s, runtime·findnull(s)); runtime·exitstatus = (int8*)buf; goexitsall(); runtime·noted(NDFLT); } if(runtime·exitstatus) runtime·exits(runtime·exitstatus); if(runtime·strcmp(s, (byte*)"gointr") == 0) runtime·noted(NCONT); runtime·noted(NDFLT); }
void runtime·badsignal(int32 sig) { if (sig == SIGPROF) { return; // Ignore SIGPROFs intended for a non-Go thread. } runtime·write(2, badsignal, sizeof badsignal - 1); if (0 <= sig && sig < NSIG) { // Call runtime·findnull dynamically to circumvent static stack size check. static int32 (*findnull)(byte*) = runtime·findnull; runtime·write(2, runtime·sigtab[sig].name, findnull((byte*)runtime·sigtab[sig].name)); } runtime·write(2, "\n", 1); runtime·exit(1); }
int32 runtime·sighandler(void *v, int8 *note, G *gp) { uintptr *sp; SigTab *t; bool crash; Ureg *ureg; intgo len, n; int32 sig, flags; ureg = (Ureg*)v; // The kernel will never pass us a nil note or ureg so we probably // made a mistake somewhere in runtime·sigtramp. if(ureg == nil || note == nil) { runtime·printf("sighandler: ureg %p note %p\n", ureg, note); goto Throw; } // Check that the note is no more than ERRMAX bytes (including // the trailing NUL). We should never receive a longer note. len = runtime·findnull((byte*)note); if(len > ERRMAX-1) { runtime·printf("sighandler: note is longer than ERRMAX\n"); goto Throw; } // See if the note matches one of the patterns in runtime·sigtab. // Notes that do not match any pattern can be handled at a higher // level by the program but will otherwise be ignored. flags = SigNotify; for(sig = 0; sig < nelem(runtime·sigtab); sig++) { t = &runtime·sigtab[sig]; n = runtime·findnull((byte*)t->name); if(len < n) continue; if(runtime·strncmp((byte*)note, (byte*)t->name, n) == 0) { flags = t->flags; break; } } if(flags & SigGoExit) runtime·exits(note+9); // Strip "go: exit " prefix. if(flags & SigPanic) { // Copy the error string from sigtramp's stack into m->notesig so // we can reliably access it from the panic routines. runtime·memmove(g->m->notesig, note, len+1); gp->sig = sig; gp->sigpc = ureg->ip; // Only push runtime·sigpanic if PC != 0. // // If PC == 0, probably panicked because of a call to a nil func. // Not pushing that onto SP will make the trace look like a call // to runtime·sigpanic instead. (Otherwise the trace will end at // runtime·sigpanic and we won't get to see who faulted). if(ureg->ip != 0) { sp = (uintptr*)ureg->sp; *--sp = ureg->ip; ureg->sp = (uint64)sp; } ureg->ip = (uintptr)runtime·sigpanic; return NCONT; } if(flags & SigNotify) { // TODO(ality): See if os/signal wants it. //if(runtime·sigsend(...)) // return NCONT; } if(flags & SigKill) goto Exit; if(!(flags & SigThrow)) return NCONT; Throw: g->m->throwing = 1; g->m->caughtsig = gp; runtime·startpanic(); runtime·printf("%s\n", note); runtime·printf("PC=%X\n", ureg->ip); runtime·printf("\n"); if(runtime·gotraceback(&crash)) { runtime·goroutineheader(gp); runtime·traceback(ureg->ip, ureg->sp, 0, gp); runtime·tracebackothers(gp); runtime·printf("\n"); runtime·dumpregs(ureg); } if(crash) runtime·crash(); Exit: runtime·goexitsall(note); runtime·exits(note); return NDFLT; // not reached }
void runtime·prints(int8 *s) { runtime·write(2, s, runtime·findnull((byte*)s)); }
int32 runtime·sighandler(void *v, int8 *s, G *gp) { bool crash; Ureg *ureg; uintptr *sp; SigTab *sig, *nsig; intgo len, i; if(!s) return NCONT; len = runtime·findnull((byte*)s); if(len <= 4 || runtime·mcmp((byte*)s, (byte*)"sys:", 4) != 0) return NDFLT; nsig = nil; sig = runtime·sigtab; for(i=0; i < NSIG; i++) { if(runtime·strstr((byte*)s, (byte*)sig->name)) { nsig = sig; break; } sig++; } if(nsig == nil) return NDFLT; ureg = v; if(nsig->flags & SigPanic) { if(gp == nil || m->notesig == 0) goto Throw; // Copy the error string from sigtramp's stack into m->notesig so // we can reliably access it from the panic routines. We can't use // runtime·memmove here since it will use SSE instructions for big // copies. The Plan 9 kernel doesn't allow floating point in note // handlers. // // TODO(ality): revert back to memmove when the kernel is fixed. if(len >= ERRMAX) len = ERRMAX-1; for(i = 0; i < len; i++) m->notesig[i] = s[i]; m->notesig[i] = '\0'; gp->sig = i; gp->sigpc = ureg->pc; // Only push runtime·sigpanic if ureg->pc != 0. // If ureg->pc == 0, probably panicked because of a // call to a nil func. Not pushing that onto sp will // make the trace look like a call to runtime·sigpanic instead. // (Otherwise the trace will end at runtime·sigpanic and we // won't get to see who faulted.) if(ureg->pc != 0) { sp = (uintptr*)ureg->sp; *--sp = ureg->pc; ureg->sp = (uint32)sp; } ureg->pc = (uintptr)runtime·sigpanic; return NCONT; } if(!(nsig->flags & SigThrow)) return NDFLT; Throw: m->throwing = 1; m->caughtsig = gp; runtime·startpanic(); runtime·printf("%s\n", s); runtime·printf("PC=%X\n", ureg->pc); runtime·printf("\n"); if(runtime·gotraceback(&crash)) { runtime·traceback(ureg->pc, ureg->sp, 0, gp); runtime·tracebackothers(gp); runtime·dumpregs(ureg); } if(crash) runtime·crash(); runtime·goexitsall(""); runtime·exits(s); return 0; }
void runtime·prints(int8 *s) { gwrite(s, runtime·findnull((byte*)s)); }
int32 runtime·sighandler(void *v, int8 *s, G *gp) { Ureg *ureg; uintptr *sp; SigTab *sig, *nsig; int32 len, i; if(!s) return NCONT; len = runtime·findnull((byte*)s); if(len <= 4 || runtime·mcmp((byte*)s, (byte*)"sys:", 4) != 0) return NDFLT; nsig = nil; sig = runtime·sigtab; for(i=0; i < NSIG; i++) { if(runtime·strstr((byte*)s, (byte*)sig->name)) { nsig = sig; break; } sig++; } if(nsig == nil) return NDFLT; ureg = v; if(nsig->flags & SigPanic) { if(gp == nil || m->notesig == 0) goto Throw; // Save error string from sigtramp's stack, // into gsignal->sigcode0, so we can reliably // access it from the panic routines. if(len > ERRMAX) len = ERRMAX; runtime·memmove((void*)m->notesig, (void*)s, len); gp->sig = i; gp->sigpc = ureg->pc; // Only push runtime·sigpanic if ureg->pc != 0. // If ureg->pc == 0, probably panicked because of a // call to a nil func. Not pushing that onto sp will // make the trace look like a call to runtime·sigpanic instead. // (Otherwise the trace will end at runtime·sigpanic and we // won't get to see who faulted.) if(ureg->pc != 0) { sp = (uintptr*)ureg->sp; *--sp = ureg->pc; ureg->sp = (uint32)sp; } ureg->pc = (uintptr)runtime·sigpanic; return NCONT; } if(!(nsig->flags & SigThrow)) return NDFLT; Throw: runtime·startpanic(); runtime·printf("%s\n", s); runtime·printf("PC=%X\n", ureg->pc); runtime·printf("\n"); if(runtime·gotraceback()) { runtime·traceback((void*)ureg->pc, (void*)ureg->sp, 0, gp); runtime·tracebackothers(gp); runtime·dumpregs(ureg); } runtime·goexitsall(""); runtime·exits(s); return 0; }
void prints(int8 *s) { write(fd, s, findnull((byte*)s)); }