git: 9front

Download patch

ref: 02dc6c44a85722d2ee7e1fe788f404fc286a3f50
parent: 62d86c34105dcc67dccdf429ff92fd35bd84cd72
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Mon Sep 22 19:07:59 EDT 2014

acid: fix sysr1() stack corruption

the syscall stubs (for amd64) currently have a unconditional
spill of the first (register) argument to the stack.

sysr1 (and _nsec) are exceptional in that they do not
take any arguments, so the stub is writing unconditionally
to ther first argument slot on the stack.

i could avoid emiting the spill in the syscall stubs for
sysr1 but that would also break truss which assumes fixed
instruction sequence from stub start to the syscall number.

i'm not going to complicate the syscall stubs just for
sysr1 (_nsec is not used in 9front), but just add a dummy
argument to sysr1 definition that can receive the bogus
argument spill.

--- a/sys/src/cmd/acid/builtin.c
+++ b/sys/src/cmd/acid/builtin.c
@@ -122,12 +122,13 @@
 void
 dosysr1(Node *r, Node*)
 {
-	extern int sysr1(void);
+	/* dummy argument for RARG spill */
+	extern int sysr1(void*);
 	
 	r->op = OCONST;
 	r->type = TINT;
 	r->fmt = 'D';
-	r->ival = sysr1();
+	r->ival = sysr1(0);
 }
 
 void
--