shithub: mc

Download patch

ref: 09d82f137706f80e53cdb12b12cd0e52217aeb57
parent: b0b7605bb866cccae5ea15cb9b8b18524ecc84d6
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Apr 21 20:12:26 EDT 2017

Reserve stack space for the environment.

	We copied it, but then clobbered it. Shit.

--- a/lib/std/fndup.myr
+++ b/lib/std/fndup.myr
@@ -25,6 +25,8 @@
 	-> envslice(repr[0]).len
 }
 
+extern const put : (fmt : byte[:], args : ... -> int64)
+
 generic fnbdup = {fn, buf
 	var repr : intptr[2]
 	var env
@@ -31,6 +33,7 @@
 
 	repr = (&fn : intptr[2]#)#
 	env = envslice(repr[0])
+	std.put("repr: {}\n", repr)
 	slcp(buf[:env.len], env)
 	repr[0] = (buf : intptr)
 	-> (&repr : @fn::function#)#
--- a/lib/thread/spawn+freebsd.myr
+++ b/lib/thread/spawn+freebsd.myr
@@ -17,7 +17,7 @@
 
 const spawnstk = {fn, sz
 	var stk : byte#, tid, ctid, ret
-	var szp, fp, tos, env, envsz
+	var szp, f, tos, env, envsz
 
 	stk = getstk(sz)
 	if stk == sys.Mapbad
@@ -36,11 +36,13 @@
 	/* store the function we call */
 	envsz = std.fnenvsz(fn)
 	tos -= (envsz : std.intptr)
+	sz -= (envsz : sys.size)
 	env = tos
 	tos -= sizeof((->void))
 	sz -= sizeof((->void))
-	fp = (tos : (->void)#)
-	fp# = std.fnbdup(fn, (env : byte#)[:envsz])
+	f = (tos : (->void)#)
+	f# = std.fnbdup(fn, (env : byte#)[:envsz])
+	var repr = (&fn : int64[2]#)#
 
 	ret = sys.thr_new(&[
 		.startfn = (startthread : void#),
@@ -70,8 +72,8 @@
 	-> (m : byte#)
 }
 
-const startthread = {fn : (-> void)#
-	fn#()
+const startthread = {f : (-> void)#
+	f#()
 	exit()
 }