ref: 837b2cb7b258a5a81325e521b1555b18f88eab74
parent: 54daa7961f3639adc9965ffa4ddf98e4ab0f2ff9
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Sep 19 13:40:46 EDT 2015
Fix syscalls on FreeBSD
--- a/lib/std/bld.sub
+++ b/lib/std/bld.sub
@@ -77,6 +77,7 @@
syswrap-ss+linux.myr
syswrap-ss+osx.myr
syswrap-ss+plan9.myr
+ syswrap-ss+freebsd.myr
syswrap+plan9.myr
syswrap+posixy.myr
;;
--- a/lib/std/execvp.myr
+++ b/lib/std/execvp.myr
@@ -1,5 +1,6 @@
use "alloc.use"
use "env.use"
+use "errno.use"
use "fmt.use"
use "option.use"
use "strfind.use"
--- a/lib/sys/bld.sub
+++ b/lib/sys/bld.sub
@@ -9,6 +9,7 @@
syscall+plan9-x64.s
syserrno+linux.myr
syserrno+osx.myr
+ syserrno+freebsd.myr
systypes.myr
ifreq+freebsd.myr
ifreq+linux.myr
--- a/lib/sys/sys+freebsd-x64.myr
+++ b/lib/sys/sys+freebsd-x64.myr
@@ -87,11 +87,11 @@
;;
type utsname = struct
- system : byte[256]
- node : byte[256]
- release : byte[256]
- version : byte[256]
- machine : byte[256]
+ system : byte[32]
+ node : byte[32]
+ release : byte[32]
+ version : byte[32]
+ machine : byte[32]
;;
type sockaddr = struct
@@ -712,9 +712,7 @@
wraps a syscall argument, converting it to 64 bits for the syscall function. This is
the same as casting, but more concise than writing castto(int64)
*/
-generic a = {x : @t
- -> a(x)
-}
+generic a = {x : @t; -> x castto(uint64)}
extern const cstring : (str : byte[:] -> byte#)
extern const alloca : (sz : size -> byte#)
@@ -736,7 +734,7 @@
/* of course we fucking have to duplicate this code everywhere,
* since we want to stack allocate... */
p = alloca((args.len + 1)*sizeof(byte#))
- cargs = (p castto(byte##))[:args.len]
+ cargs = (p castto(byte##))[:args.len + 1]
for i = 0; i < args.len; i++
cargs[i] = cstring(args[i])
;;
--- a/lib/sys/syscall+freebsd-x64.s
+++ b/lib/sys/syscall+freebsd-x64.s
@@ -8,14 +8,17 @@
harmless.
*/
movq %rdi,%rax
- movq %rsi,%rdi
- movq %rdx,%rsi
- movq %rcx,%rdx
- movq %r8,%r10
- movq %r9,%r8
- movq 8(%rsp),%r9
+ /* 8(%rsp): hidden type arg */
+ movq 16(%rsp),%rdi
+ movq 24(%rsp),%rsi
+ movq 32(%rsp),%rdx
+ movq 40(%rsp),%r10
+ movq 48(%rsp),%r8
+ movq 56(%rsp),%r9
syscall
+ jae .success
+ negq %rax
+.success:
ret
-
--- a/rt/start-freebsd.s
+++ b/rt/start-freebsd.s
@@ -53,6 +53,9 @@
pushq %rsi
pushq %rdx
+ /* call pre-main initializers */
+ call __init__
+
/* enter the main program */
call main
/* exit(0) */
--- a/rt/start-linux.s
+++ b/rt/start-linux.s
@@ -66,7 +66,7 @@
pushq %rsi
pushq %rdx
- /* enter the main program */
+ /* call pre-main initializers */
call __init__
/* enter the main program */
call main