ref: 9ed8ab553a8d92893f0417abcc2adbfc3f94e478
parent: c55bb8743117711e0b825bf5fffbde60ab34c909
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Aug 21 20:07:21 EDT 2014
Wrap up syscall args in trivial 'a()' function.
This shouldn't even cost performance once we have an inliner...
--- a/libstd/sys-linux.myr
+++ b/libstd/sys-linux.myr
@@ -599,16 +599,24 @@
const uname : (buf : utsname# -> int)
;;
+/*
+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 cstring : (str : byte[:] -> byte#)
extern const alloca : (sz : size -> byte#)
extern const __cenvp : byte##
/* process management */
-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)}+const kill = {pid, sig; -> syscall(Syskill, a(pid), a(sig))} const fork = {; -> syscall(Sysfork)}-const wait4 = {pid, loc, opt, usage; -> syscall(Syswait4, pid, loc, opt, usage)}+const wait4 = {pid, loc, opt, usage; -> syscall(Syswait4, a(pid), a(loc), a(opt), a(usage))} const waitpid = {pid, loc, opt;var rusage
-> wait4(pid, loc, opt, &rusage)
@@ -625,7 +633,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@@ -652,20 +660,20 @@
;;
cenv[env.len] = 0 castto(byte#)
- -> syscall(Sysexecve, cstring(cmd), p, cenv)
+ -> syscall(Sysexecve, cstring(cmd), a(p), a(cenv))
}
/* file 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 castto(uint64))}-const creat = {path, mode; -> syscall(Syscreat, cstring(path), mode) castto(fd)}-const read = {fd, buf; -> syscall(Sysread, fd castto(uint64), buf castto(byte#), buf.len castto(uint64)) castto(size)}-const write = {fd, buf; -> syscall(Syswrite, fd castto(uint64), buf castto(byte#), buf.len castto(uint64)) castto(size)}-const lseek = {fd, off, whence; -> syscall(Syslseek, fd castto(uint64), off, whence)}-const stat = {path, sb; -> syscall(Sysstat, cstring(path), sb)}-const fstat = {fd, sb; -> syscall(Sysfstat, fd castto(uint64), sb)}-const mkdir = {path, mode; -> syscall(Sysmkdir, cstring(path), mode) castto(int64)}+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; -> syscall(Syscreat, cstring(path), a(mode)) castto(fd)}+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(Sysstat, cstring(path), a(sb))}+const fstat = {fd, sb; -> syscall(Sysfstat, a(fd), a(sb))}+const mkdir = {path, mode; -> syscall(Sysmkdir, cstring(path), a(mode)) castto(int64)} const ioctl = {fd, req, argsvar arg : byte#
var ap
@@ -672,36 +680,40 @@
ap = vastart(&args)
(arg, ap) = vanext(ap)
- -> syscall(Sysioctl, fd castto(uint64), req, arg) castto(int64)
+ -> syscall(Sysioctl, a(fd), a(req), a(arg)) castto(int64)
}
-const getdents64 = {fd, buf; -> syscall(Sysgetdents64, fd castto(uint64), buf castto(byte#), buf.len)}+const getdents64 = {fd, buf; -> syscall(Sysgetdents64, a(fd), buf castto(byte#), a(buf.len))}/* file stuff */
const pipe = {fds; -> syscall(Syspipe, fds 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)}/* epoll */
-const epollcreate = {flg; -> syscall(Sysepoll_create1, flg castto(uint64)) castto(fd)}-const epollctl = {epfd, op, fd, evt; -> syscall(Sysepoll_ctl, epfd castto(uint64), op castto(uint64), fd castto(uint64), evt castto(uint64)) castto(int)}-const epollwait = {epfd, evts, timeout; -> syscall(Sysepoll_wait, epfd castto(uint64), evts castto(epollevt#), evts.len castto(uint64), timeout castto(uint64)) castto(int)}-const poll = {pfd, timeout; -> syscall(Syspoll, pfd castto(pollfd#), pfd.len castto(uint64), timeout castto(uint64)) castto(int)}+const poll = {pfd, timeout; -> syscall(Syspoll, pfd castto(pollfd#), a(pfd.len), a(timeout)) castto(int)}+const epollctl = {epfd, op, fd, evt;+ -> syscall(Sysepoll_ctl, a(epfd), a(op), a(fd), a(evt)) castto(int)}
+const epollwait = {epfd, evts, timeout;+ -> syscall(Sysepoll_wait, a(epfd), evts castto(epollevt#), a(evts.len), a(timeout)) castto(int)}
+const epollcreate = {flg; -> syscall(Sysepoll_create1, a(flg)) castto(fd)}/* 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 bind = {sock, addr, len; -> syscall(Sysbind, sock, addr, len) castto(int)}-const listen = {sock, backlog; -> syscall(Syslisten, sock, backlog castto(int64)) castto(int)}-const accept = {sock, addr, lenp; -> syscall(Sysaccept, sock, addr, lenp) castto(fd)}+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 bind = {sock, addr, len; -> syscall(Sysbind, a(sock), a(addr), a(len)) castto(int)}+const listen = {sock, backlog; -> syscall(Syslisten, a(sock), a(backlog)) castto(int)}+const accept = {sock, addr, lenp; -> syscall(Sysaccept, a(sock), a(addr), a(lenp)) castto(fd)}/* memory mapping */
-const munmap = {addr, len; -> syscall(Sysmunmap, addr, len)}-const mmap = {addr, len, prot, flags, fd, off; -> syscall(Sysmmap, addr, len, prot, flags, fd castto(uint64), 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 clock_getres = {clk, ts; -> syscall(Sysclock_getres, clockid(clk), ts) castto(int32)}-const clock_gettime = {clk, ts; -> syscall(Sysclock_gettime, clockid(clk), ts) castto(int32)}-const clock_settime = {clk, ts; -> syscall(Sysclock_settime, clockid(clk), ts) castto(int32)}+const clock_getres = {clk, ts; -> syscall(Sysclock_getres, clockid(clk), a(ts)) castto(int32)}+const clock_gettime = {clk, ts; -> syscall(Sysclock_gettime, clockid(clk), a(ts)) castto(int32)}+const clock_settime = {clk, ts; -> syscall(Sysclock_settime, clockid(clk), a(ts)) castto(int32)} const sleep = {timevar req, rem
@@ -709,9 +721,7 @@
-> nanosleep(&req, &rem)
}
-const nanosleep = {req, rem;- -> syscall(Sysnanosleep, req, rem) castto(int32)
-}
+const nanosleep = {req, rem; -> syscall(Sysnanosleep, a(req), a(rem)) castto(int32)}/* system information */
const uname = {buf; -> syscall(Sysuname, buf) castto(int)}--
⑨