ref: 434de8db8da082f214652a9fdb7e6a0fa3aea537
parent: 6bd0764167a0fbebb5ee90bf1a9c30e8d119442b
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Thu Nov 22 15:27:27 EST 2018
snap: use Mach->szaddr as the width of the stack pointer (fixes snap on amd64) to read the value of the stack pointer register, snap used Machdata->szreg to determine the width of the SP register in the Ureg structure. however, the value does not match the Ureg.sp type for a number of architectures (mips2, amd64) and it is unclear if this was an oversight as it is rarely used (snap is indeed the only user) or if it was intended for a different purpose. so we use szaddr instead which matches the stack pointer width in the Ureg and fixes the truncated stack issue on amd64.
--- a/sys/src/cmd/snap/take.c
+++ b/sys/src/cmd/snap/take.c
@@ -166,18 +166,17 @@
if((dreg = proc->d[Pregs]) == nil)
return 0;
- if(r->roffs+mach->szreg > dreg->len) {
+ if(r->roffs+mach->szaddr > dreg->len) {
fprint(2, "SP register too far into registers?\n");
return 0;
}
q = dreg->data+r->roffs;
- switch(mach->szreg) {
- case 2: return machdata->swab(*(ushort*)q);
+ switch(mach->szaddr) {
case 4: return machdata->swal(*(ulong*)q);
case 8: return machdata->swav(*(uvlong*)q);
default:
- fprint(2, "register size is %d bytes?\n", mach->szreg);
+ fprint(2, "address size is %d bytes?\n", mach->szaddr);
return 0;
}
}