ref: 0103ef37062ff55596da4d6ada8f75ae898885bc
parent: 5519708b4c280661204744f50e140298919dd718
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Nov 20 13:30:55 EST 2016
Fix sysctl signature. The previous one worked, but was really painful to use well for what it was intended.
--- a/lib/sys/sys+freebsd-x64.myr
+++ b/lib/sys/sys+freebsd-x64.myr
@@ -866,7 +866,10 @@
/* system information */
const uname : (buf : utsname# -> int)
- const sysctl : (mib : int[:], old : byte[:]#, new : byte[:] -> int)
+ const sysctl : (mib : int[:], \
+ old : void#, oldsz : size#, \
+ new : void#, newsz : size# \
+ -> int)
/* filled by start code */
extern const __cenvp : byte##
@@ -996,29 +999,10 @@
/* system information */
const uname = {buf; -> (syscall(Sysfreebsd4_uname, a(buf)) : int)}
-const sysctl = {mib, old, new
- var mibp
- var mibsz
- var o
- var oldp
- var oldsz
- var newp
- var newsz
- var ret
-
- mibp = (mib : byte#)
- mibsz = a(mib.len)
- o = old#
- oldp = (o : byte#)
- oldsz = a(o.len)
- newp = (new : byte#)
- newsz = a(new.len)
-
+const sysctl = {mib, old, oldsz, new, newsz
/* all args already passed through a() or ar ptrs */
- ret = (syscall(Sys__sysctl, mibp, mibsz, oldp, oldsz, newp, newsz) : int)
-
- old# = o[:oldsz]
- -> ret
+ -> (syscall(Sys__sysctl, \
+ (mib : int#), a(mib.len), old, oldsz, new, newsz) : int)
}
const clockid = {clk
--- a/lib/sys/sys+openbsd-x64.myr
+++ b/lib/sys/sys+openbsd-x64.myr
@@ -527,7 +527,10 @@
/* system information */
const uname : (buf : utsname# -> int)
- const sysctl : (mib : int[:], old : byte[:]#, new : byte[:] -> int)
+ const sysctl : (mib : int[:], \
+ old : void#, oldsz : size#, \
+ new : void#, newsz : size# \
+ -> int)
/* filled by start code */
extern const __cenvp : byte##
@@ -542,6 +545,7 @@
extern const cstring : (str : byte[:] -> byte#)
extern const alloca : (sz : size -> byte#)
+extern const __cenvp : byte##
extern const __freebsd_pipe : (fds : fd[2]# -> int64)
@@ -654,17 +658,18 @@
const uname = {buf
var mib : int[2]
var ret
- var sys
- var nod
- var rel
- var ver
- var mach
+ var sys, syssz
+ var nod, nodsz
+ var rel, relsz
+ var ver, versz
+ var mach, machsz
ret = 0
mib[0] = 1 /* CTL_KERN */
mib[1] = 1 /* KERN_OSTYPE */
- sys = buf.system[:]
- ret = sysctl(mib[:], &sys, [][:])
+ sys = (buf.system[:] : void#)
+ syssz = buf.system.len
+ ret = sysctl(mib[:], sys, &syssz, (0 : void#), (0 : size#))
if ret < 0
-> ret
;;
@@ -671,16 +676,12 @@
mib[0] = 1 /* CTL_KERN */
mib[1] = 10 /* KERN_HOSTNAME */
- nod = buf.node[:]
- ret = sysctl(mib[:], &nod, [][:])
- if ret < 0
- -> ret
- ;;
mib[0] = 1 /* CTL_KERN */
mib[1] = 2 /* KERN_OSRELEASE */
- rel = buf.release[:]
- ret = sysctl(mib[:], &rel, [][:])
+ rel = (buf.release[:] : void#)
+ relsz = buf.release.len
+ ret = sysctl(mib[:], rel, &relsz, (0 : void#), (0 : size#))
if ret < 0
-> ret
;;
@@ -687,8 +688,9 @@
mib[0] = 1 /* CTL_KERN */
mib[1] = 27 /* KERN_OSVERSION */
- ver = buf.version[:]
- ret = sysctl(mib[:], &ver, [][:])
+ ver = (buf.version[:] : void#)
+ versz = buf.version.len
+ ret = sysctl(mib[:], ver, &versz, (0 : void#), (0 : size#))
if ret < 0
-> ret
;;
@@ -695,8 +697,9 @@
mib[0] = 6 /* CTL_HW */
mib[1] = 1 /* HW_MACHINE */
- mach = buf.machine[:]
- ret = sysctl(mib[:], &mach, [][:])
+ mach = (buf.machine[:] : void#)
+ machsz = buf.machine.len
+ ret = sysctl(mib[:], mach, &machsz, (0 : void#), (0 : size#))
if ret < 0
-> ret
;;
@@ -704,29 +707,10 @@
-> 0
}
-const sysctl = {mib, old, new
- var mibp
- var mibsz
- var o
- var oldp
- var oldsz
- var newp
- var newsz
- var ret
-
- mibp = (mib : byte#)
- mibsz = a(mib.len)
- o = old#
- oldp = (o : byte#)
- oldsz = (o.len : int64)
- newp = (new : byte#)
- newsz = a(new.len)
-
+const sysctl = {mib, old, oldsz, new, newsz
/* all args already passed through a() or ar ptrs */
- ret = (syscall(Sys__sysctl, mibp, mibsz, oldp, a(&oldsz), newp, newsz) : int)
-
- old# = o[:oldsz]
- -> ret
+ -> (syscall(Sys__sysctl, \
+ (mib : int#), a(mib.len), old, oldsz, new, newsz) : int)
}
const clockid = {clk
--- a/lib/sys/sys+osx-x64.myr
+++ b/lib/sys/sys+osx-x64.myr
@@ -755,7 +755,10 @@
/* system information */
const uname : (buf : utsname# -> int)
- const sysctl : (mib : int[:], old : byte[:]#, new : byte[:] -> int)
+ const sysctl : (mib : int[:], \
+ old : void#, oldsz : size#, \
+ new : void#, newsz : size# \
+ -> int)
/* filled by start code */
extern const __cenvp : byte##
@@ -949,17 +952,18 @@
const uname = {buf;
var mib : int[2]
var ret
- var sys
- var nod
- var rel
- var ver
- var mach
+ var sys, syssz
+ var nod, nodsz
+ var rel, relsz
+ var ver, versz
+ var mach, machsz
ret = 0
mib[0] = 1 /* CTL_KERN */
mib[1] = 1 /* KERN_OSTYPE */
- sys = buf.system[:]
- ret = sysctl(mib[:], &sys, [][:])
+ sys = (buf.system[:] : void#)
+ syssz = buf.system.len
+ ret = sysctl(mib[:], sys, &syssz, (0 : void#), (0 : size#))
if ret < 0
-> ret
;;
@@ -966,8 +970,9 @@
mib[0] = 1 /* CTL_KERN */
mib[1] = 10 /* KERN_HOSTNAME */
- nod = buf.node[:]
- ret = sysctl(mib[:], &nod, [][:])
+ nod = (buf.node[:] : void#)
+ nodsz = buf.node.len
+ ret = sysctl(mib[:], nod, &nodsz, (0 : void#), (0 : size#))
if ret < 0
-> ret
;;
@@ -974,8 +979,9 @@
mib[0] = 1 /* CTL_KERN */
mib[1] = 2 /* KERN_OSRELEASE */
- rel = buf.release[:]
- ret = sysctl(mib[:], &rel, [][:])
+ rel = (buf.release[:] : void#)
+ relsz = buf.release.len
+ ret = sysctl(mib[:], rel, &relsz, (0 : void#), (0 : size#))
if ret < 0
-> ret
;;
@@ -982,8 +988,9 @@
mib[0] = 1 /* CTL_KERN */
mib[1] = 4 /* KERN_VERSION */
- ver = buf.version[:]
- ret = sysctl(mib[:], &ver, [][:])
+ ver = (buf.version[:] : void#)
+ versz = buf.version.len
+ ret = sysctl(mib[:], ver, &versz, (0 : void#), (0 : size#))
if ret < 0
-> ret
;;
@@ -990,8 +997,9 @@
mib[0] = 6 /* CTL_HW */
mib[1] = 1 /* HW_MACHINE */
- mach = buf.machine[:]
- ret = sysctl(mib[:], &mach, [][:])
+ mach = (buf.machine[:] : void#)
+ machsz = buf.machine.len
+ ret = sysctl(mib[:], mach, &machsz, (0 : void#), (0 : size#))
if ret < 0
-> ret
;;
@@ -999,33 +1007,10 @@
-> 0
}
-const sysctl = {mib, old, new
- var mibp
- var mibsz
- var o
- var oldp
- var oldsz
- var newp
- var newsz
- var ret
-
- mibp = (mib : byte#)
- mibsz = (mib.len : uint64)
- o = old#
- oldp = (o : byte#)
- oldsz = (o.len : uint64)
- if new.len > 0
- newp = (new : byte#)
- newsz = (new.len : uint64)
- else
- newp = (0 : byte#)
- newsz = 0
- ;;
-
- ret = (syscall(Sys__sysctl, a(mibp), a(mibsz), a(oldp), a(&oldsz), a(newp), a(newsz)) : int)
-
- old# = o[:oldsz]
- -> ret
+const sysctl = {mib, old, oldsz, new, newsz
+ /* all args already passed through a() or ar ptrs */
+ -> (syscall(Sys__sysctl, \
+ (mib : int#), a(mib.len), old, oldsz, new, newsz) : int)
}
const waitstatus = {st