mirror of
https://github.com/golang/go
synced 2024-11-19 21:54:40 -07:00
runtime: change PC, SP values in Stkframe, Panic, Defer from byte* to uintptr
uintptr is better when translating to Go, and in a few places it's better in C too. LGTM=r R=golang-codereviews, r CC=golang-codereviews, iant, khr https://golang.org/cl/138980043
This commit is contained in:
parent
f16729781b
commit
3de7ba1873
@ -309,7 +309,7 @@ dumpframe(Stkframe *s, void *arg)
|
||||
dumpbvtypes(&child->args, (byte*)s->sp + child->argoff);
|
||||
if(stackmap != nil && stackmap->n > 0) {
|
||||
bv = runtime·stackmapdata(stackmap, pcdata);
|
||||
dumpbvtypes(&bv, s->varp - bv.n / BitsPerPointer * PtrSize);
|
||||
dumpbvtypes(&bv, (byte*)(s->varp - bv.n / BitsPerPointer * PtrSize));
|
||||
} else {
|
||||
bv.n = -1;
|
||||
}
|
||||
@ -342,26 +342,26 @@ dumpframe(Stkframe *s, void *arg)
|
||||
// Dump fields in the local vars section
|
||||
if(stackmap == nil) {
|
||||
// No locals information, dump everything.
|
||||
for(off = child->arglen; off < s->varp - (byte*)s->sp; off += PtrSize) {
|
||||
for(off = child->arglen; off < s->varp - s->sp; off += PtrSize) {
|
||||
dumpint(FieldKindPtr);
|
||||
dumpint(off);
|
||||
}
|
||||
} else if(stackmap->n < 0) {
|
||||
// Locals size information, dump just the locals.
|
||||
size = -stackmap->n;
|
||||
for(off = s->varp - size - (byte*)s->sp; off < s->varp - (byte*)s->sp; off += PtrSize) {
|
||||
for(off = s->varp - size - s->sp; off < s->varp - s->sp; off += PtrSize) {
|
||||
dumpint(FieldKindPtr);
|
||||
dumpint(off);
|
||||
}
|
||||
} else if(stackmap->n > 0) {
|
||||
// Locals bitmap information, scan just the pointers in
|
||||
// locals.
|
||||
dumpbv(&bv, s->varp - bv.n / BitsPerPointer * PtrSize - (byte*)s->sp);
|
||||
dumpbv(&bv, s->varp - bv.n / BitsPerPointer * PtrSize - s->sp);
|
||||
}
|
||||
dumpint(FieldKindEol);
|
||||
|
||||
// Record arg info for parent.
|
||||
child->argoff = s->argp - (byte*)s->fp;
|
||||
child->argoff = s->argp - s->fp;
|
||||
child->arglen = s->arglen;
|
||||
child->sp = (byte*)s->sp;
|
||||
child->depth++;
|
||||
|
@ -674,16 +674,16 @@ scanframe(Stkframe *frame, void *unused)
|
||||
stackmap = runtime·funcdata(f, FUNCDATA_LocalsPointerMaps);
|
||||
if(stackmap == nil) {
|
||||
// No locals information, scan everything.
|
||||
size = frame->varp - (byte*)frame->sp;
|
||||
size = frame->varp - frame->sp;
|
||||
if(Debug > 2)
|
||||
runtime·printf("frame %s unsized locals %p+%p\n", runtime·funcname(f), frame->varp-size, size);
|
||||
scanblock(frame->varp - size, size, ScanConservatively);
|
||||
runtime·printf("frame %s unsized locals %p+%p\n", runtime·funcname(f), (byte*)(frame->varp-size), size);
|
||||
scanblock((byte*)(frame->varp - size), size, ScanConservatively);
|
||||
} else if(stackmap->n < 0) {
|
||||
// Locals size information, scan just the locals.
|
||||
size = -stackmap->n;
|
||||
if(Debug > 2)
|
||||
runtime·printf("frame %s conservative locals %p+%p\n", runtime·funcname(f), frame->varp-size, size);
|
||||
scanblock(frame->varp - size, size, ScanConservatively);
|
||||
runtime·printf("frame %s conservative locals %p+%p\n", runtime·funcname(f), (byte*)(frame->varp-size), size);
|
||||
scanblock((byte*)(frame->varp - size), size, ScanConservatively);
|
||||
} else if(stackmap->n > 0) {
|
||||
// Locals bitmap information, scan just the pointers in locals.
|
||||
if(pcdata < 0 || pcdata >= stackmap->n) {
|
||||
@ -694,7 +694,7 @@ scanframe(Stkframe *frame, void *unused)
|
||||
}
|
||||
bv = runtime·stackmapdata(stackmap, pcdata);
|
||||
size = (bv.n * PtrSize) / BitsPerPointer;
|
||||
scanblock(frame->varp - size, bv.n/BitsPerPointer*PtrSize, (byte*)bv.data);
|
||||
scanblock((byte*)(frame->varp - size), bv.n/BitsPerPointer*PtrSize, (byte*)bv.data);
|
||||
}
|
||||
|
||||
// Scan arguments.
|
||||
@ -702,11 +702,11 @@ scanframe(Stkframe *frame, void *unused)
|
||||
stackmap = runtime·funcdata(f, FUNCDATA_ArgsPointerMaps);
|
||||
if(stackmap != nil) {
|
||||
bv = runtime·stackmapdata(stackmap, pcdata);
|
||||
scanblock(frame->argp, bv.n/BitsPerPointer*PtrSize, (byte*)bv.data);
|
||||
scanblock((byte*)frame->argp, bv.n/BitsPerPointer*PtrSize, (byte*)bv.data);
|
||||
} else {
|
||||
if(Debug > 2)
|
||||
runtime·printf("frame %s conservative args %p+%p\n", runtime·funcname(f), frame->argp, (uintptr)frame->arglen);
|
||||
scanblock(frame->argp, frame->arglen, ScanConservatively);
|
||||
scanblock((byte*)frame->argp, frame->arglen, ScanConservatively);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -1798,7 +1798,7 @@ getgcmaskcb(Stkframe *frame, void *ctxt)
|
||||
Stkframe *frame0;
|
||||
|
||||
frame0 = ctxt;
|
||||
if(frame0->sp >= (uintptr)frame->varp - frame->sp && frame0->sp < (uintptr)frame->varp) {
|
||||
if(frame0->sp >= frame->varp - frame->sp && frame0->sp < frame->varp) {
|
||||
*frame0 = *frame;
|
||||
return false;
|
||||
}
|
||||
@ -1883,7 +1883,7 @@ runtime·getgcmask(byte *p, Type *t, byte **mask, uintptr *len)
|
||||
*len = n/PtrSize;
|
||||
*mask = runtime·mallocgc(*len, nil, 0);
|
||||
for(i = 0; i < n; i += PtrSize) {
|
||||
off = (p+i-frame.varp+size)/PtrSize;
|
||||
off = (p+i-(byte*)frame.varp+size)/PtrSize;
|
||||
bits = (bv.data[off*BitsPerPointer/32] >> ((off*BitsPerPointer)%32))&BitsMask;
|
||||
(*mask)[i/PtrSize] = bits;
|
||||
}
|
||||
|
@ -85,12 +85,12 @@ runtime·deferproc(int32 siz, FuncVal *fn, ...)
|
||||
|
||||
d = newdefer(siz);
|
||||
d->fn = fn;
|
||||
d->pc = runtime·getcallerpc(&siz);
|
||||
d->pc = (uintptr)runtime·getcallerpc(&siz);
|
||||
if(thechar == '5')
|
||||
d->argp = (byte*)(&fn+2); // skip caller's saved link register
|
||||
d->argp = (uintptr)(&fn+2); // skip caller's saved link register
|
||||
else
|
||||
d->argp = (byte*)(&fn+1);
|
||||
runtime·memmove(d->args, d->argp, d->siz);
|
||||
d->argp = (uintptr)(&fn+1);
|
||||
runtime·memmove(d->args, (byte*)d->argp, d->siz);
|
||||
|
||||
// deferproc returns 0 normally.
|
||||
// a deferred func that stops a panic
|
||||
@ -119,13 +119,13 @@ void
|
||||
runtime·deferreturn(uintptr arg0)
|
||||
{
|
||||
Defer *d;
|
||||
byte *argp;
|
||||
uintptr argp;
|
||||
FuncVal *fn;
|
||||
|
||||
d = g->defer;
|
||||
if(d == nil)
|
||||
return;
|
||||
argp = (byte*)&arg0;
|
||||
argp = (uintptr)&arg0;
|
||||
if(d->argp != argp)
|
||||
return;
|
||||
|
||||
@ -134,7 +134,7 @@ runtime·deferreturn(uintptr arg0)
|
||||
// won't know the form of the arguments until the jmpdefer can
|
||||
// flip the PC over to fn.
|
||||
g->m->locks++;
|
||||
runtime·memmove(argp, d->args, d->siz);
|
||||
runtime·memmove((byte*)argp, d->args, d->siz);
|
||||
fn = d->fn;
|
||||
g->defer = d->link;
|
||||
freedefer(d);
|
||||
@ -213,7 +213,7 @@ runtime·panic(Eface e)
|
||||
{
|
||||
Defer *d, dabort;
|
||||
Panic p;
|
||||
void *pc, *argp;
|
||||
uintptr pc, argp;
|
||||
|
||||
runtime·memclr((byte*)&p, sizeof p);
|
||||
p.arg = e;
|
||||
|
@ -624,17 +624,15 @@ struct Defer
|
||||
{
|
||||
int32 siz;
|
||||
bool special; // not part of defer frame
|
||||
byte* argp; // where args were copied from
|
||||
byte* pc;
|
||||
uintptr argp; // where args were copied from
|
||||
uintptr pc;
|
||||
FuncVal* fn;
|
||||
Defer* link;
|
||||
void* args[1]; // padded to actual size
|
||||
};
|
||||
|
||||
// argp used in Defer structs when there is no argp.
|
||||
// TODO(rsc): Maybe we could use nil instead, but we've always used -1
|
||||
// and I don't want to change this days before the Go 1.3 release.
|
||||
#define NoArgs ((byte*)-1)
|
||||
#define NoArgs ((uintptr)-1)
|
||||
|
||||
/*
|
||||
* panics
|
||||
@ -649,6 +647,8 @@ struct Panic
|
||||
bool aborted; // the panic was aborted
|
||||
};
|
||||
|
||||
typedef struct XXX XXX;
|
||||
|
||||
/*
|
||||
* stack traces
|
||||
*/
|
||||
@ -661,8 +661,8 @@ struct Stkframe
|
||||
uintptr lr; // program counter at caller aka link register
|
||||
uintptr sp; // stack pointer at pc
|
||||
uintptr fp; // stack pointer at caller aka frame pointer
|
||||
byte* varp; // top of local variables
|
||||
byte* argp; // pointer to function arguments
|
||||
uintptr varp; // top of local variables
|
||||
uintptr argp; // pointer to function arguments
|
||||
uintptr arglen; // number of bytes at argp
|
||||
};
|
||||
|
||||
@ -775,7 +775,7 @@ int32 runtime·read(int32, void*, int32);
|
||||
int32 runtime·write(uintptr, void*, int32); // use uintptr to accommodate windows.
|
||||
int32 runtime·close(int32);
|
||||
int32 runtime·mincore(void*, uintptr, byte*);
|
||||
void runtime·jmpdefer(FuncVal*, void*);
|
||||
void runtime·jmpdefer(FuncVal*, uintptr);
|
||||
void runtime·exit1(int32);
|
||||
void runtime·ready(G*);
|
||||
byte* runtime·getenv(int8*);
|
||||
|
@ -419,7 +419,7 @@ checkframecopy(Stkframe *frame, void *arg)
|
||||
if(StackDebug >= 2)
|
||||
runtime·printf(" checking %s frame=[%p,%p] stk=[%p,%p]\n", runtime·funcname(f), frame->sp, frame->fp, cinfo->stk, cinfo->base);
|
||||
// if we're not in the segment any more, return immediately.
|
||||
if(frame->varp < cinfo->stk || frame->varp >= cinfo->base) {
|
||||
if((byte*)frame->varp < cinfo->stk || (byte*)frame->varp >= cinfo->base) {
|
||||
if(StackDebug >= 2)
|
||||
runtime·printf(" <next segment>\n");
|
||||
return false; // stop traceback
|
||||
@ -438,7 +438,7 @@ checkframecopy(Stkframe *frame, void *arg)
|
||||
cinfo->frames++;
|
||||
return true;
|
||||
}
|
||||
if(frame->varp != (byte*)frame->sp) { // not in prologue (and has at least one local or outarg)
|
||||
if((byte*)frame->varp != (byte*)frame->sp) { // not in prologue (and has at least one local or outarg)
|
||||
stackmap = runtime·funcdata(f, FUNCDATA_LocalsPointerMaps);
|
||||
if(stackmap == nil) {
|
||||
cinfo->frames = -1;
|
||||
@ -501,7 +501,7 @@ copyabletopsegment(G *gp)
|
||||
// For now, this only happens with the Defer in runtime.main.
|
||||
continue;
|
||||
}
|
||||
if(d->argp < cinfo.stk || cinfo.base <= d->argp)
|
||||
if((byte*)d->argp < cinfo.stk || cinfo.base <= (byte*)d->argp)
|
||||
break; // a defer for the next segment
|
||||
fn = d->fn;
|
||||
if(fn == nil) // See issue 8047
|
||||
@ -666,7 +666,7 @@ adjustframe(Stkframe *frame, void *arg)
|
||||
pcdata = 0; // in prologue
|
||||
|
||||
// adjust local pointers
|
||||
if(frame->varp != (byte*)frame->sp) {
|
||||
if((byte*)frame->varp != (byte*)frame->sp) {
|
||||
stackmap = runtime·funcdata(f, FUNCDATA_LocalsPointerMaps);
|
||||
if(stackmap == nil)
|
||||
runtime·throw("no locals info");
|
||||
@ -715,7 +715,7 @@ adjustdefers(G *gp, AdjustInfo *adjinfo)
|
||||
*dp = (Defer*)((byte*)d + adjinfo->delta);
|
||||
continue;
|
||||
}
|
||||
if(d->argp < adjinfo->oldstk || adjinfo->oldbase <= d->argp)
|
||||
if((byte*)d->argp < adjinfo->oldstk || adjinfo->oldbase <= (byte*)d->argp)
|
||||
break; // a defer for the next segment
|
||||
fn = d->fn;
|
||||
if(fn == nil) {
|
||||
|
@ -139,7 +139,7 @@ runtime·gentraceback(uintptr pc0, uintptr sp0, uintptr lr0, G *gp, int32 skip,
|
||||
}
|
||||
}
|
||||
|
||||
frame.varp = (byte*)frame.fp;
|
||||
frame.varp = frame.fp;
|
||||
|
||||
// Derive size of arguments.
|
||||
// Most functions have a fixed-size argument block,
|
||||
@ -148,7 +148,7 @@ runtime·gentraceback(uintptr pc0, uintptr sp0, uintptr lr0, G *gp, int32 skip,
|
||||
// in package runtime and reflect, and for those we use call-specific
|
||||
// metadata recorded by f's caller.
|
||||
if(callback != nil || printing) {
|
||||
frame.argp = (byte*)frame.fp + sizeof(uintptr);
|
||||
frame.argp = frame.fp + sizeof(uintptr);
|
||||
if(f->args != ArgsSizeUnknown)
|
||||
frame.arglen = f->args;
|
||||
else if(flr == nil)
|
||||
@ -193,18 +193,18 @@ runtime·gentraceback(uintptr pc0, uintptr sp0, uintptr lr0, G *gp, int32 skip,
|
||||
// returns; everything live at earlier deferprocs is still live at that one.
|
||||
frame.continpc = frame.pc;
|
||||
if(waspanic) {
|
||||
if(panic != nil && panic->defer->argp == (byte*)sparg)
|
||||
if(panic != nil && panic->defer->argp == sparg)
|
||||
frame.continpc = (uintptr)panic->defer->pc;
|
||||
else if(defer != nil && defer->argp == (byte*)sparg)
|
||||
else if(defer != nil && defer->argp == sparg)
|
||||
frame.continpc = (uintptr)defer->pc;
|
||||
else
|
||||
frame.continpc = 0;
|
||||
}
|
||||
|
||||
// Unwind our local panic & defer stacks past this frame.
|
||||
while(panic != nil && (panic->defer == nil || panic->defer->argp == (byte*)sparg || panic->defer->argp == NoArgs))
|
||||
while(panic != nil && (panic->defer == nil || panic->defer->argp == sparg || panic->defer->argp == NoArgs))
|
||||
panic = panic->link;
|
||||
while(defer != nil && (defer->argp == (byte*)sparg || defer->argp == NoArgs))
|
||||
while(defer != nil && (defer->argp == sparg || defer->argp == NoArgs))
|
||||
defer = defer->link;
|
||||
|
||||
if(skip > 0) {
|
||||
|
@ -181,7 +181,7 @@ runtime·gentraceback(uintptr pc0, uintptr sp0, uintptr lr0, G *gp, int32 skip,
|
||||
}
|
||||
}
|
||||
|
||||
frame.varp = (byte*)frame.fp - sizeof(uintreg);
|
||||
frame.varp = frame.fp - sizeof(uintreg);
|
||||
|
||||
// Derive size of arguments.
|
||||
// Most functions have a fixed-size argument block,
|
||||
@ -190,7 +190,7 @@ runtime·gentraceback(uintptr pc0, uintptr sp0, uintptr lr0, G *gp, int32 skip,
|
||||
// in package runtime and reflect, and for those we use call-specific
|
||||
// metadata recorded by f's caller.
|
||||
if(callback != nil || printing) {
|
||||
frame.argp = (byte*)frame.fp;
|
||||
frame.argp = frame.fp;
|
||||
if(f->args != ArgsSizeUnknown)
|
||||
frame.arglen = f->args;
|
||||
else if(flr == nil)
|
||||
@ -228,18 +228,18 @@ runtime·gentraceback(uintptr pc0, uintptr sp0, uintptr lr0, G *gp, int32 skip,
|
||||
// returns; everything live at earlier deferprocs is still live at that one.
|
||||
frame.continpc = frame.pc;
|
||||
if(waspanic) {
|
||||
if(panic != nil && panic->defer->argp == (byte*)sparg)
|
||||
frame.continpc = (uintptr)panic->defer->pc;
|
||||
else if(defer != nil && defer->argp == (byte*)sparg)
|
||||
frame.continpc = (uintptr)defer->pc;
|
||||
if(panic != nil && panic->defer->argp == sparg)
|
||||
frame.continpc = panic->defer->pc;
|
||||
else if(defer != nil && defer->argp == sparg)
|
||||
frame.continpc = defer->pc;
|
||||
else
|
||||
frame.continpc = 0;
|
||||
}
|
||||
|
||||
// Unwind our local panic & defer stacks past this frame.
|
||||
while(panic != nil && (panic->defer == nil || panic->defer->argp == (byte*)sparg || panic->defer->argp == NoArgs))
|
||||
while(panic != nil && (panic->defer == nil || panic->defer->argp == sparg || panic->defer->argp == NoArgs))
|
||||
panic = panic->link;
|
||||
while(defer != nil && (defer->argp == (byte*)sparg || defer->argp == NoArgs))
|
||||
while(defer != nil && (defer->argp == sparg || defer->argp == NoArgs))
|
||||
defer = defer->link;
|
||||
|
||||
if(skip > 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user