Commit 3de7ba18 authored by Russ Cox's avatar Russ Cox

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