ref: e38e62217b5946970855fe2760dcea764db6c74c
parent: 55a8161ac8d282bf14fc4344d0b87b334b375767
author: Ori Bernstein <[email protected]>
date: Fri Aug 22 06:43:48 EDT 2014
Also wrap syscall args on OSX with 'a()' function.
--- a/libstd/sys-osx.myr
+++ b/libstd/sys-osx.myr
@@ -557,7 +557,7 @@
const getpid : ( -> pid)
const kill : (pid : pid, sig:int64 -> int64)
const fork : (-> pid)
- const wait4 : (pid : pid, loc:int32#, opt : int64, usage:rusage# -> int64)
+ const wait4 : (pid : pid, loc:int32#, opt : int64, rusage:rusage# -> int64)
const waitpid : (pid : pid, loc:int32#, opt : int64 -> int64)
const execv : (cmd : byte[:], args : byte[:][:] -> int64)
const execve : (cmd : byte[:], args : byte[:][:], env : byte[:][:] -> int64)
@@ -614,18 +614,26 @@
const sysctl : (mib : int[:], old : byte[:]#, new : byte[:] -> int)
;;
-extern const __osx_fork : (->int64)
-extern const __osx_pipe : (fd : fd# ->int64)
+/*
+wraps a syscall argument, converting it to 64 bits for the syscall function. This is
+effectively the same as casting all the args, but shorter than writing castto(int64)
+*/
+generic a = {x : @t
+ -> x castto(uint64)
+}
+
+extern const __osx_fork : (-> pid)
+extern const __osx_pipe : (fd : fd# -> int64)
extern const cstring : (str : byte[:] -> byte#)
extern const alloca : (sz : size -> byte#)
extern const __cenvp : byte##
/* process control */
-const exit = {status; syscall(Sysexit, status castto(int64))}
-const getpid = {; -> syscall(Sysgetpid, 1)}
-const kill = {pid, sig; -> syscall(Syskill, pid, sig)}
+const exit = {status; syscall(Sysexit, a(status))}
+const getpid = {; -> syscall(Sysgetpid) castto(pid)}
+const kill = {pid, sig; -> syscall(Syskill, a(pid), a(sig))}
const fork = {; -> __osx_fork()}
-const wait4 = {pid, loc, opt, usage; -> syscall(Syswait4, pid, loc, opt, usage)}
+const wait4 = {pid, loc, opt, rusage; -> syscall(Syswait4, a(pid), a(loc), a(opt), a(rusage))}
const waitpid = {pid, loc, opt;
-> wait4(pid, loc, opt, 0 castto(rusage#))
}
@@ -640,7 +648,7 @@
cargs[i] = cstring(args[i])
;;
cargs[args.len] = 0 castto(byte#)
- -> syscall(Sysexecve, cstring(cmd), p, __cenvp)
+ -> syscall(Sysexecve, cstring(cmd), a(p), a(__cenvp))
}
const execve = {cmd, args, env
@@ -667,22 +675,22 @@
;;
cenv[env.len] = 0 castto(byte#)
- -> syscall(Sysexecve, cstring(cmd), p, cenv)
+ -> syscall(Sysexecve, cstring(cmd), a(p), a(cenv))
}
/* fd manipulation */
-const open = {path, opts; -> syscall(Sysopen, cstring(path), opts, 0o777) castto(fd)}
-const openmode = {path, opts, mode; -> syscall(Sysopen, cstring(path), opts, mode) castto(fd)}
-const close = {fd; -> syscall(Sysclose, fd)}
+const open = {path, opts; -> syscall(Sysopen, cstring(path), a(opts), a(0o777)) castto(fd)}
+const openmode = {path, opts, mode; -> syscall(Sysopen, cstring(path), a(opts), a(mode)) castto(fd)}
+const close = {fd; -> syscall(Sysclose, a(fd))}
const creat = {path, mode; -> openmode(path, Ocreat | Otrunc | Owronly, mode) castto(fd)}
-const read = {fd, buf; -> syscall(Sysread, fd, buf castto(byte#), buf.len castto(size)) castto(size)}
-const write = {fd, buf; -> syscall(Syswrite, fd, buf castto(byte#), buf.len castto(size)) castto(size)}
-const lseek = {fd, off, whence; -> syscall(Syslseek, fd, off, whence)}
-const stat = {path, sb; -> syscall(Sysstat64, cstring(path), sb)}
-const lstat = {path, sb; -> syscall(Syslstat64, cstring(path), sb)}
-const fstat = {fd, sb; -> syscall(Sysfstat64, fd, sb)}
-const mkdir = {path, mode; -> syscall(Sysmkdir, cstring(path), mode) castto(int64)}
+const read = {fd, buf; -> syscall(Sysread, a(fd), buf castto(byte#), a(buf.len)) castto(size)}
+const write = {fd, buf; -> syscall(Syswrite, a(fd), buf castto(byte#), a(buf.len)) castto(size)}
+const lseek = {fd, off, whence; -> syscall(Syslseek, a(fd), a(off), a(whence))}
+const stat = {path, sb; -> syscall(Sysstat64, cstring(path), a(sb))}
+const lstat = {path, sb; -> syscall(Syslstat64, cstring(path), a(sb))}
+const fstat = {fd, sb; -> syscall(Sysfstat64, a(fd), a(sb))}
+const mkdir = {path, mode; -> syscall(Sysmkdir, cstring(path), a(mode)) castto(int64)}
const ioctl = {fd, req, args
var arg : byte#
var ap
@@ -689,47 +697,48 @@
ap = vastart(&args)
(arg, ap) = vanext(ap)
- -> syscall(Sysioctl, fd, req, arg) castto(int64)
+ -> syscall(Sysioctl, a(fd), a(req), a(arg)) castto(int64)
}
-const getdirentries64 = {fd, buf, basep; -> syscall(Sysgetdirentries64, fd, buf castto(byte#), buf.len castto(size), basep)}
+const getdirentries64 = {fd, buf, basep; -> syscall(Sysgetdirentries64, a(fd), buf castto(byte#), a(buf.len), a(basep))}
/* fd stuff */
const pipe = {fd; -> __osx_pipe(fd castto(fd#))}
-const dup = {fd; -> syscall(Sysdup, fd castto(uint64)) castto(fd)}
-const dup2 = {src, dst; -> syscall(Sysdup2, src castto(uint64), dst castto(uint64)) castto(fd)}
+const dup = {fd; -> syscall(Sysdup, a(fd)) castto(fd)}
+const dup2 = {src, dst; -> syscall(Sysdup2, a(src), a(dst)) castto(fd)}
/* kqueueueueueueue */
const kqueue = {; -> syscall(Syskqueue) castto(fd)}
const kevent = {q, cl, el, flg, timeout
- -> syscall(Syskevent, q castto(uint64), \
- cl castto(kevent#), cl.len castto(uint64), \
- el castto(kevent#), el.len castto(uint64), \
- flg castto(uint64), \
+ -> syscall(Syskevent, a(q), \
+ cl castto(kevent#), a(cl.len), \
+ el castto(kevent#), a(el.len), \
+ a(flg), \
timeout)
}
const kevent64 = {q, cl, el, flg, timeout
- -> syscall(Syskevent, q castto(uint64), \
- cl castto(kevent#), cl.len castto(uint64), \
- el castto(kevent#), el.len castto(uint64), \
- flg castto(uint64), \
+ -> syscall(Syskevent, a(q), \
+ cl castto(kevent#), a(cl.len), \
+ el castto(kevent#), a(el.len), \
+ a(flg), \
timeout)
}
/* networking */
-const socket = {dom, stype, proto; -> syscall(Syssocket, dom castto(int64), stype, proto) castto(fd) }
-const connect = {sock, addr, len; -> syscall(Sysconnect, sock, addr, len) castto(int)}
-const accept = {sock, addr, len; -> syscall(Sysaccept, sock, addr, len) castto(fd)}
-const listen = {sock, backlog; -> syscall(Syslisten, sock, backlog castto(int64)) castto(int)}
-const bind = {sock, addr, len; -> syscall(Sysbind, sock, addr, len) castto(int)}
+const socket = {dom, stype, proto; -> syscall(Syssocket, a(dom), a(stype), a(proto)) castto(fd) }
+const connect = {sock, addr, len; -> syscall(Sysconnect, a(sock), a(addr), a(len)) castto(int)}
+const accept = {sock, addr, len; -> syscall(Sysaccept, a(sock), a(addr), a(len)) castto(fd)}
+const listen = {sock, backlog; -> syscall(Syslisten, a(sock), a(backlog)) castto(int)}
+const bind = {sock, addr, len; -> syscall(Sysbind, a(sock), a(addr), a(len)) castto(int)}
/* memory management */
-const munmap = {addr, len; -> syscall(Sysmunmap, addr, len)}
-const mmap = {addr, len, prot, flags, fd, off; -> syscall(Sysmmap, addr, len, prot, flags, fd, off) castto(byte#)}
+const munmap = {addr, len; -> syscall(Sysmunmap, a(addr), a(len))}
+const mmap = {addr, len, prot, flags, fd, off;
+ -> syscall(Sysmmap, a(addr), a(len), a(prot), a(flags), a(fd), a(off)) castto(byte#)}
/* time */
-const gettimeofday = {tv, tz; -> syscall(Sysgettimeofday, tv, tz) castto(int)}
-const settimeofday = {tv, tz; -> syscall(Syssettimeofday, tv, tz) castto(int)}
+const gettimeofday = {tv, tz; -> syscall(Sysgettimeofday, a(tv), a(tz)) castto(int)}
+const settimeofday = {tv, tz; -> syscall(Syssettimeofday, a(tv), a(tz)) castto(int)}
/* faked with gettimeofday */
const clock_getres = {clk, ts
@@ -835,7 +844,7 @@
newp = new castto(byte#)
newsz = new castto(uint64)
- ret = syscall(Sys__sysctl, mibp, mibsz, oldp, &oldsz, newp, newsz) castto(int)
+ ret = syscall(Sys__sysctl, a(mibp), a(mibsz), a(oldp), a(&oldsz), a(newp), a(newsz)) castto(int)
old# = o[:oldsz]
-> ret