summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-04-22 00:12:26 -0700
committerOri Bernstein <ori@eigenstate.org>2017-04-22 00:12:26 -0700
commit09d82f137706f80e53cdb12b12cd0e52217aeb57 (patch)
tree655b0024411baac31c3075281fedbab57122e004
parentb0b7605bb866cccae5ea15cb9b8b18524ecc84d6 (diff)
downloadmc-09d82f137706f80e53cdb12b12cd0e52217aeb57.tar.gz
Reserve stack space for the environment.
We copied it, but then clobbered it. Shit.
-rw-r--r--lib/std/fndup.myr3
-rw-r--r--lib/thread/spawn+freebsd.myr12
2 files changed, 10 insertions, 5 deletions
diff --git a/lib/std/fndup.myr b/lib/std/fndup.myr
index dce0837..0169f96 100644
--- a/lib/std/fndup.myr
+++ b/lib/std/fndup.myr
@@ -25,12 +25,15 @@ generic fnenvsz = {fn
-> envslice(repr[0]).len
}
+extern const put : (fmt : byte[:], args : ... -> int64)
+
generic fnbdup = {fn, buf
var repr : intptr[2]
var env
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#)#
diff --git a/lib/thread/spawn+freebsd.myr b/lib/thread/spawn+freebsd.myr
index ebeb616..cdc7673 100644
--- a/lib/thread/spawn+freebsd.myr
+++ b/lib/thread/spawn+freebsd.myr
@@ -17,7 +17,7 @@ const spawn = {fn
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 @@ const spawnstk = {fn, sz
/* 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 @@ const getstk = {sz
-> (m : byte#)
}
-const startthread = {fn : (-> void)#
- fn#()
+const startthread = {f : (-> void)#
+ f#()
exit()
}