summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-12-14 14:51:30 -0800
committerOri Bernstein <ori@eigenstate.org>2017-12-14 14:51:30 -0800
commit920b587c66cc2bb5169a117500deb9f8b00127fd (patch)
treefa78cd059c021511f87906a5fc66a7cc00b2750e
parent377381aa9dcdc3a004faac1b06aa79d0e4fa9c98 (diff)
downloadmc-920b587c66cc2bb5169a117500deb9f8b00127fd.tar.gz
Add atexit for 9front.
A tad ugly, but a start. Maybe we'll figure something better out soon.
-rw-r--r--lib/sys/sys+plan9-x64.myr17
-rw-r--r--lib/thread/spawn+plan9.myr2
-rw-r--r--rt/_myrrt-plan9.s1
3 files changed, 19 insertions, 1 deletions
diff --git a/lib/sys/sys+plan9-x64.myr b/lib/sys/sys+plan9-x64.myr
index 2a749ae..33541fe 100644
--- a/lib/sys/sys+plan9-x64.myr
+++ b/lib/sys/sys+plan9-x64.myr
@@ -169,8 +169,25 @@ pkg sys =
extern var tosptr : tos#
extern var curbrk : byte#
+
+ const atexit : (fn : (-> void) -> void)
+
+ pkglocal const __fini__ : (-> void)
;;
+var exitfn : (-> void)[128]
+var nexit : size
+
+const atexit = {fn
+ exitfn[nexit++] = fn
+}
+
+const __fini__ = {
+ for var i = 0; i < nexit; i++
+ exitfn[i]()
+ ;;
+}
+
/* asm stub from syscall.s */
extern const syscall : (scno : scno, args : ... -> int64)
/* asm stubs from util+plan9.s */
diff --git a/lib/thread/spawn+plan9.myr b/lib/thread/spawn+plan9.myr
index d79731a..e577e7c 100644
--- a/lib/thread/spawn+plan9.myr
+++ b/lib/thread/spawn+plan9.myr
@@ -9,7 +9,7 @@ pkg thread =
const spawn = {fn
fn = std.fndup(fn)
- match sys.rfork(sys.Rfproc | sys.Rfmem | sys.Rfnowait)
+ match sys.rfork(sys.Rfproc | sys.Rfmem)
| 0:
fn()
std.fnfree(fn)
diff --git a/rt/_myrrt-plan9.s b/rt/_myrrt-plan9.s
index 4b76fdf..e52e160 100644
--- a/rt/_myrrt-plan9.s
+++ b/rt/_myrrt-plan9.s
@@ -62,6 +62,7 @@ TEXT _main(SB), 1, $(2*8+NPRIVATES*8)
CALL main(SB)
POPQ DX
POPQ R13
+ CALL sys$__fini__(SB)
exitloop:
MOVQ $0,8(SP)