2010-01-06 18:58:55 -07:00
|
|
|
// 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.
|
|
|
|
|
2010-06-29 08:12:14 -06:00
|
|
|
#include "runtime.h"
|
2011-01-19 13:10:15 -07:00
|
|
|
#include "defs.h"
|
|
|
|
#include "os.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
runtime·dumpregs(Context *r)
|
|
|
|
{
|
|
|
|
runtime·printf("eax %x\n", r->Eax);
|
|
|
|
runtime·printf("ebx %x\n", r->Ebx);
|
|
|
|
runtime·printf("ecx %x\n", r->Ecx);
|
|
|
|
runtime·printf("edx %x\n", r->Edx);
|
|
|
|
runtime·printf("edi %x\n", r->Edi);
|
|
|
|
runtime·printf("esi %x\n", r->Esi);
|
|
|
|
runtime·printf("ebp %x\n", r->Ebp);
|
|
|
|
runtime·printf("esp %x\n", r->Esp);
|
|
|
|
runtime·printf("eip %x\n", r->Eip);
|
|
|
|
runtime·printf("eflags %x\n", r->EFlags);
|
|
|
|
runtime·printf("cs %x\n", r->SegCs);
|
|
|
|
runtime·printf("fs %x\n", r->SegFs);
|
|
|
|
runtime·printf("gs %x\n", r->SegGs);
|
|
|
|
}
|
2010-06-29 08:12:14 -06:00
|
|
|
|
2010-01-06 18:58:55 -07:00
|
|
|
void
|
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
2010-11-04 12:00:19 -06:00
|
|
|
runtime·initsig(int32)
|
2010-01-06 18:58:55 -07:00
|
|
|
{
|
2011-02-14 10:15:13 -07:00
|
|
|
runtime·siginit();
|
2010-10-21 11:06:17 -06:00
|
|
|
}
|
|
|
|
|
2011-01-19 13:10:15 -07:00
|
|
|
uint32
|
|
|
|
runtime·sighandler(ExceptionRecord *info, void *frame, Context *r)
|
|
|
|
{
|
|
|
|
uintptr *sp;
|
|
|
|
G *gp;
|
|
|
|
|
|
|
|
USED(frame);
|
|
|
|
|
|
|
|
switch(info->ExceptionCode) {
|
|
|
|
case EXCEPTION_BREAKPOINT:
|
|
|
|
r->Eip--; // because 8l generates 2 bytes for INT3
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((gp = m->curg) != nil && runtime·issigpanic(info->ExceptionCode)) {
|
|
|
|
// Make it look like a call to the signal func.
|
|
|
|
// Have to pass arguments out of band since
|
|
|
|
// augmenting the stack frame would break
|
|
|
|
// the unwinding code.
|
|
|
|
gp->sig = info->ExceptionCode;
|
|
|
|
gp->sigcode0 = info->ExceptionInformation[0];
|
|
|
|
gp->sigcode1 = info->ExceptionInformation[1];
|
2011-02-01 09:49:24 -07:00
|
|
|
gp->sigpc = r->Eip;
|
2011-01-19 13:10:15 -07:00
|
|
|
|
|
|
|
// Only push runtime·sigpanic if r->eip != 0.
|
|
|
|
// If r->eip == 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(r->Eip != 0) {
|
|
|
|
sp = (uintptr*)r->Esp;
|
|
|
|
*--sp = r->Eip;
|
|
|
|
r->Esp = (uintptr)sp;
|
|
|
|
}
|
|
|
|
r->Eip = (uintptr)runtime·sigpanic;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(runtime·panicking) // traceback already printed
|
|
|
|
runtime·exit(2);
|
|
|
|
runtime·panicking = 1;
|
|
|
|
|
|
|
|
runtime·printf("Exception %x %p %p\n", info->ExceptionCode,
|
|
|
|
info->ExceptionInformation[0], info->ExceptionInformation[1]);
|
|
|
|
|
|
|
|
runtime·printf("PC=%x\n", r->Eip);
|
|
|
|
runtime·printf("\n");
|
|
|
|
|
|
|
|
if(runtime·gotraceback()){
|
|
|
|
runtime·traceback((void*)r->Eip, (void*)r->Esp, 0, m->curg);
|
|
|
|
runtime·tracebackothers(m->curg);
|
|
|
|
runtime·dumpregs(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
runtime·exit(2);
|
|
|
|
return 0;
|
|
|
|
}
|
2011-03-23 09:43:37 -06:00
|
|
|
|
|
|
|
void
|
2011-09-17 01:57:59 -06:00
|
|
|
runtime·dosigprof(Context *r, G *gp)
|
2011-03-23 09:43:37 -06:00
|
|
|
{
|
2011-09-17 01:57:59 -06:00
|
|
|
runtime·sigprof((uint8*)r->Eip, (uint8*)r->Esp, nil, gp);
|
2011-03-23 09:43:37 -06:00
|
|
|
}
|