ref: 920b587c66cc2bb5169a117500deb9f8b00127fd
parent: 377381aa9dcdc3a004faac1b06aa79d0e4fa9c98
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Dec 14 09:51:30 EST 2017
Add atexit for 9front. A tad ugly, but a start. Maybe we'll figure something better out soon.
--- a/lib/sys/sys+plan9-x64.myr
+++ b/lib/sys/sys+plan9-x64.myr
@@ -169,7 +169,24 @@
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)
--- a/lib/thread/spawn+plan9.myr
+++ b/lib/thread/spawn+plan9.myr
@@ -9,7 +9,7 @@
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)
--- a/rt/_myrrt-plan9.s
+++ b/rt/_myrrt-plan9.s
@@ -62,6 +62,7 @@
CALL main(SB)
POPQ DX
POPQ R13
+ CALL sys$__fini__(SB)
exitloop:
MOVQ $0,8(SP)