From 434de8db8da082f214652a9fdb7e6a0fa3aea537 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Thu, 22 Nov 2018 20:27:27 +0100 Subject: [PATCH] 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. --- sys/src/cmd/snap/take.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sys/src/cmd/snap/take.c b/sys/src/cmd/snap/take.c index bb139ef11..2d0c88af3 100644 --- a/sys/src/cmd/snap/take.c +++ b/sys/src/cmd/snap/take.c @@ -166,18 +166,17 @@ stackptr(Proc *proc, int fd) 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; } }