diff options
Diffstat (limited to 'lib')
82 files changed, 5151 insertions, 1086 deletions
diff --git a/lib/bio/bio.myr b/lib/bio/bio.myr index e56844a..437cde6 100644 --- a/lib/bio/bio.myr +++ b/lib/bio/bio.myr @@ -33,17 +33,10 @@ pkg bio = close : (-> bool) ;; - type status(@a) = union + type err = union `Eof - `Ok @a - `Err ioerr - ;; - - type ioerr = union - `Ebadfile - `Ebadbuf - `Ebadfd - `Eioerr + `Eio + `Ebadf ;; /* creation */ @@ -56,36 +49,36 @@ pkg bio = const free : (f : file# -> void) /* basic i/o. Returns sub-buffer when applicable. */ - const write : (f : file#, src : byte[:] -> status(std.size)) - const read : (f : file#, dst : byte[:] -> status(byte[:])) + const write : (f : file#, src : byte[:] -> std.result(std.size, err)) + const read : (f : file#, dst : byte[:] -> std.result(byte[:], err)) const flush : (f : file# -> bool) /* seeking */ - const seek : (f : file#, off : std.off -> std.result(std.off, ioerr)) + const seek : (f : file#, off : std.off -> std.result(std.off, err)) /* single unit operations */ - const putb : (f : file#, b : byte -> status(std.size)) - const putc : (f : file#, c : char -> status(std.size)) - const getb : (f : file# -> status(byte)) - const getc : (f : file# -> status(char)) + const putb : (f : file#, b : byte -> std.result(std.size, err)) + const putc : (f : file#, c : char -> std.result(std.size, err)) + const getb : (f : file# -> std.result(byte, err)) + const getc : (f : file# -> std.result(char, err)) /* peeking */ - const peekb : (f : file# -> status(byte)) - const peekc : (f : file# -> status(char)) + const peekb : (f : file# -> std.result(byte, err)) + const peekc : (f : file# -> std.result(char, err)) /* delimited read; returns freshly allocated buffer. */ - const readln : (f : file# -> status(byte[:])) - const readto : (f : file#, delim : byte[:] -> status(byte[:])) + const readln : (f : file# -> std.result(byte[:], err)) + const readto : (f : file#, delim : byte[:] -> std.result(byte[:], err)) const skipto : (f : file#, delim : byte[:] -> bool) const skipspace : (f : file# -> bool) /* formatted i/o */ - const put : (f : file#, fmt : byte[:], args : ... -> status(std.size)) - const putv : (f : file#, fmt : byte[:], ap : std.valist# -> status(std.size)) + const put : (f : file#, fmt : byte[:], args : ... -> std.result(std.size, err)) + const putv : (f : file#, fmt : byte[:], ap : std.valist# -> std.result(std.size, err)) /* pkg funcs */ - pkglocal const ensureread : (f : file#, n : std.size -> status(std.size)) - pkglocal const ensurewrite : (f : file#, n : std.size -> status(std.size)) + pkglocal const ensureread : (f : file#, n : std.size -> std.result(std.size, err)) + pkglocal const ensurewrite : (f : file#, n : std.size -> std.result(std.size, err)) ;; const Bufsz = 16*std.KiB @@ -149,8 +142,8 @@ const dial = {srv, mode /* map from the bio modes to the unix open modes */ const sysmode = {mode match mode - | Rd: -> std.Ordonly - | Wr: -> std.Owronly + | Rd: -> std.Oread + | Wr: -> std.Owrite | Rw: -> std.Ordwr | _: std.fatal("bio: bad file mode") ;; @@ -208,7 +201,7 @@ const write = {f, src if src.len <= (f.wbuf.len - f.wend) std.slcp(f.wbuf[f.wend:f.wend+src.len], src) f.wend += src.len - -> `Ok src.len + -> `std.Ok src.len else flush(f) -> writebuf(f, src) @@ -225,7 +218,7 @@ const read = {f, dst /* Clear the error state so we can retry */ if f.lasterr != 0 - -> `Err geterr(f) + -> `std.Err geterr(f) ;; /* @@ -235,7 +228,7 @@ const read = {f, dst an EOF condition. */ if dst.len == 0 - -> `Ok dst + -> `std.Ok dst ;; std.assert(f.mode & Rd != 0, "File is not in read mode") /* @@ -268,7 +261,7 @@ const read = {f, dst d = d[n:] | `std.Err err: if count == 0 - -> `Err errtype(err) + -> `std.Err errtype(err) else f.lasterr = err ;; @@ -276,9 +269,9 @@ const read = {f, dst ;; ;; if count == 0 - -> `Eof + -> `std.Err `Eof else - -> `Ok dst[:count] + -> `std.Ok dst[:count] ;; } @@ -289,7 +282,7 @@ const flush = {f ret = true if f.mode & Wr != 0 match writebuf(f, f.wbuf[:f.wend]) - | `Ok n: ret = (n == f.wend) + | `std.Ok n: ret = (n == f.wend) | _: ret = false ;; ;; @@ -309,11 +302,10 @@ const seek = {f, off /* writes a single byte to the output stream */ const putb = {f, b match ensurewrite(f, 1) - | `Eof: -> `Eof - | `Err e: -> `Err e - | `Ok n: + | `std.Err e: -> `std.Err e + | `std.Ok n: f.wbuf[f.wend++] = b - -> `Ok 1 + -> `std.Ok 1 ;; } @@ -323,22 +315,20 @@ const putc = {f, c sz = std.charlen(c) match ensurewrite(f, sz) - | `Eof: -> `Eof - | `Err e: -> `Err e - | `Ok n: + | `std.Err e: -> `std.Err e + | `std.Ok n: std.encode(f.wbuf[f.wend:], c) f.wend += sz - -> `Ok sz + -> `std.Ok sz ;; } /* reads a single byte from the input stream */ const getb = {f match ensureread(f, 1) - | `Eof: -> `Eof - | `Err e: -> `Err e - | `Ok n: - -> `Ok f.rbuf[f.rstart++] + | `std.Err e: -> `std.Err e + | `std.Ok n: + -> `std.Ok f.rbuf[f.rstart++] ;; } @@ -347,12 +337,11 @@ const getc = {f var c match ensurecodepoint(f) - | `Eof: -> `Eof - | `Err e: -> `Err e - | `Ok n: + | `std.Err e: -> `std.Err e + | `std.Ok n: c = std.decode(f.rbuf[f.rstart:f.rend]) f.rstart += std.charlen(c) - -> `Ok c + -> `std.Ok c ;; } @@ -362,9 +351,8 @@ const ensurecodepoint = {f var len match ensureread(f, 1) - | `Eof: -> `Eof - | `Err e: -> `Err e - | `Ok n: + | `std.Err e: -> `std.Err e + | `std.Ok n: b = f.rbuf[f.rstart] if b & 0x80 == 0 /* 0b0xxx_xxxx */ len = 1 @@ -408,20 +396,18 @@ generic putbe = {f, v : @a::(numeric,integral) /* peeks a single byte from an input stream */ const peekb = {f match ensureread(f, 1) - | `Eof: -> `Eof - | `Err e: -> `Err e - | `Ok n: - -> `Ok f.rbuf[f.rstart] + | `std.Err e: -> `std.Err e + | `std.Ok n: + -> `std.Ok f.rbuf[f.rstart] ;; } /* peeks a single character from a utf8 encoded input stream */ const peekc = {f match ensurecodepoint(f) - | `Eof: -> `Eof - | `Err e: -> `Err e - | `Ok n: - -> `Ok std.decode(f.rbuf[f.rstart:f.rend]) + | `std.Err e: -> `std.Err e + | `std.Ok n: + -> `std.Ok std.decode(f.rbuf[f.rstart:f.rend]) ;; } @@ -441,23 +427,20 @@ const readto = {f, delim /* same as readto, but drops the read data. */ const skipto = {f, delim match readdelim(f, delim, true) - | `Ok ign: -> true - | `Eof: -> false - | `Err _: -> false + | `std.Ok ign: -> true + | `std.Err _: -> false ;; } const skipspace = {f while true match bio.peekc(f) - | `Ok c: + | `std.Ok c: if !std.isspace(c) break ;; bio.getc(f) - | `Err e: -> false - | `Eof: break - + | `std.Err e: -> false ;; ;; -> true @@ -471,15 +454,15 @@ const readln = {f while true /* get at least delimiter count of characters */ match ensureread(f, 1) - | `Ok _: - | `Err e: -> `Err e - | `Eof: + | `std.Err `Eof: ret = readinto(f, ret, f.rend - f.rstart) if ret.len > 0 - -> `Ok ret + -> `std.Ok ret else - -> `Eof + -> `std.Err `Eof ;; + | `std.Err e: -> `std.Err e + | `std.Ok _: ;; /* scan for delimiter */ for var i = f.rstart; i < f.rend; i++ @@ -491,7 +474,7 @@ const readln = {f if c == '\r' && unwrapc(peekc(f), -1) == '\n' f.rstart++ ;; - -> `Ok ret + -> `std.Ok ret ;; :nextitergetln ;; @@ -502,7 +485,7 @@ const readln = {f const unwrapc = {cc, v match cc - | `Ok c: -> c + | `std.Ok c: -> c | _: -> v ;; } @@ -514,17 +497,17 @@ const readdelim = {f, delim, drop while true /* get at least delimiter count of characters */ match ensureread(f, 1) - | `Ok _: - | `Err e: -> `Err e - | `Eof: + | `std.Err `Eof: if !drop ret = readinto(f, ret, f.rend - f.rstart) ;; if ret.len > 0 - -> `Ok ret + -> `std.Ok ret else - -> `Eof + -> `std.Err `Eof ;; + | `std.Err e: -> `std.Err e + | `std.Ok _: ;; for var i = f.rstart; i < f.rend; i++ if f.rbuf[i] == delim[0] @@ -537,7 +520,7 @@ const readdelim = {f, delim, drop ret = readinto(f, ret, i - f.rstart) ;; f.rstart += delim.len - -> `Ok ret + -> `std.Ok ret ;; :nextiterread ;; @@ -591,14 +574,13 @@ const ensurewrite = {f, n std.assert(n < f.wbuf.len, "ensured write capacity > buffer size") if n > f.wbuf.len - f.wend match writebuf(f, f.wbuf[:f.wend]) - | `Ok len: + | `std.Ok len: f.wend = 0 - -> `Ok len - | `Err e: -> `Err e - | `Eof: -> `Eof + -> `std.Ok len + | `std.Err e: -> `std.Err e ;; ;; - -> `Ok n + -> `std.Ok n } /* @@ -612,17 +594,16 @@ const ensureread = {f, n held = f.rend - f.rstart if n > held match fill(f, n) - | `Eof: -> `Eof - | `Err e: -> `Err e - | `Ok len: + | `std.Err e: -> `std.Err e + | `std.Ok len: if len >= n - -> `Ok len + -> `std.Ok len else - -> `Eof + -> `std.Err `Eof ;; ;; else - -> `Ok n + -> `std.Ok n ;; } @@ -634,16 +615,16 @@ const writebuf = {f, src while src.len != 0 match f.write(src) | `std.Ok 0: - -> `Eof + -> `std.Err `Eof | `std.Ok n: count += n src = src[n:] | `std.Err e: - -> `Err errtype(e) + -> `std.Err errtype(e) ;; ;; :writedone - -> `Ok count + -> `std.Ok count } @@ -658,7 +639,7 @@ const fill = {f, min count = 0 /* Clear the error state so we can retry */ if f.lasterr != 0 - -> `Err geterr(f) + -> `std.Err geterr(f) ;; /* if we need to shift the slice down to the start, do it */ @@ -684,16 +665,16 @@ const fill = {f, min if count > 0 f.lasterr = e else - -> `Err errtype(e) + -> `std.Err errtype(e) ;; break ;; ;; if count == 0 - -> `Eof + -> `std.Err `Eof else - -> `Ok count + -> `std.Ok count ;; } @@ -705,20 +686,18 @@ const geterr = {f -> errtype(e) } -const errtype = {e : std.errno -> ioerr +const errtype = {e : std.errno -> err var errno errno = (e : std.errno) if errno == std.Ebadf - -> `Ebadfile + -> `Ebadf elif errno == std.Einval - -> `Ebadfile + -> `Ebadf elif errno == std.Efault - -> `Ebadbuf - elif errno == std.Eio - -> `Eioerr + -> `Eio else - -> `Eioerr + -> `Eio ;; } diff --git a/lib/bio/geti.myr b/lib/bio/geti.myr index 70186b2..c7ae74e 100644 --- a/lib/bio/geti.myr +++ b/lib/bio/geti.myr @@ -4,34 +4,31 @@ use "bio" pkg bio = /* unsigned big endian */ - generic getbe8 : (f : file# -> status(@a::(numeric,integral))) - generic getbe16 : (f : file# -> status(@a::(numeric,integral))) - generic getbe32 : (f : file# -> status(@a::(numeric,integral))) - generic getbe64 : (f : file# -> status(@a::(numeric,integral))) + generic getbe8 : (f : file# -> std.result(@a::(numeric,integral), err)) + generic getbe16 : (f : file# -> std.result(@a::(numeric,integral), err)) + generic getbe32 : (f : file# -> std.result(@a::(numeric,integral), err)) + generic getbe64 : (f : file# -> std.result(@a::(numeric,integral), err)) /* signed big endian */ - generic getle8 : (f : file# -> status(@a::(numeric,integral))) - generic getle16 : (f : file# -> status(@a::(numeric,integral))) - generic getle32 : (f : file# -> status(@a::(numeric,integral))) - generic getle64 : (f : file# -> status(@a::(numeric,integral))) + generic getle8 : (f : file# -> std.result(@a::(numeric,integral), err)) + generic getle16 : (f : file# -> std.result(@a::(numeric,integral), err)) + generic getle32 : (f : file# -> std.result(@a::(numeric,integral), err)) + generic getle64 : (f : file# -> std.result(@a::(numeric,integral), err)) ;; /* reads a single integer-like value to the output stream, in little endian format */ -generic getle = {f, n -> status(@a::(numeric,integral)) - var v, i - - v = 0 +generic getle = {f, n -> std.result(@a::(numeric,integral), err) match ensureread(f, n) - | `Eof: -> `Eof - | `Err e : -> `Err e - | `Ok _: - for i = 0; i < n; i++ + | `std.Err e : -> `std.Err e + | `std.Ok _: + var v = 0 + for var i = 0; i < n; i++ v |= (f.rbuf[f.rstart++] : uint64) << (8*(i : uint64)) ;; - -> `Ok (v : @a::(numeric,integral)) + -> `std.Ok (v : @a::(numeric,integral)) ;; } @@ -39,19 +36,16 @@ generic getle = {f, n -> status(@a::(numeric,integral)) reads a single integer-like value to the output stream, in big endian format */ -generic getbe = {f, n -> status(@a::(numeric,integral)) - var v, i - - v = 0 +generic getbe = {f, n -> std.result(@a::(numeric,integral), err) match ensureread(f, n) - | `Eof: -> `Eof - | `Err e : -> `Err e - | `Ok _: - for i = 0; i < n; i++ + | `std.Err e : -> `std.Err e + | `std.Ok _: + var v = 0 + for var i = 0; i < n; i++ v <<= 8 v |= (f.rbuf[f.rstart++] : uint64) ;; - -> `Ok (v : @a::(numeric,integral)) + -> `std.Ok (v : @a::(numeric,integral)) ;; } diff --git a/lib/bio/iter.myr b/lib/bio/iter.myr index dbdd025..55379ed 100644 --- a/lib/bio/iter.myr +++ b/lib/bio/iter.myr @@ -18,9 +18,8 @@ const byline = {f impl iterable lineiter -> byte[:] = __iternext__ = {itp, outp match bio.readln((itp# : file#)) - | `Ok ln: outp# = ln - | `Err _: -> false - | `Eof: -> false + | `std.Ok ln: outp# = ln + | `std.Err _: -> false ;; -> true } @@ -37,9 +36,8 @@ const bychar = {f impl iterable chariter -> char = __iternext__ = {itp, outp : char# match bio.getc((itp# : file#)) - | `Ok c: outp# = c - | `Err _: -> false - | `Eof: -> false + | `std.Ok c: outp# = c + | `std.Err _: -> false ;; -> true } diff --git a/lib/bio/puti.myr b/lib/bio/puti.myr index d4d7a3f..056f6a4 100644 --- a/lib/bio/puti.myr +++ b/lib/bio/puti.myr @@ -4,16 +4,16 @@ use "bio" pkg bio = /* unsigned big endian */ - generic putbe8 : (f : file#, v : @a::(numeric,integral) -> status(std.size)) - generic putbe16 : (f : file#, v : @a::(numeric,integral) -> status(std.size)) - generic putbe32 : (f : file#, v : @a::(numeric,integral) -> status(std.size)) - generic putbe64 : (f : file#, v : @a::(numeric,integral) -> status(std.size)) + generic putbe8 : (f : file#, v : @a::(numeric,integral) -> std.result(std.size, err)) + generic putbe16 : (f : file#, v : @a::(numeric,integral) -> std.result(std.size, err)) + generic putbe32 : (f : file#, v : @a::(numeric,integral) -> std.result(std.size, err)) + generic putbe64 : (f : file#, v : @a::(numeric,integral) -> std.result(std.size, err)) /* unsigned little endian */ - generic putle8 : (f : file#, v : @a::(numeric,integral) -> status(std.size)) - generic putle16 : (f : file#, v : @a::(numeric,integral) -> status(std.size)) - generic putle32 : (f : file#, v : @a::(numeric,integral) -> status(std.size)) - generic putle64 : (f : file#, v : @a::(numeric,integral) -> status(std.size)) + generic putle8 : (f : file#, v : @a::(numeric,integral) -> std.result(std.size, err)) + generic putle16 : (f : file#, v : @a::(numeric,integral) -> std.result(std.size, err)) + generic putle32 : (f : file#, v : @a::(numeric,integral) -> std.result(std.size, err)) + generic putle64 : (f : file#, v : @a::(numeric,integral) -> std.result(std.size, err)) ;; generic putbe8 = {f, v; -> putbe(f, (v : uint64), 1)} @@ -30,9 +30,9 @@ const putle = {f, v, n var buf : byte[8] match ensurewrite(f, n) - | `Eof: -> `Eof - | `Err e: -> `Err e - | `Ok _: + | `std.Err e: + -> `std.Err e + | `std.Ok _: buf[0] = ((v >> 0) & 0xff : byte) buf[1] = ((v >> 8) & 0xff : byte) buf[2] = ((v >> 16) & 0xff : byte) @@ -49,9 +49,9 @@ const putbe = {f, v, n var buf : byte[8] match ensurewrite(f, n) - | `Eof: -> `Eof - | `Err e: -> `Err e - | `Ok _: + | `std.Err e: + -> `std.Err e + | `std.Ok _: buf[0] = ((v >> 56) & 0xff : byte) buf[1] = ((v >> 48) & 0xff : byte) buf[2] = ((v >> 40) & 0xff : byte) diff --git a/lib/bio/test/bio-delim.myr b/lib/bio/test/bio-delim.myr index 354dc50..dbc2f65 100644 --- a/lib/bio/test/bio-delim.myr +++ b/lib/bio/test/bio-delim.myr @@ -67,11 +67,11 @@ const main = { const readln = {f match bio.readln(f) - | `bio.Ok d: -> d - | `bio.Eof: + | `std.Ok d: -> d + | `std.Err `bio.Eof: std.put("eof\n") -> [][:] - | `bio.Err e: + | `std.Err e: std.put("err\n") -> [][:] ;; @@ -79,11 +79,11 @@ const readln = {f const readto = {f, delim match bio.readto(f, delim) - | `bio.Ok d: -> d - | `bio.Eof: + | `std.Ok d: -> d + | `std.Err `bio.Eof: std.put("eof\n") -> [][:] - | `bio.Err e: + | `std.Err e: std.put("err\n") -> [][:] ;; diff --git a/lib/bio/test/bio-endianrd.myr b/lib/bio/test/bio-endianrd.myr index e445459..8296c75 100644 --- a/lib/bio/test/bio-endianrd.myr +++ b/lib/bio/test/bio-endianrd.myr @@ -1,13 +1,6 @@ use std use bio -generic try = {opt : bio.status(@a::(integral,numeric))-> @a::(integral,numeric) - match opt - | `bio.Ok val: -> val - | _: std.fatal("read failed") - ;; -} - const main = { var b : byte var w : uint16 @@ -23,31 +16,31 @@ const main = { /* byte */ b = 0xaa - var r = try(bio.getle8(f)) + var r = std.try(bio.getle8(f)) std.assert(r == b, "le byte broken: {x}\n", r) - std.assert(try(bio.getbe8(f)) == b, "be byte broken\n") + std.assert(std.try(bio.getbe8(f)) == b, "be byte broken\n") /* word */ w = 0xaabb - std.assert(try(bio.getle16(f)) == w, "le word broken\n") - std.assert(try(bio.getbe16(f)) == w, "be word broken\n") + std.assert(std.try(bio.getle16(f)) == w, "le word broken\n") + std.assert(std.try(bio.getbe16(f)) == w, "be word broken\n") /* long */ l = 0xaabbccdd - std.assert(try(bio.getle32(f)) == l, "le long broken\n") - std.assert(try(bio.getbe32(f)) == l, "be long broken\n") + std.assert(std.try(bio.getle32(f)) == l, "le long broken\n") + std.assert(std.try(bio.getbe32(f)) == l, "be long broken\n") /* quad */ q = (0x11223344aabbccdd : uint64) - std.assert(try(bio.getle64(f)) == q, "le quad broken\n") - std.assert(try(bio.getbe64(f)) == q, "be quad broken\n") + std.assert(std.try(bio.getle64(f)) == q, "le quad broken\n") + std.assert(std.try(bio.getbe64(f)) == q, "be quad broken\n") /* end of file */ match bio.getle64(f) - | `bio.Eof: - | `bio.Err _: + | `std.Err `bio.Eof: + | `std.Err _: std.die("error on reading file\n") - | `bio.Ok v: + | `std.Ok v: std.die("read past end of file\n") v = q /* shut up type inference */ ;; diff --git a/lib/bio/test/bio-peek.myr b/lib/bio/test/bio-peek.myr index 506dea0..a0f4752 100644 --- a/lib/bio/test/bio-peek.myr +++ b/lib/bio/test/bio-peek.myr @@ -28,11 +28,11 @@ const main = { const peekc = {f match bio.peekc(f) - | `bio.Ok c: -> c - | `bio.Eof: + | `std.Ok c: -> c + | `std.Err `bio.Eof: std.put("eof\n") -> -1 - | `bio.Err e: + | `std.Err e: std.fatal("error reading\n") -> -1 ;; @@ -40,11 +40,11 @@ const peekc = {f const peekb = {f match bio.peekb(f) - | `bio.Ok b: -> b - | `bio.Eof: + | `std.Ok b: -> b + | `std.Err `bio.Eof: std.put("eof\n") -> -1 - | `bio.Err e: + | `std.Err e: std.fatal("error reading\n") -> -1 ;; diff --git a/lib/bio/test/bio-read.myr b/lib/bio/test/bio-read.myr index 829b442..3e477c2 100644 --- a/lib/bio/test/bio-read.myr +++ b/lib/bio/test/bio-read.myr @@ -40,12 +40,12 @@ const main = { const r = {f, buf match bio.read(f, buf) - | `bio.Ok b: + | `std.Ok b: -> b - | `bio.Eof: + | `std.Err `bio.Eof: std.put("eof\n") -> "" - | `bio.Err e: + | `std.Err e: std.put("err\n") -> "" ;; diff --git a/lib/bio/test/bio-unitwr.myr b/lib/bio/test/bio-unitwr.myr index 5b66bbb..f101927 100644 --- a/lib/bio/test/bio-unitwr.myr +++ b/lib/bio/test/bio-unitwr.myr @@ -3,6 +3,8 @@ use bio const main = { var f + + std.mkpath("tmpout") match bio.create("tmpout/test-unitwr", bio.Wr, 0o644) | `std.Ok bio: f = bio | `std.Err m: std.fatal("Unable to open data file: {}\n", m) diff --git a/lib/bio/test/mem.myr b/lib/bio/test/mem.myr index f3135d2..a7cb613 100644 --- a/lib/bio/test/mem.myr +++ b/lib/bio/test/mem.myr @@ -7,21 +7,21 @@ const main = { f = bio.mkmem("hello world") match bio.read(f, buf[:3]) - | `bio.Ok "hel": + | `std.Ok "hel": /* ok */ | _: std.fatal("invalid read from memfile") ;; match bio.read(f, buf[:]) - | `bio.Ok "lo world": + | `std.Ok "lo world": /* ok */ | _: std.fatal("invalid read from memfile") ;; match bio.read(f, buf[:]) - | `bio.Eof: + | `std.Err `bio.Eof: /* ok */ | _: std.fatal("expected eof in memfile") diff --git a/lib/bld.sub b/lib/bld.sub index 3bb040b..da62ed6 100644 --- a/lib/bld.sub +++ b/lib/bld.sub @@ -4,6 +4,7 @@ sub = date escfmt fileutil + http inifile json regex diff --git a/lib/crypto/entropy.myr b/lib/crypto/entropy.myr index b5c5120..8120791 100644 --- a/lib/crypto/entropy.myr +++ b/lib/crypto/entropy.myr @@ -7,7 +7,7 @@ pkg crypto = var randfd const __init__ = { - randfd = std.try(std.open("/dev/random", std.Ordonly)) + randfd = std.try(std.open("/dev/random", std.Oread)) } const getentropy = {buf diff --git a/lib/date/fmt.myr b/lib/date/fmt.myr index c66827b..323b25a 100644 --- a/lib/date/fmt.myr +++ b/lib/date/fmt.myr @@ -62,9 +62,9 @@ const datefmt = {sb, fmt, d | 'H': std.sbfmt(sb, "{p=0,w=2}", d.h) | 'I': std.sbfmt(sb, "{p=0,w=2}", d.h % 12) | 'j': std.sbfmt(sb, "year day... unimplemented.") - | 'k': std.sbfmt(sb, "{}", d.h) + | 'k': std.sbfmt(sb, "{p=0,w=2}", d.h) | 'l': std.sbfmt(sb, "{}", d.h % 12) - | 'm': std.sbfmt(sb, "{}", d.mon) + | 'm': std.sbfmt(sb, "{p=0,w=2}", d.mon) | 'M': std.sbfmt(sb, "{p=0,w=2}", d.m) | 'n': std.sbfmt(sb, "\n") | 'O': std.sbfmt(sb, "unsupported %O") diff --git a/lib/date/parse.myr b/lib/date/parse.myr index 80f0b76..19798dd 100644 --- a/lib/date/parse.myr +++ b/lib/date/parse.myr @@ -164,9 +164,9 @@ const eatspace = {s const indexof = {dst, s, set, err for var i = 0; i < set.len; i++ - if s.len >= set[i].len && std.streq(s, set[i]) + if s.len >= set[i].len && std.streq(s[:set[i].len], set[i]) dst# = i - -> s + -> s[set[i].len:] ;; ;; err# = `std.Some `Badname s diff --git a/lib/date/test/fmt.myr b/lib/date/test/fmt.myr index 024c7b6..d0abba9 100644 --- a/lib/date/test/fmt.myr +++ b/lib/date/test/fmt.myr @@ -7,13 +7,13 @@ const main = { /* epoch */ d = date.mkinstant(0, "") - eq("1970-1-01 00:00:00 +0000", std.bfmt(buf[:], "{D}", d)) + eq("1970-01-01 00:00:00 +0000", std.bfmt(buf[:], "{D}", d)) d = date.mkinstant(24*3600*1_000_000, "") - eq("1970-1-02 00:00:00 +0000", std.bfmt(buf[:], "{D}", d)) + eq("1970-01-02 00:00:00 +0000", std.bfmt(buf[:], "{D}", d)) /* epoch + 12 hours */ d = date.mkinstant(12*3600*1_000_000, "") - eq("1970-1-01 12:00:00 +0000", std.bfmt(buf[:], "{D}", d)) + eq("1970-01-01 12:00:00 +0000", std.bfmt(buf[:], "{D}", d)) /* epoch - 6 hours */ d = date.mkinstant(-6*3600*1_000_000, "") @@ -25,11 +25,11 @@ const main = { /* more or less random: Fri 29 Aug 2014 07:47:43 PM UTC*/ d = date.mkinstant(1_409_341_663*1_000_000, "") - eq("2014-8-29 19:47:43 +0000", std.bfmt(buf[:], "{D}", d)) + eq("2014-08-29 19:47:43 +0000", std.bfmt(buf[:], "{D}", d)) /* large negative time stamp */ d = date.mkinstant(-50000000000*1_000_000, "") - eq("385-7-25 07:06:40 +0000", std.bfmt(buf[:], "{D}", d)) + eq("385-07-25 07:06:40 +0000", std.bfmt(buf[:], "{D}", d)) /* date : the bc */ d = date.mkinstant(-70000000000*1_000_000, "") @@ -38,27 +38,27 @@ const main = { /* test addition and subtraction of dates */ d = date.mkinstant(-1, "") d = date.addperiod(d, `date.Hour 1) - eq("1970-1-01 00:59:59 +0000", std.bfmt(buf[:], "{D}", d)) + eq("1970-01-01 00:59:59 +0000", std.bfmt(buf[:], "{D}", d)) d = date.mkinstant(0, "") d = date.addperiod(d, `date.Hour 24) - eq("1970-1-02 00:00:00 +0000", std.bfmt(buf[:], "{D}", d)) + eq("1970-01-02 00:00:00 +0000", std.bfmt(buf[:], "{D}", d)) d = date.mkinstant(0, "") d = date.addperiod(d, `date.Day 1) - eq("1970-1-02 00:00:00 +0000", std.bfmt(buf[:], "{D}", d)) + eq("1970-01-02 00:00:00 +0000", std.bfmt(buf[:], "{D}", d)) d = date.subperiod(d, `date.Day 1) - eq("1970-1-01 00:00:00 +0000", std.bfmt(buf[:], "{D}", d)) + eq("1970-01-01 00:00:00 +0000", std.bfmt(buf[:], "{D}", d)) d = date.subperiod(d, `date.Year 1) - eq("1969-1-01 00:00:00 +0000", std.bfmt(buf[:], "{D}", d)) + eq("1969-01-01 00:00:00 +0000", std.bfmt(buf[:], "{D}", d)) d = date.addperiod(d, `date.Day 365) - eq("1970-1-01 00:00:00 +0000", std.bfmt(buf[:], "{D}", d)) + eq("1970-01-01 00:00:00 +0000", std.bfmt(buf[:], "{D}", d)) d = date.addperiod(d, `date.Year 2) - eq("1972-1-01 00:00:00 +0000", std.bfmt(buf[:], "{D}", d)) + eq("1972-01-01 00:00:00 +0000", std.bfmt(buf[:], "{D}", d)) d = date.addperiod(d, `date.Day 365) eq("1972-12-31 00:00:00 +0000", std.bfmt(buf[:], "{D}", d)) @@ -66,7 +66,7 @@ const main = { for var i = 0; i < 50; i++ d = date.addperiod(d, `date.Day 1) d = date.addperiod(d, `date.Second 1) - s = std.fmt("1970-{}-{p=0,w=2} 12:{p=0,w=2}:{p=0,w=2} +0000", \ + s = std.fmt("1970-{p=0,w=2}-{p=0,w=2} 12:{p=0,w=2}:{p=0,w=2} +0000", \ (i+1)/31 + 1, (i+1)%31+1, (i+13)/60, (i+13)%60) eq(s, std.bfmt(buf[:], "{D}", d)) std.slfree(s) diff --git a/lib/date/test/parse.myr b/lib/date/test/parse.myr index 6bc7347..dc34707 100644 --- a/lib/date/test/parse.myr +++ b/lib/date/test/parse.myr @@ -24,7 +24,7 @@ const main = { match date.parsefmtz("%Y-%m-%d %H:%M:%S %z", "1969-12-31 16:00:00 -0800", "") | `std.Ok d: std.assert(d.actual == 0, "got wrong date") - eq(std.bfmt(buf[:], "{D}", d), "1970-1-01 00:00:00 +0000") + eq(std.bfmt(buf[:], "{D}", d), "1970-01-01 00:00:00 +0000") | `std.Err m: std.fatal("failed to parse date: {}\n", m) ;; @@ -37,6 +37,15 @@ const main = { | `std.Err m: std.fatal("Failed to parse date: {}", m) ;; + + /*Names*/ + match date.parsefmt("%a, %d %b %Y %H:%M:%S %z", "Thu, 21 Sep 2017 13:55:05 -0400") + | `std.Ok d: + std.assert(d.actual == 1506016505 * 1_000_000, "wrong timestamp") + eq(std.bfmt(buf[:], "{D}", d), "2017-09-21 13:55:05 -0400") + | `std.Err m: + std.fatal("Failed to parse date: {}", m) + ;; } const eq = {actual, expected diff --git a/lib/fileutil/bld.sub b/lib/fileutil/bld.sub index 8971630..e54f88d 100644 --- a/lib/fileutil/bld.sub +++ b/lib/fileutil/bld.sub @@ -1,6 +1,10 @@ lib fileutil = walk.myr homedir.myr + tmpdir.myr + + loopcheck+posixy.myr + loopcheck+plan9.myr lib ../sys:sys lib ../std:std diff --git a/lib/fileutil/loopcheck+plan9.myr b/lib/fileutil/loopcheck+plan9.myr new file mode 100644 index 0000000..9b5584b --- /dev/null +++ b/lib/fileutil/loopcheck+plan9.myr @@ -0,0 +1,21 @@ +use std + +/* plan 9 can't have directory loops, by construction, so this is nops */ +pkg fileutil = + type loopcheck = void + + const mkloopcheck : (cwd : byte[:] -> loopcheck) + const freeloopcheck : (l : loopcheck -> void) + const looped : (l : loopcheck, p : byte[:] -> bool) +;; + +const mkloopcheck = {cwd + -> (void : loopcheck) +} + +const freeloopcheck = {l +} + +const looped = {l, p + -> false +} diff --git a/lib/fileutil/loopcheck+posixy.myr b/lib/fileutil/loopcheck+posixy.myr new file mode 100644 index 0000000..784fe3f --- /dev/null +++ b/lib/fileutil/loopcheck+posixy.myr @@ -0,0 +1,65 @@ +use std +use sys + +/* plan 9 can't have directory loops, by construction, so this is nops */ +pkg fileutil = + type loopcheck = std.htab((int64, int64), void)# + + const mkloopcheck : (cwd : byte[:] -> loopcheck) + const freeloopcheck : (l : loopcheck -> void) + const looped : (l : loopcheck, p : byte[:] -> bool) +;; + +const mkloopcheck = {cwd + var ht : std.htab((int64, int64), void)# + var l + + ht = std.mkht(fidhash, fideq) + l = (ht : loopcheck) + looped(l, cwd) + -> l +} + +const freeloopcheck = {l + std.htfree((l : std.htab((int64, int64), void)#)) +} + +const looped = {l, p + var ht, has + + ht = (l : std.htab((int64, int64), void)#) + match fid(p) + | `std.Err e: + -> false + | `std.Ok id: + has = std.hthas(ht, id) + std.htput(ht, id, void) + -> has + ;; +} + +const fid = {p + var sb + + if sys.stat(p, &sb) != 0 + -> `std.Err void + else + -> `std.Ok ((sb.dev : int64), (sb.ino : int64)) + ;; +} + +const fidhash = {fid + var dev, ino + + (dev, ino) = fid + -> std.inthash(dev) ^ std.inthash(ino) +} + +const fideq = {a, b + var adev, aino + var bdev, bino + + (adev, aino) = a + (bdev, bino) = b + -> adev == bdev && aino == bino +} diff --git a/lib/fileutil/tmpdir.myr b/lib/fileutil/tmpdir.myr new file mode 100644 index 0000000..786a151 --- /dev/null +++ b/lib/fileutil/tmpdir.myr @@ -0,0 +1,12 @@ +use std + +pkg fileutil = + const tmpdir : (-> byte[:]) +;; + +const tmpdir = { + match std.getenv("TMPDIR") + | `std.Some d: -> d + | `std.None: -> "/tmp" + ;; +} diff --git a/lib/fileutil/walk.myr b/lib/fileutil/walk.myr index 75ed5e2..dbdfb5f 100644 --- a/lib/fileutil/walk.myr +++ b/lib/fileutil/walk.myr @@ -1,18 +1,33 @@ use std +use "loopcheck" + pkg fileutil = type walkiter = struct dirstk : std.dir#[:] curdir : byte[:][:] - iterdir : bool + loopck : loopcheck ;; impl iterable walkiter -> byte[:] - const bywalk : (dir : std.dir# -> walkiter) + const bywalk : (dir : byte[:] -> walkiter) ;; -const bywalk = {d - -> [.dirstk = std.sldup([d][:]), .curdir = std.sldup([""][:])] +const bywalk = {p + match std.diropen(p) + | `std.Ok d: + -> [ + .dirstk = std.sldup([d][:]), + .curdir = std.sldup([std.sldup(p)][:]), + .loopck = mkloopcheck(p), + ] + | `std.Err e: + -> [ + .dirstk = [][:], + .curdir = [][:], + .loopck = mkloopcheck(p), + ] + ;; } impl iterable walkiter -> byte[:] = @@ -20,34 +35,38 @@ impl iterable walkiter -> byte[:] = var cur, p :nextfile + if itp.dirstk.len < 1 + freeloopcheck(itp.loopck) + -> false + ;; cur = itp.dirstk[itp.dirstk.len - 1] match std.dirread(cur) | `std.Some ".": goto nextfile | `std.Some "..": goto nextfile | `std.Some ent: p = std.pathcat(itp.curdir[itp.curdir.len - 1], ent) + if looped(itp.loopck, p) + std.slfree(p) + goto nextfile + ;; if std.fisdir(p) match std.diropen(p) - | `std.Ok d: std.slpush(&itp.dirstk, d) + | `std.Ok d: + std.slpush(&itp.dirstk, d) + std.slpush(&itp.curdir, p) | `std.Err e: /* ? */ + std.slfree(p) ;; - std.slpush(&itp.curdir, p) goto nextfile - else - valp# = p ;; + valp# = p -> true | `std.None: - /* don't close the directory given to us by the user */ - if itp.dirstk.len > 1 - std.dirclose(itp.dirstk[itp.dirstk.len - 1]) - std.slfree(itp.curdir[itp.curdir.len - 1]) - std.slpop(&itp.curdir) - std.slpop(&itp.dirstk) - goto nextfile - else - -> false - ;; + std.dirclose(cur) + std.slfree(itp.curdir[itp.curdir.len - 1]) + std.slpop(&itp.curdir) + std.slpop(&itp.dirstk) + goto nextfile ;; } diff --git a/lib/http/bld.sub b/lib/http/bld.sub new file mode 100644 index 0000000..0c4834b --- /dev/null +++ b/lib/http/bld.sub @@ -0,0 +1,34 @@ +bin h {noinst}= + h.myr + + lib http + lib ../sys:sys + lib ../std:std + lib ../bio:bio + lib ../thread:thread +;; + +bin srvdot {noinst}= + srvdot.myr + + lib http + lib ../sys:sys + lib ../std:std + lib ../bio:bio + lib ../thread:thread +;; + +lib http = + parse.myr + types.myr + url.myr + client.myr + server.myr + session.myr + status.myr + + lib ../sys:sys + lib ../std:std + lib ../bio:bio + lib ../thread:thread +;; diff --git a/lib/http/client.myr b/lib/http/client.myr new file mode 100644 index 0000000..770c233 --- /dev/null +++ b/lib/http/client.myr @@ -0,0 +1,276 @@ +use std +use bio + +use "types" +use "session" +use "parse" + +pkg http = + /* simple versions */ + const get : (s : session#, r : url# -> std.result(resp#, err)) + const head : (s : session#, r : url# -> std.result(resp#, err)) + const put : (s : session#, r : url#, data : byte[:] -> std.result(resp#, err)) + const post : (s : session#, r : url#, data : byte[:] -> std.result(resp#, err)) + const delete : (s : session#, r : url# -> std.result(resp#, err)) + const options : (s : session#, r : url# -> std.result(resp#, err)) + const trace : (s : session#, r : url# -> std.result(resp#, err)) + + /* request based versions */ + const getreq : (s : session#, r : req# -> std.result(resp#, err)) + const headreq : (s : session#, r : req# -> std.result(resp#, err)) + const putreq : (s : session#, r : req#, data : byte[:] -> std.result(resp#, err)) + const postreq : (s : session#, r : req#, data : byte[:] -> std.result(resp#, err)) + const deletereq : (s : session#, r : req# -> std.result(resp#, err)) + const optionsreq : (s : session#, r : req# -> std.result(resp#, err)) + const tracereq : (s : session#, r : req# -> std.result(resp#, err)) + + const freeresp : (r : resp# -> void) +;; + +const get = {s, path; -> getreq(s, &[.url=path])} +const head = {s, path; -> headreq(s, &[.url=path])} +const put = {s, path, data; -> putreq(s, &[.url=path], data)} +const post = {s, path, data; -> postreq(s, &[.url=path], data)} +const delete = {s, path; -> deletereq(s, &[.url=path])} +const options = {s, path; -> optionsreq(s, &[.url=path])} +const trace = {s, path; -> tracereq(s, &[.url=path])} + + +const getreq = {s, r + match request(s, `Get, r, `std.None) + | `std.Ok _: /* nothing */ + | `std.Err e: -> `std.Err e + ;; + + -> response(s, true) +} + +const headreq = {s, r + match request(s, `Head, r, `std.None) + | `std.Ok _: /* nothing */ + | `std.Err e: -> `std.Err e + ;; + + -> response(s, false) +} + +const putreq = {s, r, data + match request(s, `Put, r, `std.Some data) + | `std.Ok _: /* nothing */ + | `std.Err e: -> `std.Err e + ;; + + -> response(s, true) +} + +const postreq = {s, r, data + match request(s, `Post, r, `std.Some data) + | `std.Ok _: /* nothing */ + | `std.Err e: -> `std.Err e + ;; + + -> response(s, true) +} + +const deletereq = {s, r + match request(s, `Delete, r, `std.None) + | `std.Ok _: /* nothing */ + | `std.Err e: -> `std.Err e + ;; + + -> response(s, true) +} + +const optionsreq = {s, r + match request(s, `Options, r, `std.None) + | `std.Ok _: /* nothing */ + | `std.Err e: -> `std.Err e + ;; + + -> response(s, true) +} + +const tracereq = {s, r + match request(s, `Trace, r, `std.None) + | `std.Ok _: /* nothing */ + | `std.Err e: -> `std.Err e + ;; + + -> response(s, true) +} + +const response = {s, body + var resp + + resp = std.mk([ + .hdrs = [][:], + .len = 0, + .err = `std.None, + .reason = "", + .status = 0, + .enc = `Length, + ]) + + if parseresp(s, resp) + if !body + -> `std.Ok resp + else + match readbody(s, resp) + | `std.Ok buf: resp.body = buf + | `std.Err e: -> `std.Err e + ;; + ;; + else + match resp.err + | `std.Some e: -> `std.Err e + | `std.None: -> `std.Err `Ewat + ;; + ;; + -> `std.Ok resp +} + +const request = {s, method, r, data + /* status */ + ioput(s, "{} {p} HTTP/1.1\r\n", method, r.url) + + /* headers */ + ioput(s, "Host: {}\r\n", s.host) + ioput(s, "User-Agent: {}\r\n", s.ua) + match data + | `std.Some d: ioput(s, "Content-Length: {}\r\n", d.len) + | `std.None: /* nothing to do */ + ;; + for (k, v) : r.hdrs + ioput(s, "{}: {}\r\n", k, v) + ;; + ioput(s, "\r\n") + + /* body */ + match data + | `std.None: /* nothing to do */ + | `std.Some d: + iowrite(s, d) + ioput(s, "\r\n") + ;; + ioflush(s) + + if s.err + -> `std.Err `Econn + else + -> `std.Ok void + ;; + +} + +const readbody = {s, r -> std.result(byte[:], err) + match r.enc + | `Length: -> readlenbody(s, r) + | `Chunked: -> readchunkedbody(s, r) + | badenc: std.fatal("unsupported encoding {}\n", badenc) + ;; +} + +const readlenbody = {s, r + var buf + + buf = "" + if r.len == 0 + -> `std.Ok buf + ;; + + buf = std.slalloc(r.len) + match bio.read(s.f, buf) + | `std.Err e: goto shortread + | `std.Ok rd: + if rd.len != r.len + goto shortread + ;; + ;; + -> `std.Ok buf +:shortread + std.slfree(buf) + -> `std.Err `Eshort +} + +const __init__ = { + var m + + m = `Get + std.fmtinstall(std.typeof(m), fmtmethod, [][:]) +} + +const readchunkedbody = {s, r + var buf, len + + buf = "" + len = 0 + while true + match parsechunksz(s) + | `std.Err e: + std.slfree(buf) + -> `std.Err e + | `std.Ok 0: + break + | `std.Ok sz: + std.slgrow(&buf, buf.len + sz) + match bio.read(s.f, buf[len:len + sz]) + | `std.Err e: + std.slfree(buf) + -> `std.Err `Econn + | `std.Ok str: + if str.len != sz + std.slfree(buf) + -> `std.Err `Eshort + ;; + len += sz + match checkendln(s) + | `std.Ok _: /* nothing */ + | `std.Err e: + std.slfree(buf) + -> `std.Err e + ;; + ;; + ;; + ;; + -> `std.Ok buf +} + +const checkendln = {s + var r + + match bio.readln(s.f) + | `std.Err e: r = `std.Err `Econn + | `std.Ok crlf: + if std.strstrip(crlf).len == 0 + r = `std.Ok void + else + r = `std.Err `Eproto + ;; + std.slfree(crlf) + ;; + -> r +} + +const fmtmethod = {sb, ap, opt + var r + + r = std.vanext(ap) + match r + | `Get: std.sbputs(sb, "GET") + | `Head: std.sbputs(sb, "HEAD") + | `Put: std.sbputs(sb, "PUT") + | `Post: std.sbputs(sb, "POST") + | `Delete: std.sbputs(sb, "DELETE") + | `Trace: std.sbputs(sb, "TRACE") + | `Options: std.sbputs(sb, "OPTIONS") + ;; +} + +const freeresp = {r + for (k, v) : r.hdrs + std.slfree(k) + std.slfree(v) + ;; + std.slfree(r.reason) + std.free(r) +} diff --git a/lib/http/h.myr b/lib/http/h.myr new file mode 100644 index 0000000..9a00e2e --- /dev/null +++ b/lib/http/h.myr @@ -0,0 +1,90 @@ +use std +use http + +const main = {args + var data, method, showhdr, hdrs, out + var s, u, r + var cmd + + cmd = std.optparse(args, &[ + .argdesc = "url...", + .minargs = 1, + .opts = [ + [.opt='m', .arg="method", .desc="http method to use"], + [.opt='d', .arg="data", .desc="data to put in request body"], + [.opt='o', .arg="out", .desc="output file name"], + [.opt='H', .desc="show headers"], + [.opt='D', .arg="hdr", .desc="define custom header"] + ][:] + ]) + + showhdr = false + method = "get" + data = "" + hdrs = [][:] + out = "" + for opt : cmd.opts + match opt + | ('m', m): method = m + | ('d', d): data = d + | ('o', o): out = o + | ('H', ""): showhdr = true + | ('D', def): parsedef(&hdrs, def) + | _: std.die("unreachable") + ;; + ;; + + for url : cmd.args + if !std.hasprefix(url, "http") + url = std.fmt("http://{}", url) + ;; + u = std.try(http.parseurl(url)) + s = std.try(http.mksession(u.schema, u.host, u.port)) + + match method + | "get": r = http.getreq(s, &[.url=u, .hdrs=hdrs]) + | "head": r = http.headreq(s, &[.url=u, .hdrs=hdrs]) + | "delete": r = http.deletereq(s, &[.url=u, .hdrs=hdrs]) + | "trace": r = http.tracereq(s, &[.url=u, .hdrs=hdrs]) + | "options": r = http.optionsreq(s, &[.url=u, .hdrs=hdrs]) + | "put": r = http.putreq(s, &[.url=u, .hdrs=hdrs], data) + | "post": r = http.postreq(s, &[.url=u, .hdrs=hdrs], data) + | unknown: std.fatal("unknown method '{}'\n", unknown) + ;; + + match r + | `std.Ok resp: + if showhdr + std.put("status: {}\n", resp.status) + for (k, v) : resp.hdrs + std.put("{}: {}\n", k, v) + ;; + ;; + if out.len != 0 + if !std.blat(out, resp.body, 0o644) + std.fatal("could not write output: {}\n", out) + ;; + else + std.fblat(std.Out, resp.body) + ;; + http.freeresp(resp) + | `std.Err e: + std.put("{}\n", e) + ;; + http.urlfree(u) + ;; +} + +const parsedef = {hdrs, hdr + var key, val + + match std.strfind(hdr, ":") + | `std.None: + std.fatal("bad header string {}\n", hdr) + | `std.Some idx: + key = std.sldup(std.strstrip(hdr[:idx])) + val = std.sldup(std.strstrip(hdr[idx+1:])) + std.slpush(hdrs, (key, val)) + ;; +} + diff --git a/lib/http/parse.myr b/lib/http/parse.myr new file mode 100644 index 0000000..fabf7a2 --- /dev/null +++ b/lib/http/parse.myr @@ -0,0 +1,278 @@ +use std +use bio + +use "types" + +pkg http = + pkglocal const parsereq : (s : session# -> std.result(req#, err)) + pkglocal const parseresp : (s : session#, r : resp# -> bool) + pkglocal const parsechunksz : (s : session# -> std.result(std.size, err)) + pkglocal const parsenumber : (str : byte[:]#, base : int -> std.option(int)) +;; + +const parsereq = {s + var r, err + + r.hdrs = [][:] + r.url = std.mk([ + .schema=`Http, + .host=std.sldup(s.host), + .port=s.port, + .path="", + .params=[][:], + ]) + + match bio.readln(s.f) + | `std.Err e: + err = `Econn + goto error + | `std.Ok ln: + match parsereqstatus(s, r, ln) + | `std.Ok void: + | `std.Err e: + std.slfree(ln) + err = e + -> `std.Err e + ;; + std.slfree(ln) + ;; + + while true + match bio.readln(s.f) + | `std.Err e: + err = `Econn + goto error + | `std.Ok ln: + if std.strstrip(ln).len == 0 + std.slfree(ln) + break + ;; + match parsehdr(s, ln) + | `std.Ok kvp: + std.slpush(&r.hdrs, kvp) + | `std.Err e: + std.slfree(ln) + -> `std.Err e + ;; + std.slfree(ln) + ;; + ;; + -> `std.Ok std.mk(r) +:error + -> `std.Err err +} + +const parseresp = {s, r : resp# + match bio.readln(s.f) + | `std.Err _: r.err = `std.Some `Econn + | `std.Ok ln: + if !parserespstatus(s, r, ln) + std.slfree(ln) + -> false + ;; + std.slfree(ln) + ;; + + while true + match bio.readln(s.f) + | `std.Err e: r.err = `std.Some `Econn + | `std.Ok ln: + if std.strstrip(ln).len == 0 + std.slfree(ln) + break + ;; + match parsehdr(s, ln) + | `std.Ok kvp: + std.slpush(&r.hdrs, kvp) + | `std.Err e: + r.err = `std.Some e + std.slfree(ln) + -> false + ;; + std.slfree(ln) + ;; + ;; + + match getenc(r) + | `std.Ok `Length: + r.enc = `Length + match getlen(r) + | `std.Some n: + r.len = n + | `std.None: + r.err = `std.Some `Eproto + -> false + ;; + | `std.Ok enc: + r.enc = enc + | `std.Err e: + r.err = `std.Some e + -> false + ;; + -> true + +} + +const parsereqstatus = {s, r, ln + match parseword(&ln) + | `std.Some "GET": r.method = `Get + | `std.Some "HEAD": r.method = `Head + | `std.Some "POST": r.method = `Post + | `std.Some "DELETE": r.method = `Delete + | `std.Some "TRACE": r.method = `Trace + | `std.Some "OPTIONS": r.method = `Options + | `std.Some _: -> `std.Err `Eproto + | `std.None: -> `std.Err `Eproto + ;; + + match parseword(&ln) + | `std.Some w: r.url.path = std.sldup(w) + | `std.None: -> `std.Err `Eproto + ;; + + match parseword(&ln) + | `std.Some "HTTP/1.1": /* ok */ + | `std.Some w: std.put("warn: http version '{}'\n", w) + | `std.None: -> `std.Err `Eproto + ;; + + ln = std.strfstrip(ln) + -> `std.Ok void +} + +const parserespstatus = {s, r, ln + /* HTTP/1.1 */ + ln = std.strfstrip(ln) + if !std.chomp(&ln, "HTTP") + r.err = `std.Some `Eproto + -> false + ;; + if !std.chomp(&ln, "/1.1") + r.err = `std.Some `Eproto + -> false + ;; + + ln = std.strfstrip(ln) + match parsenumber(&ln, 10) + | `std.Some n: + r.status = n + | `std.None: + r.err = `std.Some `Eproto + -> false + ;; + + ln = std.strfstrip(ln) + r.reason = std.sldup(ln) + -> true +} + +const parsehdr = {s, ln + var key, val + + match std.strfind(ln, ":") + | `std.Some idx: + key = std.sldup(std.strstrip(ln[:idx])) + val = std.sldup(std.strstrip(ln[idx+1:])) + -> `std.Ok (key, val) + | `std.None: + -> `std.Err `Ehdr + ;; +} + +const getlen = {r + match findhdr(r, "Content-Length") + | `std.Some v: + match std.intparsebase(v, 10) + | `std.Some n: -> `std.Some n + | `std.None: -> `std.None + ;; + | `std.None: + -> `std.None + ;; +} + +const parsechunksz = {s + var ret, str + + match bio.readln(s.f) + | `std.Err e: ret = `std.Err `Econn + | `std.Ok ln: + str = ln + match parsenumber(&str, 16) + | `std.Some n: ret = `std.Ok (n : std.size) + | `std.None: + ret = `std.Err `Eproto + ;; + std.slfree(ln) + ;; + -> ret +} + +const getenc = {r + match findhdr(r, "Transfer-Encoding") + | `std.None: -> `std.Ok `Length + | `std.Some "chunked": -> `std.Ok `Chunked + | `std.Some "compress": -> `std.Ok `Compress + | `std.Some "deflate": -> `std.Ok `Deflate + | `std.Some "gzip": -> `std.Ok `Gzip + | `std.Some unknown: -> `std.Err `Eenc + ;; +} + +const findhdr = {r, name + for (k, v) : r.hdrs + if std.strcaseeq(k, name) + -> `std.Some v + ;; + ;; + -> `std.None +} + +const parseword = {ln + var w, end + + ln# = std.strfstrip(ln#) + end = 0 + for var i = 0; i < ln#.len; i++ + if i == ln#.len - 1 + end = i + 1 + elif std.isspace(std.decode(ln#[i:])) + end = i + break + ;; + ;; + if end == 0 + -> `std.None + else + w = ln#[:end] + ln# = ln#[end:] + -> `std.Some w + ;; +} + +const parsenumber = {ln, base + var n, ok + var c, s, dig + + n = 0 + s = ln# + ok = false + while true + (c, s) = std.strstep(s) + dig = std.charval(c, base) + if dig >= 0 && dig < base + ok = true + n *= base + n += dig + else + break + ;; + ;; + ln# = s + if ok + -> `std.Some n + else + -> `std.None + ;; +} + diff --git a/lib/http/server.myr b/lib/http/server.myr new file mode 100644 index 0000000..0cfdcb0 --- /dev/null +++ b/lib/http/server.myr @@ -0,0 +1,100 @@ +use bio +use std +use thread + +use "types" +use "session" +use "parse" + +pkg http = + const announce : (ds : byte[:] -> std.result(server#, err)) + const shutdown : (srv : server# -> void) + const serve : (srv : server#, fn : (srv : server#, s : session#, req : req# -> void) -> void) + const respond : (srv : server#, sess : session#, resp : resp# -> void) +;; + +const announce = {ds + match std.announce(ds) + | `std.Err e: -> `std.Err `Econn + | `std.Ok a: + -> `std.Ok std.mk([ + .refs=1, + .ann=a, + .quit=false + ]) + ;; +} + +const serve = {srv, fn + while !srv.quit + match waitconn(srv) + | `std.Ok fd: + ref(srv) + thread.spawn({;communicate(srv, fd, fn)}) + | `std.Err e: /* eh? */ + ;; + ;; + unref(srv) +} + +const communicate = {srv, fd, fn + var s + + s = mksrvsession(fd) + while !srv.quit + match parsereq(s) + | `std.Ok req: fn(srv, s, req) + | `std.Err e: break + ;; + ;; + std.close(fd) + unref(srv) +} + +const respond = {srv, s, resp + var sb + + sb = std.mksb() + ioput(s, "HTTP/1.1 {} {}\r\n", resp.status, statusstr(resp.status)) + ioput(s, "Content-Length: {}\r\n", resp.body.len) + ioput(s, "Encoding: {}\r\n", resp.enc) + for (k, v) : resp.hdrs + ioput(s, "{}: {}\r\n", k, v) + ;; + ioput(s, "\r\n") + iowrite(s, resp.body) + ioflush(s) +} + +const statusstr = {st + match st + | 200: -> "OK" + | 404: -> "Not Found" + | 503: -> "Internal Error" + | _: -> "Bad State" + ;; +} + +const shutdown = {srv + std.aclose(srv.ann) + srv.quit = true +} + +const waitconn = {srv + match std.accept(srv.ann) + | `std.Ok fd: -> `std.Ok fd + | `std.Err e: -> `std.Err `Econn + ;; +} + + +const ref = {srv + thread.xadd(&srv.refs, 1) +} + +const unref = {srv + thread.xadd(&srv.refs, -1) + if thread.xget(&srv.refs) == 0 + std.free(srv) + ;; +} diff --git a/lib/http/session.myr b/lib/http/session.myr new file mode 100644 index 0000000..4091165 --- /dev/null +++ b/lib/http/session.myr @@ -0,0 +1,80 @@ +use std +use bio + +use "types" + +pkg http = + const mksession : (schema : schema, host : byte[:], port : uint16 -> std.result(session#, err)) + const mksrvsession : (fd : std.fd -> session#) + const freesession : (s : session# -> void) + + pkglocal const ioput : (s : session#, fmt : byte[:], args : ... -> bool) + pkglocal const iowrite : (s : session#, buf : byte[:] -> bool) + pkglocal const ioflush : (s : session# -> void) +;; + +const mksession = {schema, host, port + var s, sess + + match schema + | `Http: /* nothing */ + | `Https: std.fatal("unsupported protocol\n") + ;; + + s = std.fmt("tcp!{}!{}", host, port) + match std.dial(s) + | `std.Err e: sess = `std.Err `Econn + | `std.Ok fd: sess = `std.Ok std.mk([ + .err = false, + .ua = std.sldup("Myrfoo HTTP"), + .host = std.sldup(host), + .f = bio.mkfile(fd, bio.Rw) + ]) + ;; + std.slfree(s) + -> sess +} + +const mksrvsession = {fd + -> std.mk([ + .err = false, + .srvname = std.sldup("Myrfoo HTTP Server"), + .f = bio.mkfile(fd, bio.Rw), + ]) +} + +const freesession = {s + bio.close(s.f) + std.slfree(s.host) + std.slfree(s.ua) + std.free(s) +} + +const ioput = {s, fmt, args + var ap + + if s.err + -> false + ;; + ap = std.vastart(&args) + match bio.putv(s.f, fmt, &ap) + | `std.Ok _: /* nothing */ + | `std.Err _: s.err = true + ;; + -> s.err +} + +const iowrite = {s, buf + if s.err + -> false + ;; + match bio.write(s.f, buf) + | `std.Ok _: /* nothing */ + | `std.Err _: s.err = true + ;; + -> s.err +} + +const ioflush = {s + bio.flush(s.f) +} diff --git a/lib/http/srvdot.myr b/lib/http/srvdot.myr new file mode 100644 index 0000000..e6c0a21 --- /dev/null +++ b/lib/http/srvdot.myr @@ -0,0 +1,66 @@ +use std +use http + +const main = {args + var srv, ann, cmd + + cmd = std.optparse(args, &[ + .maxargs=0, + .opts = [[.opt='a', .arg="ann", .desc="announce on `ann`"]][:] + ]) + ann = "tcp!localhost!8080" + for opt : cmd.opts + match opt + | ('a', a): ann = a + | _: std.die("unreachable") + ;; + ;; + + match http.announce(ann) + | `std.Ok s: srv = s + | `std.Err e: std.fatal("unable to announce: {}\n", e) + ;; + + http.serve(srv, route) +} + +const route = {srv, sess, req + std.put("Reading path {}\n", req.url.path) + match req.url.path + | "/ping": respond(srv, sess, 200, "pong") + | "/quit": http.shutdown(srv) + | fspath: showfile(srv, sess, req.url.path) + ;; +} + +const showfile = {srv, sess, path + var eb : byte[128] + var p + + p = std.pathcat(".", path) + match std.slurp(p) + | `std.Ok buf: + respond(srv, sess, 200, buf) + std.slfree(buf) + | `std.Err e: + respond(srv, sess, 404, std.bfmt(eb[:], "error reading {}: {}\n", p, e)) + ;; + std.slfree(p) +} + + +const respond = {srv, sess, status, body + var resp + + resp = std.mk([ + .status=status, + .hdrs = [][:], + .len = 0, + .err = `std.None, + .reason = "", + .body = body, + .enc = `http.Length + ]) + http.respond(srv, sess, resp) + std.free(resp) +} diff --git a/lib/http/status.myr b/lib/http/status.myr new file mode 100644 index 0000000..df247be --- /dev/null +++ b/lib/http/status.myr @@ -0,0 +1,67 @@ +use "types" + +pkg http = + const Continue : status = 100 /* RFC 7231, 6.2.1*/ + const SwitchingProtocols : status = 101 /* RFC 7231, 6.2.2*/ + const Processing : status = 102 /* RFC 2518, 10.1*/ + + const Ok : status = 200 /* RFC 7231, 6.3.1*/ + const Created : status = 201 /* RFC 7231, 6.3.2*/ + const Accepted : status = 202 /* RFC 7231, 6.3.3*/ + const NonAuthoritativeInfo : status = 203 /* RFC 7231, 6.3.4*/ + const NoContent : status = 204 /* RFC 7231, 6.3.5*/ + const ResetContent : status = 205 /* RFC 7231, 6.3.6*/ + const PartialContent : status = 206 /* RFC 7233, 4.1*/ + const Multi : status = 207 /* RFC 4918, 11.1*/ + const AlreadyReported : status = 208 /* RFC 5842, 7.1*/ + const IMUsed : status = 226 /* RFC 3229, 10.4.1*/ + + const MultipleChoices : status = 300 /* RFC 7231, 6.4.1*/ + const MovedPermanently : status = 301 /* RFC 7231, 6.4.2*/ + const Found : status = 302 /* RFC 7231, 6.4.3*/ + const SeeOther : status = 303 /* RFC 7231, 6.4.4*/ + const NotModified : status = 304 /* RFC 7232, 4.1*/ + const UseProxy : status = 305 /* RFC 7231, 6.4.5*/ + const TemporaryRedirect : status = 307 /* RFC 7231, 6.4.7*/ + const PermanentRedirect : status = 308 /* RFC 7538, 3*/ + + const BadRequest : status = 400 /* RFC 7231, 6.5.1*/ + const Unauthorized : status = 401 /* RFC 7235, 3.1*/ + const PaymentRequired : status = 402 /* RFC 7231, 6.5.2*/ + const Forbidden : status = 403 /* RFC 7231, 6.5.3*/ + const NotFound : status = 404 /* RFC 7231, 6.5.4*/ + const MethodNotAllowed : status = 405 /* RFC 7231, 6.5.5*/ + const NotAcceptable : status = 406 /* RFC 7231, 6.5.6*/ + const ProxyAuthRequired : status = 407 /* RFC 7235, 3.2*/ + const RequestTimeout : status = 408 /* RFC 7231, 6.5.7*/ + const Conflict : status = 409 /* RFC 7231, 6.5.8*/ + const Gone : status = 410 /* RFC 7231, 6.5.9*/ + const LengthRequired : status = 411 /* RFC 7231, 6.5.10*/ + const PreconditionFailed : status = 412 /* RFC 7232, 4.2*/ + const RequestEntityTooLarge : status = 413 /* RFC 7231, 6.5.11*/ + const RequestURITooLong : status = 414 /* RFC 7231, 6.5.12*/ + const UnsupportedMediaType : status = 415 /* RFC 7231, 6.5.13*/ + const RangeNotSatisfiable : status = 416 /* RFC 7233, 4.4*/ + const ExpectationFailed : status = 417 /* RFC 7231, 6.5.14*/ + const Teapot : status = 418 /* RFC 7168, 2.3.3*/ + const UnprocessableEntity : status = 422 /* RFC 4918, 11.2*/ + const Locked : status = 423 /* RFC 4918, 11.3*/ + const FailedDependency : status = 424 /* RFC 4918, 11.4*/ + const UpgradeRequired : status = 426 /* RFC 7231, 6.5.15*/ + const PreconditionRequired : status = 428 /* RFC 6585, 3*/ + const TooManyRequests : status = 429 /* RFC 6585, 4*/ + const HeaderFieldsTooLarge : status = 431 /* RFC 6585, 5*/ + const UnavailableForLegal : status = 451 /* RFC 7725, 3*/ + + const InternalServerError : status = 500 /* RFC 7231, 6.6.1*/ + const NotImplemented : status = 501 /* RFC 7231, 6.6.2*/ + const BadGateway : status = 502 /* RFC 7231, 6.6.3*/ + const ServiceUnavailable : status = 503 /* RFC 7231, 6.6.4*/ + const GatewayTimeout : status = 504 /* RFC 7231, 6.6.5*/ + const VersionNotSupported : status = 505 /* RFC 7231, 6.6.6*/ + const VariantAlsoNegotiates : status = 506 /* RFC 2295, 8.1*/ + const InsufficientStorage : status = 507 /* RFC 4918, 11.5*/ + const LoopDetected : status = 508 /* RFC 5842, 7.2*/ + const NotExtended : status = 510 /* RFC 2774, 7*/ + const NetworkAuthRequired : status = 511 /* RFC 6585, 6*/ +;; diff --git a/lib/http/types.myr b/lib/http/types.myr new file mode 100644 index 0000000..68e2c28 --- /dev/null +++ b/lib/http/types.myr @@ -0,0 +1,83 @@ +use std +use bio + +pkg http = + type status = int + + type session = struct + f : bio.file# + host : byte[:] + port : uint16 + srvname : byte[:] + ua : byte[:] + err : bool + ;; + + + type server = struct + ann : std.announce# + refs : uint32 + quit : bool + ;; + + type url = struct + schema : schema + port : uint16 + host : byte[:] + path : byte[:] + params : (byte[:], byte[:])[:] + ;; + + type err = union + `Ehttp int /* http error */ + `Eunsupp /* unsupported feature */ + `Econn /* connection lost */ + `Ehdr /* invalid header */ + `Eproto /* protocol error */ + `Eshort /* truncated response */ + `Egarbled /* syntax error */ + `Eenc /* encoding error */ + `Ewat /* unknown error */ + ;; + + type schema = union + `Http + `Https + ;; + + type method = union + `Get + `Head + `Put + `Post + `Delete + `Trace + `Options + ;; + + type encoding = union + `Length + `Chunked + `Compress + `Deflate + `Gzip + ;; + + type req = struct + url : url# + hdrs : (byte[:], byte[:])[:] + err : std.option(err) + method : method + ;; + + type resp = struct + status : int + hdrs : (byte[:], byte[:])[:] + len : std.size + err : std.option(err) + reason : byte[:] + body : byte[:] + enc : encoding + ;; + +;; diff --git a/lib/http/url.myr b/lib/http/url.myr new file mode 100644 index 0000000..be17d20 --- /dev/null +++ b/lib/http/url.myr @@ -0,0 +1,238 @@ +use std + +use "types" +use "parse" + +pkg http = + const parseurl : (url : byte[:] -> std.result(url#, err)) + const urlfree : (url : url# -> void) +;; + +const __init__ = { + var u : url# + + u = u + std.fmtinstall(std.typeof(u), urlfmt, [ + ("p", false) + ][:]) +} + +const urlfmt = {sb, ap, opts + var url : url# + var defaultport + var sep + var showhost + + showhost = true + url = std.vanext(ap) + for o : opts + match o + | ("p", ""): showhost = false + | _: std.fatal("unknown param\n") + ;; + ;; + + if showhost + match url.schema + | `Http: + std.sbputs(sb, "http://") + defaultport = 80 + | `Https: + std.sbputs(sb, "https://") + defaultport = 443 + ;; + + std.sbputs(sb, url.host) + if url.port != defaultport + std.sbfmt(sb, ":{}", url.port) + ;; + ;; + + std.sbfmt(sb, url.path) + + if url.params.len > 0 + sep = '?' + for (k, v) : url.params + std.sbfmt(sb, "{}{}={}", sep, k, v) + sep = '&' + ;; + ;; +} + +const parseurl = {url + var schema, host, port, path, params + + match parseschema(&url) + | `std.Ok s: schema = s + | `std.Err e: -> `std.Err e + ;; + + match parsehostname(&url) + | `std.Ok h: host = h + | `std.Err e: -> `std.Err e + ;; + + match parseport(&url) + | `std.Ok p: port = p + | `std.Err e: -> `std.Err e + ;; + + match parsepath(&url) + | `std.Ok p: path = p + | `std.Err e: -> `std.Err e + ;; + + match parseparams(&url) + | `std.Ok p: params = p + | `std.Err e: -> `std.Err e + ;; + + /* todo: params */ + -> `std.Ok std.mk([ + .schema=schema, + .host=std.sldup(host), + .port=port, + .path=std.sldup(path), + .params=params, + ]) +} + +const urlfree = {url + std.slfree(url.host) + std.slfree(url.path) + std.free(url) +} + +const parseschema = {url + if std.chomp(url, "http://") + -> `std.Ok `Http + elif std.chomp(url, "https://") + -> `std.Err `Eunsupp + else + -> `std.Err `Eproto + ;; +} + +const parsehostname = {url + if std.chomp(url, "[") + -> ipv6hostname(url) + else + -> hostname(url) + ;; +} + +const parsepath = {url + var len, p + + if url#.len == 0 + -> `std.Ok "/" + elif std.decode(url#) == '?' + -> `std.Ok "/" + elif std.decode(url#) == '/' + match std.strfind(url#, "?") + | `std.Some i: len = i + | `std.None: len = url#.len + ;; + p = url#[:len] + url# = url#[len:] + -> `std.Ok p + else + -> `std.Err `Egarbled + ;; +} + +const parseparams = {url + var kvp : byte[:][2] + var params + + if url#.len == 0 + -> `std.Ok [][:] + ;; + + match std.decode(url#) + | '?': (_, url#) = std.strstep(url#) + | _: -> `std.Err `Egarbled + ;; + + params = [][:] + for sp : std.bysplit(url#, "&") + if std.bstrsplit(kvp[:], sp, "=").len != 2 + -> `std.Err `Egarbled + ;; + std.slpush(¶ms, (std.sldup(kvp[0]), std.sldup(kvp[1]))) + ;; + + -> `std.Ok params +} + +const hostname = {url + var len, host + + len = 0 + for c : std.bychar(url#) + match c + | ':': break + | '/': break + | '?': break + | chr: + if ishostchar(chr) + len += std.charlen(chr) + else + -> `std.Err `Egarbled + ;; + ;; + ;; + + host = url#[:len] + url# = url#[len:] + -> `std.Ok host +} + +const ipv6hostname = {url -> std.result(byte[:], err) + var ip + + match std.strfind(url#, "]") + | `std.None: -> `std.Err `Egarbled + | `std.Some idx: + ip = url#[:idx] + url# = url#[idx+1:] + match std.ip6parse(url#[:idx]) + | `std.Some _: -> `std.Ok ip + | `std.None: -> `std.Err `Egarbled + ;; + ;; +} + +const parseport = {url + if std.chomp(url, ":") + match parsenumber(url, 10) + | `std.None: -> `std.Err `Egarbled + | `std.Some n: + if n > 65535 + -> `std.Err `Egarbled + else + -> `std.Ok (n : uint16) + ;; + ;; + else + -> `std.Ok 80 + ;; +} + +const ishostchar = {c + if !std.isascii(c) + -> false + else + -> std.isalnum(c) || unreserved(c) || subdelim(c) + ;; +} + +const unreserved = {c + -> c == '.' || c == '-' || c == '_' || c == '~' +} + +const subdelim = {c + -> c == '.' || c == '-' || c == '_' || c == '~' || c == '!' || \ + c == '$' || c == '&' || c == '\'' || c == '(' || c == ')' || \ + c == '*' || c == '+' || c == ',' || c == ';' || c == '=' +} diff --git a/lib/inifile/parse.myr b/lib/inifile/parse.myr index e2490c2..6b9be91 100644 --- a/lib/inifile/parse.myr +++ b/lib/inifile/parse.myr @@ -18,7 +18,7 @@ type parser = struct ;; const load = {path - match std.open(path, std.Ordonly) + match std.open(path, std.Oread) | `std.Ok fd: -> loadf(fd) | `std.Err e: -> `std.Err `Fileerr ;; @@ -54,13 +54,13 @@ const loadf = {fd f = bio.mkfile(fd, bio.Rd) while true match bio.readln(f) - | `bio.Eof: + | `std.Err `bio.Eof: break - | `bio.Ok ln: + | `std.Ok ln: if !parseline(p, ini, ln) break ;; - | `bio.Err e: + | `std.Err e: p.err = `std.Some `Fileerr break ;; diff --git a/lib/inifile/write.myr b/lib/inifile/write.myr index 1c7071d..ab4042c 100644 --- a/lib/inifile/write.myr +++ b/lib/inifile/write.myr @@ -53,7 +53,7 @@ const writeini = {f, ini val = std.htgetv(ini.elts, (sect, key), "") match bio.put(f, "\t{} = {}\n", key, val) - | `bio.Err e: -> false + | `std.Err e: -> false | _: ;; ;; diff --git a/lib/regex/interp.myr b/lib/regex/interp.myr index c7e8514..3856c57 100644 --- a/lib/regex/interp.myr +++ b/lib/regex/interp.myr @@ -127,7 +127,7 @@ const sbsuball = {sb, re, str, subst std.sbputb(sb, str[i]) i++ else - len = thr.mend[0] + len = thr.mgroup[0][1] s = str[i:len + i] dosubst(sb, re, thr, s, subst) i += len @@ -142,10 +142,10 @@ const dosubst = {sb, re, thr, str, subst off = 0 for var i = 1; i < re.nmatch; i++ - if thr.mstart[i] != -1 && thr.mend[i] != -1 - std.sbputs(sb, str[off:thr.mstart[i]]) + if thr.mgroup[i][0] != -1 && thr.mgroup[i][1] != -1 + std.sbputs(sb, str[off:thr.mgroup[i][0]]) std.sbputs(sb, subst[i - 1]) - off = thr.mend[i] + off = thr.mgroup[i][1] ;; ;; std.sbputs(sb, str[off:]) @@ -164,7 +164,10 @@ const cleanup = {re next = thr.next thrfree(re, thr) ;; + re.runq = Zthr + re.expired = Zthr re.nexttid = 0 + re.nthr = 0 } const matchfree = {m @@ -179,8 +182,8 @@ const getmatches = {re, thr ;; ret = std.slalloc(re.nmatch) for var i = 0; i < re.nmatch; i++ - if thr.mstart[i] != -1 && thr.mend[i] != -1 - ret[i] = re.str[thr.mstart[i]:thr.mend[i]] + if thr.mgroup[i][0] != -1 && thr.mgroup[i][1] != -1 + ret[i] = re.str[thr.mgroup[i][0]:thr.mgroup[i][1]] else ret[i] = [][:] ;; @@ -197,8 +200,8 @@ const getidxmatches = {re, thr ;; ret = std.slalloc(re.nmatch) for var i = 0; i < re.nmatch; i++ - if thr.mstart[i] != -1 && thr.mend[i] != -1 - ret[i] = (thr.mstart[i], thr.mend[i]) + if thr.mgroup[i][0] != -1 && thr.mgroup[i][1] != -1 + ret[i] = (thr.mgroup[i][0], thr.mgroup[i][1]) else ret[i] = (-1, -1) ;; @@ -230,11 +233,10 @@ const run = {re, str, idx, wholestr re.traces = [][:] std.slpush(&re.traces, std.mkbs()) ;; - re.runq.mstart = std.slalloc(re.nmatch) - re.runq.mend = std.slalloc(re.nmatch) + re.runq.mgroup = std.slalloc(re.nmatch) for var i = 0; i < re.nmatch; i++ - re.runq.mstart[i] = -1 - re.runq.mend[i] = -1 + re.runq.mgroup[i][0] = -1 + re.runq.mgroup[i][1] = -1 ;; while re.nthr > 0 while re.runq != Zthr @@ -299,8 +301,7 @@ const run = {re, str, idx, wholestr */ const step = {re, thr, curip var str - var mstart - var mend + var mgroup str = re.str match re.prog[thr.ip] @@ -372,22 +373,21 @@ const step = {re, thr, curip | `Ilbra m: trace(re, thr, "\t{}:\tLbra {}\n", thr.ip, m) trace(re, thr, "\t\tmatch start = {}\n", re.strp) - thr.mstart[m] = re.strp + thr.mgroup[m][0] = re.strp hit(re, thr) thr.ip++ -> false | `Irbra m: trace(re, thr, "\t{}:\tRbra {}\n", thr.ip, m) - thr.mend[m] = re.strp + thr.mgroup[m][1] = re.strp hit(re, thr) thr.ip++ -> false | `Ifork (lip, rip): trace(re, thr, "\t{}:\tFork ({}, {})\n", thr.ip, lip, rip) - mstart = std.sldup(thr.mstart) - mend = std.sldup(thr.mend) + mgroup = std.sldup(thr.mgroup) hit(re, thr) - fork(re, rip, curip, mstart, mend) + fork(re, rip, curip, mgroup) if re.debug std.slpush(&re.traces, std.bsdup(re.traces[thr.tid])) ;; @@ -407,7 +407,7 @@ const step = {re, thr, curip -> true } -const fork = {re, ip, curip, mstart, mend +const fork = {re, ip, curip, mgroup var thr if ip == curip /* loop detection */ @@ -415,8 +415,7 @@ const fork = {re, ip, curip, mstart, mend ;; thr = mkthread(re, ip) thr.next = re.runq - thr.mstart = mstart - thr.mend = mend + thr.mgroup = mgroup re.runq = thr } @@ -455,8 +454,7 @@ const mkthread = {re, ip thr.dead = false thr.matched = false - thr.mstart = [][:] - thr.mend = [][:] + thr.mgroup = [][:] re.nthr++ @@ -465,8 +463,7 @@ const mkthread = {re, ip const thrfree = {re, thr trace(re, thr, "\t\tcleanup {}\n", thr.tid) - std.slfree(thr.mstart) - std.slfree(thr.mend) + std.slfree(thr.mgroup) std.free(thr) } diff --git a/lib/regex/myr-regex.3 b/lib/regex/myr-regex.3 index 6e8f018..46bb998 100644 --- a/lib/regex/myr-regex.3 +++ b/lib/regex/myr-regex.3 @@ -167,17 +167,18 @@ Space separator unicode property use regex const main = { - match regex.compile(pat) var i - | `std.Success re: + + match regex.compile(pat) + | `std.Ok re: match regex.exec(re, text) | `std.Some matches: for i = 0; i < matches.len; i++ - std.put("Match %i: %s\n", i, match[i]) + std.put("Match {}: {}\n", i, matches[i]) ;; | `std.None: std.put("Text did not match\n") ;; - | `std.Failure err: + | `std.Err err: std.put("failed to compile regex") ;; } diff --git a/lib/regex/redump.myr b/lib/regex/redump.myr index e47b824..2cbb4ad 100644 --- a/lib/regex/redump.myr +++ b/lib/regex/redump.myr @@ -57,12 +57,12 @@ const runall = {re, files const dump = {re, fd while true match bio.readln(fd) - | `bio.Ok ln: + | `std.Ok ln: show(re, ln, regex.exec(re, ln)) std.slfree(ln) - | `bio.Eof: + | `std.Err `bio.Eof: break - | `bio.Err e: + | `std.Err e: std.put("error reading from input: {}", e) break ;; diff --git a/lib/regex/types.myr b/lib/regex/types.myr index 766105b..c21d474 100644 --- a/lib/regex/types.myr +++ b/lib/regex/types.myr @@ -68,8 +68,7 @@ pkg regex = dead : bool /* thread died */ matched : bool /* thread matched */ - mstart : std.size[:] /* match starts */ - mend : std.size[:] /* match ends */ + mgroup : std.size[2][:] /* match starts */ ;; pkglocal type reinst = union diff --git a/lib/std/bigint.myr b/lib/std/bigint.myr index 45170dd..129890c 100644 --- a/lib/std/bigint.myr +++ b/lib/std/bigint.myr @@ -28,6 +28,7 @@ pkg std = const bigdup : (a : bigint# -> bigint#) const bigassign : (d : bigint#, s : bigint# -> bigint#) const bigmove : (d : bigint#, s : bigint# -> bigint#) + const bigsteal : (d : bigint#, s : bigint# -> bigint#) const bigparse : (s : byte[:] -> option(bigint#)) const bigclear : (a : bigint# -> bigint#) const bigbfmt : (b : byte[:], a : bigint#, base : int -> size) @@ -162,6 +163,12 @@ const bigmove = {d, s -> d } +const bigsteal = {d, s + bigmove(d, s); + bigfree(s) + -> d +} + const bigclear = {v std.slfree(v.dig) v.sign = 0 @@ -547,7 +554,7 @@ const bigdiv = {a : bigint#, b : bigint# -> bigint# (q, r) = bigdivmod(a, b) bigfree(r) - -> bigmove(a, q) + -> bigsteal(a, q) } const bigmod = {a : bigint#, b : bigint# -> bigint# @@ -555,7 +562,7 @@ const bigmod = {a : bigint#, b : bigint# -> bigint# (q, r) = bigdivmod(a, b) bigfree(q) - -> bigmove(a, r) + -> bigsteal(a, r) } /* a /= b */ @@ -665,6 +672,7 @@ const bigdivmod = {a : bigint#, b : bigint# -> (bigint#, bigint#) /* undo the biasing for remainder */ bigshri(u, shift) trim(q) + bigfree(v) -> (trim(q), trim(u)) } @@ -698,7 +706,7 @@ const bigmodpow = {base, exp, mod bigmul(base, base) bigmod(base, mod) ;; - -> bigmove(base, r) + -> bigsteal(base, r) } /* returns the number of leading zeros */ diff --git a/lib/std/bitset.myr b/lib/std/bitset.myr index b173d87..afc66b4 100644 --- a/lib/std/bitset.myr +++ b/lib/std/bitset.myr @@ -30,7 +30,7 @@ pkg std = const bsunion : (a : bitset#, b : bitset# -> void) const bseq : (a : bitset#, b : bitset# -> bool) const bsissubset : (a : bitset#, b : bitset# -> bool) - const bshash : (a : bitset# -> uint32) + const bshash : (a : bitset# -> uint64) type bsiter = struct idx : size diff --git a/lib/std/blat.myr b/lib/std/blat.myr index c0e2b4b..f68f089 100644 --- a/lib/std/blat.myr +++ b/lib/std/blat.myr @@ -7,7 +7,7 @@ pkg std = ;; const blat = {path, buf, perm - match openmode(path, Ocreat|Owronly, perm) + match openmode(path, Ocreat|Owrite, perm) | `Ok fd: -> fblat(fd, buf) | `Err e: -> false ;; diff --git a/lib/std/bld.sub b/lib/std/bld.sub index b8ce9bc..a834dbb 100644 --- a/lib/std/bld.sub +++ b/lib/std/bld.sub @@ -108,6 +108,7 @@ lib std {inc=.} = env+posixy.myr errno+plan9.myr listen+posixy.myr + listen+plan9.myr resolve+plan9.myr resolve+posixy.myr wait+plan9.myr diff --git a/lib/std/bytealloc.myr b/lib/std/bytealloc.myr index 51c0a34..9b48acc 100644 --- a/lib/std/bytealloc.myr +++ b/lib/std/bytealloc.myr @@ -28,7 +28,7 @@ pkg std = const Zslab = (0 : slab#) const Zchunk = (0 : chunk#) -const Slabsz = 4*MiB +const Slabsz = 512*KiB const Cachemax = 4 const Bktmax = 128*KiB /* a balance between wasted space and falling back to mmap */ const Pagesz = 4*KiB @@ -71,7 +71,7 @@ const __init__ = { } const startalloctrace = {path - match openmode(path, Owronly | Ocreat, 0o644) + match openmode(path, Owrite | Ocreat, 0o644) | `Ok fd: tracefd = fd | `Err e: -> void ;; @@ -92,7 +92,7 @@ const zbytealloc = {sz } const tracealloc = {p, sz - var stk : void#[13] /* [type, addr, sz, 10 stack slots] */ + var stk : void#[23] /* [type, addr, sz, 10 stack slots] */ slfill(stk[:], (0 : void#)) stk[0] = (0 : void#) @@ -123,6 +123,7 @@ const writealloctrace = {sl const bytealloc = {sz var bkt, p + sz += 8 if sz <= Bktmax bkt = &buckets[bktnum(sz)] lock(memlck) @@ -142,7 +143,12 @@ const bytealloc = {sz /* frees a blob that is 'sz' bytes long. */ const bytefree = {p, sz var bkt + var v + if p == (0 : byte#) + -> void + ;; + v = ((p : size) + sz : uint32#)# if trace lock(memlck) tracefree(p, sz) @@ -253,7 +259,9 @@ const mkslab = {bkt s = bkt.cache bkt.cache = s.next bkt.ncache-- + -> s ;; + /* tricky: we need power of two alignment, so we allocate double the needed size, chop off the unaligned ends, and waste the address @@ -308,13 +316,12 @@ const bktalloc = {bkt b = s.freehd s.freehd = b.next s.nfree-- - if s.nfree == 0 + if s.freehd == Zchunk bkt.slabs = s.next if s.next != Zslab s.next.prev = Zslab ;; ;; - -> (b : byte#) } @@ -337,6 +344,16 @@ const bktfree = {bkt, m s.prev = Zslab bkt.slabs = s elif s.nfree == bkt.nper - 1 + /* unlink the slab from the list */ + if s.next != Zslab + s.next.prev = s.prev + ;; + if s.prev != Zslab + s.prev.next = s.next + ;; + if bkt.slabs == s + bkt.slabs = s.next + ;; /* HACK HACK HACK: if we can't unmap, keep an infinite cache per slab size. We should solve this better somehow. @@ -345,17 +362,8 @@ const bktfree = {bkt, m s.next = bkt.cache s.prev = Zslab bkt.cache = s + bkt.ncache++ else - /* unlink the slab from the list */ - if s.next != Zslab - s.next.prev = s.prev - ;; - if s.prev != Zslab - s.prev.next = s.next - ;; - if bkt.slabs == s - bkt.slabs = s.next - ;; /* we mapped 2*Slabsz so we could align it, so we need to unmap the same */ freemem(s.head, Slabsz*2) @@ -433,3 +441,4 @@ be a power of two. const mtrunc = {m, align -> ((m : intptr) & ~((align : intptr) - 1) : byte#) } + diff --git a/lib/std/dir+plan9.myr b/lib/std/dir+plan9.myr index e363662..82e301f 100644 --- a/lib/std/dir+plan9.myr +++ b/lib/std/dir+plan9.myr @@ -26,7 +26,7 @@ const diropen = {p var fd var dir - match open(p, Ordonly) + match open(p, Oread) | `Ok f: fd = f | `Err e: -> `Err "couldn't open directory" ;; diff --git a/lib/std/fltbits.myr b/lib/std/fltbits.myr index f9afd7a..0d7169b 100644 --- a/lib/std/fltbits.myr +++ b/lib/std/fltbits.myr @@ -48,12 +48,12 @@ const flt32explode = {flt bits = flt32bits(flt) isneg = (bits >> 31) != 0 /* msb is sign bit */ - exp = (bits >> 22) & 0xff /* exp is in bits [23..30] */ - mant = bits & ((1 << 22) - 1) /* msb is in bits [0..22] */ + exp = (bits >> 23) & 0xff /* exp is in bits [23..30] */ + mant = bits & ((1 << 23) - 1) /* msb is in bits [0..22] */ /* add back the implicit bit if this is not a denormal */ if exp != 0 - mant |= 1 << 22 + mant |= 1 << 23 else exp = 1 ;; diff --git a/lib/std/fltfmt.myr b/lib/std/fltfmt.myr index 71bb183..9b2e100 100644 --- a/lib/std/fltfmt.myr +++ b/lib/std/fltfmt.myr @@ -32,7 +32,7 @@ const flt32bfmt = {sb, val, mode, precision var isneg, exp, mant (isneg, mant, exp) = flt32explode(val) - dragon4(sb, isneg, (mant : int64), (exp - 52 : int64), Fltbias, mode, precision) + dragon4(sb, isneg, (mant : int64), (exp - 23 : int64), Fltbias, mode, precision) } /* @@ -52,10 +52,10 @@ const dragon4 = {sb, isneg, f, e, p, mode, cutoff var k var a, i - /* if we have zero for the mantissa, we can return early */ if isneg sbputs(sb, "-") ;; + /* if we have zero for the mantissa, we can return early */ if f == 0 sbputs(sb, "0.0") -> void @@ -63,12 +63,11 @@ const dragon4 = {sb, isneg, f, e, p, mode, cutoff /* initialize */ roundup = false - r = mkbigint(f) - r = bigshli(r, max(e - p, 0)) + u = mkbigint(0) + r = bigshli(mkbigint(f), max(e - p, 0)) s = bigshli(mkbigint(1), max(0, -(e - p))) mm = bigshli(mkbigint(1), max((e - p), 0)) mp = bigdup(mm) - u = mkbigint(0) /* fixup: unequal gaps */ t = mkbigint(1) @@ -224,10 +223,16 @@ const dragon4 = {sb, isneg, f, e, p, mode, cutoff ;; ;; k-- - while k >= -1 format(sb, 0, k--) ;; + + bigfree(u) + bigfree(r) + bigfree(s) + bigfree(mm) + bigfree(mp) + } const lowdig = {u diff --git a/lib/std/fltparse.myr b/lib/std/fltparse.myr index fcc97af..9836d1f 100644 --- a/lib/std/fltparse.myr +++ b/lib/std/fltparse.myr @@ -183,8 +183,8 @@ const fallback = {mant, exp, lim while true (xprime, rprime) = std.bigdivmod(u, v) - std.bigmove(x, xprime) - std.bigmove(r, rprime) + std.bigsteal(x, xprime) + std.bigsteal(r, rprime) if k == lim.minexp if std.biggei(x, lim.minsig) && std.biglei(x, lim.maxsig) break @@ -193,7 +193,8 @@ const fallback = {mant, exp, lim goto done ;; elif k > lim.maxexp - -> std.flt64inf() + f = std.flt64inf() + goto done ;; if std.biglti(x, lim.minsig) std.bigmuli(u, 2) diff --git a/lib/std/fmt.myr b/lib/std/fmt.myr index 11268e4..08b814d 100644 --- a/lib/std/fmt.myr +++ b/lib/std/fmt.myr @@ -481,11 +481,13 @@ const intparams = {params ] opts = parseparams(params, [ + ("b", true), ("x", false), ("w", true), ("p", true)][:]) for o : opts match o + | ("b", bas): ip.base = getint(bas, "fmt: base must be integer") | ("x", ""): ip.base = 16 | ("w", wid): ip.padto = getint(wid, "fmt: width must be integer") | ("p", pad): ip.padfill = decode(pad) diff --git a/lib/std/hashfuncs.myr b/lib/std/hashfuncs.myr index 3046377..da47215 100644 --- a/lib/std/hashfuncs.myr +++ b/lib/std/hashfuncs.myr @@ -1,30 +1,32 @@ use "alloc" use "chartype" use "die" +use "getint" use "sleq" use "slpush" use "types" use "utf" pkg std = - const strhash : (s : byte[:] -> uint32) + const strhash : (s : byte[:] -> uint64) const streq : (a : byte[:], b : byte[:] -> bool) - const strcasehash : (s : byte[:] -> uint32) + const strcasehash : (s : byte[:] -> uint64) const strcaseeq : (a : byte[:], b : byte[:] -> bool) - generic ptrhash : (p : @a# -> uint32) + generic ptrhash : (p : @a# -> uint64) generic ptreq : (a : @a#, b : @a# -> bool) - generic inthash : (v : @a::(integral,numeric) -> uint32) + generic inthash : (v : @a::(integral,numeric) -> uint64) generic inteq : (a : @a::(integral,numeric), b : @a::(integral,numeric) -> bool) const murmurhash2 : (data : byte[:], seed : uint32 -> uint32) + const siphash24 : (data : byte[:], seed : byte[16] -> uint64) - generic slhash : (sl : @a[:] -> uint32) + generic slhash : (sl : @a[:] -> uint64) ;; -const Seed = 1234 +const Seed : byte[16] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] generic slhash = {data : @a[:] -> strhash(slbytes(data)) @@ -38,7 +40,7 @@ generic slbytes = {data : @a[:] } const strhash = {s - -> murmurhash2(s, Seed) + -> siphash24(s, Seed) } const strcaseeq = {a, b @@ -66,7 +68,7 @@ const strcasehash = {s (c, s) = std.strstep(s) std.slpush(&chars, std.tolower(c)) ;; - h = murmurhash2(slbytes(chars), Seed) + h = siphash24(slbytes(chars), Seed) slfree(chars) -> h } @@ -76,10 +78,7 @@ const streq = {a, b } generic ptrhash = {p : @a# - var x - - x = (&p : byte#) - -> murmurhash2(x[0:sizeof(@a#)], Seed) + -> inthash((p : intptr)) } generic ptreq = {a, b @@ -90,7 +89,7 @@ generic inthash = {v : @a::(integral,numeric) var p p = (&v : byte#) - -> murmurhash2(p[0:sizeof(@a)], Seed) + -> siphash24(p[0:sizeof(@a)], Seed) } generic inteq = {a, b @@ -141,3 +140,59 @@ const murmurhash2 = {data, seed -> h } + +const sipround = {v0, v1, v2, v3 -> (uint64, uint64, uint64, uint64) + v0 += v1 + v1 = (v1 << 13) | (v1 >> 51) + v1 ^= v0 + v0 = (v0 << 32) | (v0 >> 32) + v2 += v3 + v3 = (v3 << 16) | (v3 >> 48) + v3 ^= v2 + + v2 += v1 + v1 = (v1 << 17) | (v1 >> 47) + v1 ^= v2 + v2 = (v2 << 32) | (v2 >> 32) + v0 += v3 + v3 = (v3 << 21) | (v3 >> 43) + v3 ^= v0 + + -> (v0, v1, v2, v3) +} + +const siphash24 = {data, seed + var k0, k1, m, v0, v1, v2, v3, w + var tail : byte[8] = [0, 0, 0, 0, 0, 0, 0, 0] + + k0 = std.getle64(seed[0:8]) + k1 = std.getle64(seed[8:16]) + v0 = k0 ^ 0x736f6d6570736575 + v1 = k1 ^ 0x646f72616e646f6d + v2 = k0 ^ 0x6c7967656e657261 + v3 = k1 ^ 0x7465646279746573 + w = (data.len + 8) / 8 - 1 + for var i = 0; i < w; i++ + m = std.getle64(data[8 * i:8 * (i + 1)]) + v3 ^= m + (v0, v1, v2, v3) = sipround(v0, v1, v2, v3) + (v0, v1, v2, v3) = sipround(v0, v1, v2, v3) + v0 ^= m + ;; + for var i = 0; i < data.len % 8; i++ + tail[i] = data[8 * w + i] + ;; + tail[7] = (data.len % 256 : byte) + m = std.getle64(tail[:]) + v3 ^= m + (v0, v1, v2, v3) = sipround(v0, v1, v2, v3) + (v0, v1, v2, v3) = sipround(v0, v1, v2, v3) + v0 ^= m + + v2 ^= 0xff + (v0, v1, v2, v3) = sipround(v0, v1, v2, v3) + (v0, v1, v2, v3) = sipround(v0, v1, v2, v3) + (v0, v1, v2, v3) = sipround(v0, v1, v2, v3) + (v0, v1, v2, v3) = sipround(v0, v1, v2, v3) + -> v0 ^ v1 ^ v2 ^ v3 +} diff --git a/lib/std/htab.myr b/lib/std/htab.myr index ec4ce72..b728124 100644 --- a/lib/std/htab.myr +++ b/lib/std/htab.myr @@ -6,19 +6,19 @@ use "types" pkg std = type htab(@k, @v) = struct - hash : (k : @k -> uint32) + hash : (k : @k -> uint64) eq : (a : @k, b : @k -> bool) nelt : size ndead : size keys : @k[:] vals : @v[:] - hashes : uint32[:] + hashes : uint64[:] dead : bool[:] ;; - generic mkht : (h : (k : @k -> uint32), eq : (a : @k, b : @k -> bool) -> htab(@k, @v)#) - generic htinit : (ht : htab(@k, @v)#, h : (k : @k -> uint32), eq : (a : @k, b : @k -> bool) -> void) + generic mkht : (h : (k : @k -> uint64), eq : (a : @k, b : @k -> bool) -> htab(@k, @v)#) + generic htinit : (ht : htab(@k, @v)#, h : (k : @k -> uint64), eq : (a : @k, b : @k -> bool) -> void) generic htfree : (ht : htab(@k, @v)# -> void) generic htput : (ht : htab(@k, @v)#, k : @k, v : @v -> void) generic htdel : (ht : htab(@k, @v)#, k : @k -> void) diff --git a/lib/std/listen+plan9.myr b/lib/std/listen+plan9.myr new file mode 100644 index 0000000..be82bcf --- /dev/null +++ b/lib/std/listen+plan9.myr @@ -0,0 +1,175 @@ +use sys + +use "alloc" +use "cstrconv" +use "die" +use "dirname" +use "fmt" +use "mk" +use "option" +use "result" +use "sldup" +use "strfind" +use "syswrap" +use "utf" + + +pkg std = + type announce = struct + afd : fd + lpath : byte[:] + netdir : byte[:] + ;; + + const announce : (ds : byte[:] -> result(announce#, byte[:])) + const aclose : (a : announce# -> void) + const accept : (a : announce# -> result(fd, byte[:])) +;; + +const Maxpath = 256 + +const announce = {ds + var a, abuf : byte[Maxpath] + var f, fbuf : byte[Maxpath] + var nbuf : byte[32] + var dir, ctl, n + + /* announce */ + match translate(ds, abuf[:], fbuf[:]) + | `Err _: -> `Err "invalid dial string" + | `Ok (addr, file): + put("addr: {}, file: {}\n", addr, file) + a = addr + f = file + match strrfind(f, "/") + | `Some i: dir = i + | `None: -> `Err "invalid net dir" + ;; + ;; + + match open(f, Ordwr) + | `Ok fd: ctl = fd + | `Err e: -> `Err "could not open ctl fd" + ;; + + match read(ctl, nbuf[:]) + | `Err e: ->`Err "unable to read ctl fd" + | `Ok nn: + n = fput(ctl, "announce {}", a) + if n <= 0 + close(ctl) + -> `Err "writing announce" + ;; + + -> `std.Ok mk([ + .afd=ctl, + .lpath = fmt("{}/{}/listen", f[:dir], nbuf[:nn]), + .netdir = sldup(f[:dir]), + ]) + ;; + +} + +const aclose = {a + slfree(a.netdir) + slfree(a.lpath) + close(a.afd) + free(a) +} + +const accept = {a -> result(fd, byte[:]) + var num, numbuf : byte[16] + var dat, datbuf : byte[Maxpath] + var lfd + + match open(a.lpath, Ordwr) + | `Err e: -> `Err "could not open ctl" + | `Ok fd: lfd = fd + ;; + + match read(lfd, numbuf[:]) + | `Ok n: num = numbuf[:n] + | `Err e: -> `Err "could not accept" + ;; + + dat = bfmt(datbuf[:], "{}/{}/data", a.netdir, num) + match open(dat, Ordwr) + | `Ok fd: -> `Ok fd + | `Err e: -> `Err "could not open data fd" + ;; +} + +const translate = {ds, addrbuf, filebuf + var cs, csbuf : byte[Maxpath] + var r, rbuf : byte[Maxpath] + var netdir, rest + var addr, file + + match strfind(ds, "!") + | `None: -> `Err void + | `Some sep: + if decode(ds[:sep]) == '#' || decode(ds[:sep]) == '/' + match strrfind(ds[:sep], "/") + | `None: -> `Err void + | `Some idx: + netdir = ds[:idx] + rest = ds[idx+1:] + ;; + else + netdir = "/net" + addr = ds + ;; + ;; + + cs = bfmt(csbuf[:], "{}/cs", netdir) + match open(cs, Ordwr) + | `Err e: -> identtrans(rest, netdir, addrbuf, filebuf) + | `Ok fd: + match write(fd, addr) + | `Err e: + close(fd) + -> `Err void + | `Ok _: + ;; + + seek(fd, 0, Seekset) + match read(fd, rbuf[:]) + | `Err e: + close(fd) + -> `Err void + | `Ok n: + r = rbuf[:n] + ;; + close(fd) + ;; + + put("cs returned: {}\n", r) + match strfind(r, " ") + | `None: -> `Err void + | `Some i: + addr = bfmt(addrbuf, "{}", r[i+1:]) + if decode(r) == '/' + match strfind(r[:i], "/") + | `None: -> `Err void + | `Some 0: file = bfmt(filebuf, "{}{}", netdir, r[:i]) + | `Some n: file = bfmt(filebuf, "{}{}", netdir, r[n+1:]) + ;; + else + file = bfmt(filebuf, "{}/{}", netdir, r[:i]) + ;; + ;; + -> `Ok (addr, file) +} + +const identtrans = {ds, netdir, addrbuf, filebuf + var a, f + + match strfind(ds, "!") + | `None: + -> `Err void + | `Some sep: + a = bfmt(addrbuf, "{}", ds[sep + 1:]) + f = bfmt(filebuf, "{}/{}/clone", netdir, ds[:sep]) + -> `Ok (a, f) + ;; +} diff --git a/lib/std/listen+posixy.myr b/lib/std/listen+posixy.myr index be4456d..49d1054 100644 --- a/lib/std/listen+posixy.myr +++ b/lib/std/listen+posixy.myr @@ -5,6 +5,7 @@ use "chartype" use "dialparse" use "die" use "endian" +use "mk" use "option" use "resolve" use "result" @@ -16,9 +17,14 @@ use "syswrap" use "utf" pkg std = - const announce : (ds : byte[:] -> result(fd, byte[:])) - const listen : (sock : fd -> result(fd, byte[:])) - const accept : (lfd : fd -> result(fd, byte[:])) + type announce = struct + lfd : fd + ;; + + const announce : (ds : byte[:] -> result(announce#, byte[:])) + const aclose : (a : announce# -> void) + + const accept : (a : announce# -> result(fd, byte[:])) ;; const announce = {ds @@ -31,6 +37,11 @@ const announce = {ds ;; } +const aclose = {a + close(a.lfd) + free(a) +} + const announcesock = {proto, str var sa4 : sys.sockaddr_in var sa6 : sys.sockaddr_in6 @@ -80,7 +91,10 @@ const announcesock = {proto, str if sys.bind(sock, sa, sz) < 0 -> `Err "failed to bind socket" ;; - -> `Ok (sock : fd) + if sys.listen((sock : sys.fd), 10) < 0 + -> `Err "unable to listen on socket" + ;; + -> `Ok mk([.lfd=(sock : fd)]) } const announceunix = {path @@ -106,23 +120,19 @@ const announceunix = {path if sys.bind(sock, (&sa : sys.sockaddr#), sizeof(sys.sockaddr_un)) < 0 -> `Err "failed to bind address" ;; - -> `Ok (sock : fd) - -} - -const listen = {sock : std.fd -> result(fd, byte[:]) if sys.listen((sock : sys.fd), 10) < 0 -> `Err "unable to listen on socket" ;; - -> `Ok (sys.dup((sock : sys.fd)) : fd) + -> `Ok mk([.lfd=(sock : fd)]) + } -const accept = {lfd +const accept = {a var sa : sys.sockaddr_storage var len : sys.size var fd - fd = sys.accept((lfd : sys.fd), (0 : sys.sockaddr#), (0 : sys.size#)) + fd = sys.accept((a.lfd : sys.fd), (0 : sys.sockaddr#), (0 : sys.size#)) if fd < 0 -> `Err "unable to accept socket" ;; diff --git a/lib/std/mkpath.myr b/lib/std/mkpath.myr index 61e2a72..22d1d3d 100644 --- a/lib/std/mkpath.myr +++ b/lib/std/mkpath.myr @@ -10,9 +10,11 @@ const mkpath = {p for var i = 0; i < p.len; i++ if p[i] == ('/' : byte) && i != 0 - st = mkdir(p[:i], 0o755) - if st != 0 && st != Eexist - -> st + if !fexists(p[:i]) + st = mkdir(p[:i], 0o755) + if st != 0 + -> st + ;; ;; ;; ;; diff --git a/lib/std/mktemp.myr b/lib/std/mktemp.myr index c5f06c8..bc1bf87 100644 --- a/lib/std/mktemp.myr +++ b/lib/std/mktemp.myr @@ -15,6 +15,8 @@ use "types" pkg std = const mktemp : (base : byte[:], opt : fdopt, mode : int64 -> std.result((fd, byte[:]), errno)) const mktempat : (dir : byte[:], base : byte[:], opt : fdopt, mode : int64 -> std.result((fd, byte[:]), errno)) + const mkdtemp : (base : byte[:], mode : int64 -> std.result(byte[:], errno)) + const mkdtempat : (dir : byte[:], base : byte[:], mode : int64 -> std.result(byte[:], errno)) const mktemppath : (base : byte[:] -> byte[:]) ;; @@ -51,6 +53,36 @@ const mktempat = {tmpdir, base, opt, mode -> `Err Eexist } +const mkdtemp = {base, mode + var tmpdir + + match std.getenv("TMPDIR") + | `std.Some d: tmpdir = d + | `std.None: tmpdir = "/tmp" + ;; + + -> mkdtempat(tmpdir, base, mode) +} + +const mkdtempat = {tmpdir, base, mode + var path + + for var i = 0; i < Retries; i++ + path = randpath(tmpdir, base) + match std.mkdir(path, mode) + | Enone: + -> `Ok path + | e: + if e != Eexist + std.slfree(path) + -> `Err e + ;; + ;; + std.slfree(path) + ;; + -> `Err Eexist +} + const mktemppath = {base var tmpdir, path diff --git a/lib/std/resolve+posixy.myr b/lib/std/resolve+posixy.myr index 06250d5..8fa8352 100644 --- a/lib/std/resolve+posixy.myr +++ b/lib/std/resolve+posixy.myr @@ -333,7 +333,7 @@ const rquery = {srv, host, id pfd = [ [.fd=srv, .events=sys.Pollin, .revents=0] ][:] - r = sys.poll(pfd[:], (std.now() - giveup : int)/1000) + r = sys.poll(pfd[:], (giveup - std.now() : int)/1000) if r < 0 -> `Err `Badconn elif r == 0 diff --git a/lib/std/slurp.myr b/lib/std/slurp.myr index a966e4a..8e653f9 100644 --- a/lib/std/slurp.myr +++ b/lib/std/slurp.myr @@ -15,7 +15,7 @@ const Bufstart = 4096 const slurp = {path var sl - match open(path, Ordonly) + match open(path, Oread) | `Err e: -> `Err e | `Ok fd: sl = fslurp(fd) diff --git a/lib/std/syswrap+plan9.myr b/lib/std/syswrap+plan9.myr index ddf37ab..9f0ccc9 100644 --- a/lib/std/syswrap+plan9.myr +++ b/lib/std/syswrap+plan9.myr @@ -27,8 +27,8 @@ pkg std = const Failmem : byte# = (-1 : byte#) - const Ordonly : fdopt = (sys.Ordonly : fdopt) - const Owronly : fdopt = (sys.Owronly : fdopt) + const Oread : fdopt = (sys.Oread : fdopt) + const Owrite : fdopt = (sys.Owrite : fdopt) const Ordwr : fdopt = (sys.Ordwr : fdopt) const Otrunc : fdopt = (sys.Otrunc : fdopt) const Ocexec : fdopt = (sys.Ocexec : fdopt) @@ -198,7 +198,7 @@ const chdir = {path; -> sys.chdir(path) == 0} const mkdir = {path, mode; var fd - fd = sys.create(path, sys.Ordonly, sys.Dmdir | (mode : int)) + fd = sys.create(path, sys.Oread, sys.Dmdir | (mode : int)) if fd < 0 -> lasterr() ;; diff --git a/lib/std/syswrap+posixy.myr b/lib/std/syswrap+posixy.myr index 5766a00..f49f9b8 100644 --- a/lib/std/syswrap+posixy.myr +++ b/lib/std/syswrap+posixy.myr @@ -25,12 +25,13 @@ pkg std = const Seekcur : whence = (sys.Seekcur : whence) const Seekend : whence = (sys.Seekend : whence) - const Ordonly : fdopt = (sys.Ordonly : fdopt) - const Owronly : fdopt = (sys.Owronly : fdopt) + const Oread : fdopt = (sys.Ordonly : fdopt) + const Owrite : fdopt = (sys.Owronly : fdopt) const Ordwr : fdopt = (sys.Ordwr : fdopt) const Ocreat : fdopt = (sys.Ocreat : fdopt) const Otrunc : fdopt = (sys.Otrunc : fdopt) const Ocexec : fdopt = (sys.Ocloexec : fdopt) + const Oappend : fdopt = (sys.Oappend : fdopt) const Odir : fdopt = (sys.Odir : fdopt) /* fd stuff */ diff --git a/lib/std/syswrap-ss+plan9.myr b/lib/std/syswrap-ss+plan9.myr index 96a2973..58a751a 100644 --- a/lib/std/syswrap-ss+plan9.myr +++ b/lib/std/syswrap-ss+plan9.myr @@ -22,7 +22,7 @@ const nanosleep = {nsecs const bgetcwd = {buf var fd - fd = sys.open(".", sys.Ordonly) + fd = sys.open(".", sys.Oread) if fd < 0 -> (fd : errno) ;; diff --git a/lib/std/test/bitset.myr b/lib/std/test/bitset.myr index 9112537..6936cba 100644 --- a/lib/std/test/bitset.myr +++ b/lib/std/test/bitset.myr @@ -49,11 +49,11 @@ const main = { }], [.name="hash", .fn={ctx var bs = mkset([][:]) - testr.check(ctx, std.bshash(bs) == 2580988821, "wrong hash, got {}", std.bshash(bs)) + testr.check(ctx, std.bshash(bs) == 0x726fdb47dd0e0e31, "wrong hash, got {}", std.bshash(bs)) std.bsput(bs, 123456) - testr.check(ctx, std.bshash(bs) == 2020624217, "wrong hash, got {}", std.bshash(bs)) + testr.check(ctx, std.bshash(bs) == 0x778abc1d7706143b, "wrong hash, got {}", std.bshash(bs)) std.bsdel(bs, 123456) - testr.check(ctx, std.bshash(bs) == 2580988821, "wrong hash, got {}", std.bshash(bs)) + testr.check(ctx, std.bshash(bs) == 0x726fdb47dd0e0e31, "wrong hash, got {}", std.bshash(bs)) std.bsfree(bs) }] ][:]) diff --git a/lib/std/test/fmt.myr b/lib/std/test/fmt.myr index 67ba2e4..5d0cfa8 100644 --- a/lib/std/test/fmt.myr +++ b/lib/std/test/fmt.myr @@ -62,6 +62,7 @@ const builtins = { check("0x7b", "0x{x}", 123) check("0.0", "{}", 0.0) check("0.3", "{}", 0.3) + check("0.3", "{}", (0.3 : flt32)) check("1.0", "{}", 1.0) check("100.0", "{}", 100.0) check("666.91972", "{}", 666.91972) diff --git a/lib/std/test/hashfuncs.myr b/lib/std/test/hashfuncs.myr index d2b1161..f1684f9 100644 --- a/lib/std/test/hashfuncs.myr +++ b/lib/std/test/hashfuncs.myr @@ -1,24 +1,113 @@ use std +use testr const main = { - var x, y: int + testr.run([ + [.name="string hash and equality", .fn={ctx + testr.check(ctx, std.strhash("abc") == 0x5dbcfa53aa2007a5, "wrong hash\n") + testr.check(ctx, std.streq("abc\0def", "abc\0def"), "equal strings not equal\n") + testr.check(ctx, !std.streq("abc\0def", "abcdef"), "unequal strings are equal\n") + }], + [.name="case insensitive hash and equality", .fn={ctx + testr.check(ctx, std.strcasehash("abc") == std.strcasehash("AbC"), "wrong case insensitive hash\n") + testr.check(ctx, std.strcaseeq("abc", "AbC"), "equal case insensitive strings not equal") + testr.check(ctx, !std.strcaseeq("abc", "AbCd"), "unequal case insensitive strings equal") + }], + [.name="pointer equality", .fn={ctx + var x, y: int + /* can't sanely test ptrhash; it will change every time */ + testr.check(ctx, std.ptreq(&x, &x), "equal pointers not equal") + testr.check(ctx, !std.ptreq(&x, &y), "unequal pointers are equal") + }], + [.name="int hash and equality", .fn={ctx + testr.check(ctx, std.inthash(123) == 0x5671db246859d5b6, "wrong int hash") + testr.check(ctx, std.inteq(123, 123), "equal integers not equal") + testr.check(ctx, !std.inteq(123, 456), "unequal integers are equal") + }], + [.name="murmurhash test", .fn={ctx + testr.check(ctx, std.murmurhash2("foobar", 1234) == 2203212445, "wrong murmurhash value") + }], + [.name="siphash test", .fn={ctx + siphashreferencetestvector(ctx) + }], + ][:]) - std.assert(std.strhash("abc") == 1241861192, "wrong hash\n") - std.assert(std.streq("abc\0def", "abc\0def"), "equal strings not equal\n") - std.assert(!std.streq("abc\0def", "abcdef"), "unstrings are equal\n") - - std.assert(std.strcasehash("abc") == std.strcasehash("AbC"), "wrong case insensitive hash\n") - std.assert(std.strcaseeq("abc", "AbC"), "equal case insensitive strings not equal") - std.assert(!std.strcaseeq("abc", "AbCd"), "unequal case insensitive strings equal") - - /* can't sanely test ptrhash; it will change every time */ - std.assert(std.ptreq(&x, &x), "equal pointers not equal") - std.assert(!std.ptreq(&x, &y), "unequal pointers are equal") - - std.assert(std.inthash(123) == 3497506805, "wrong int hash") - std.assert(std.inteq(123, 123), "equal integers not equal") - std.assert(!std.inteq(123, 456), "unequal integers are equal") +} - std.assert(std.murmurhash2("foobar", 1234) == 2203212445, "wrong murmurhash value") +const siphashtestvector : byte[8][64] = [ + [ 0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72, ], + [ 0xfd, 0x67, 0xdc, 0x93, 0xc5, 0x39, 0xf8, 0x74, ], + [ 0x5a, 0x4f, 0xa9, 0xd9, 0x09, 0x80, 0x6c, 0x0d, ], + [ 0x2d, 0x7e, 0xfb, 0xd7, 0x96, 0x66, 0x67, 0x85, ], + [ 0xb7, 0x87, 0x71, 0x27, 0xe0, 0x94, 0x27, 0xcf, ], + [ 0x8d, 0xa6, 0x99, 0xcd, 0x64, 0x55, 0x76, 0x18, ], + [ 0xce, 0xe3, 0xfe, 0x58, 0x6e, 0x46, 0xc9, 0xcb, ], + [ 0x37, 0xd1, 0x01, 0x8b, 0xf5, 0x00, 0x02, 0xab, ], + [ 0x62, 0x24, 0x93, 0x9a, 0x79, 0xf5, 0xf5, 0x93, ], + [ 0xb0, 0xe4, 0xa9, 0x0b, 0xdf, 0x82, 0x00, 0x9e, ], + [ 0xf3, 0xb9, 0xdd, 0x94, 0xc5, 0xbb, 0x5d, 0x7a, ], + [ 0xa7, 0xad, 0x6b, 0x22, 0x46, 0x2f, 0xb3, 0xf4, ], + [ 0xfb, 0xe5, 0x0e, 0x86, 0xbc, 0x8f, 0x1e, 0x75, ], + [ 0x90, 0x3d, 0x84, 0xc0, 0x27, 0x56, 0xea, 0x14, ], + [ 0xee, 0xf2, 0x7a, 0x8e, 0x90, 0xca, 0x23, 0xf7, ], + [ 0xe5, 0x45, 0xbe, 0x49, 0x61, 0xca, 0x29, 0xa1, ], + [ 0xdb, 0x9b, 0xc2, 0x57, 0x7f, 0xcc, 0x2a, 0x3f, ], + [ 0x94, 0x47, 0xbe, 0x2c, 0xf5, 0xe9, 0x9a, 0x69, ], + [ 0x9c, 0xd3, 0x8d, 0x96, 0xf0, 0xb3, 0xc1, 0x4b, ], + [ 0xbd, 0x61, 0x79, 0xa7, 0x1d, 0xc9, 0x6d, 0xbb, ], + [ 0x98, 0xee, 0xa2, 0x1a, 0xf2, 0x5c, 0xd6, 0xbe, ], + [ 0xc7, 0x67, 0x3b, 0x2e, 0xb0, 0xcb, 0xf2, 0xd0, ], + [ 0x88, 0x3e, 0xa3, 0xe3, 0x95, 0x67, 0x53, 0x93, ], + [ 0xc8, 0xce, 0x5c, 0xcd, 0x8c, 0x03, 0x0c, 0xa8, ], + [ 0x94, 0xaf, 0x49, 0xf6, 0xc6, 0x50, 0xad, 0xb8, ], + [ 0xea, 0xb8, 0x85, 0x8a, 0xde, 0x92, 0xe1, 0xbc, ], + [ 0xf3, 0x15, 0xbb, 0x5b, 0xb8, 0x35, 0xd8, 0x17, ], + [ 0xad, 0xcf, 0x6b, 0x07, 0x63, 0x61, 0x2e, 0x2f, ], + [ 0xa5, 0xc9, 0x1d, 0xa7, 0xac, 0xaa, 0x4d, 0xde, ], + [ 0x71, 0x65, 0x95, 0x87, 0x66, 0x50, 0xa2, 0xa6, ], + [ 0x28, 0xef, 0x49, 0x5c, 0x53, 0xa3, 0x87, 0xad, ], + [ 0x42, 0xc3, 0x41, 0xd8, 0xfa, 0x92, 0xd8, 0x32, ], + [ 0xce, 0x7c, 0xf2, 0x72, 0x2f, 0x51, 0x27, 0x71, ], + [ 0xe3, 0x78, 0x59, 0xf9, 0x46, 0x23, 0xf3, 0xa7, ], + [ 0x38, 0x12, 0x05, 0xbb, 0x1a, 0xb0, 0xe0, 0x12, ], + [ 0xae, 0x97, 0xa1, 0x0f, 0xd4, 0x34, 0xe0, 0x15, ], + [ 0xb4, 0xa3, 0x15, 0x08, 0xbe, 0xff, 0x4d, 0x31, ], + [ 0x81, 0x39, 0x62, 0x29, 0xf0, 0x90, 0x79, 0x02, ], + [ 0x4d, 0x0c, 0xf4, 0x9e, 0xe5, 0xd4, 0xdc, 0xca, ], + [ 0x5c, 0x73, 0x33, 0x6a, 0x76, 0xd8, 0xbf, 0x9a, ], + [ 0xd0, 0xa7, 0x04, 0x53, 0x6b, 0xa9, 0x3e, 0x0e, ], + [ 0x92, 0x59, 0x58, 0xfc, 0xd6, 0x42, 0x0c, 0xad, ], + [ 0xa9, 0x15, 0xc2, 0x9b, 0xc8, 0x06, 0x73, 0x18, ], + [ 0x95, 0x2b, 0x79, 0xf3, 0xbc, 0x0a, 0xa6, 0xd4, ], + [ 0xf2, 0x1d, 0xf2, 0xe4, 0x1d, 0x45, 0x35, 0xf9, ], + [ 0x87, 0x57, 0x75, 0x19, 0x04, 0x8f, 0x53, 0xa9, ], + [ 0x10, 0xa5, 0x6c, 0xf5, 0xdf, 0xcd, 0x9a, 0xdb, ], + [ 0xeb, 0x75, 0x09, 0x5c, 0xcd, 0x98, 0x6c, 0xd0, ], + [ 0x51, 0xa9, 0xcb, 0x9e, 0xcb, 0xa3, 0x12, 0xe6, ], + [ 0x96, 0xaf, 0xad, 0xfc, 0x2c, 0xe6, 0x66, 0xc7, ], + [ 0x72, 0xfe, 0x52, 0x97, 0x5a, 0x43, 0x64, 0xee, ], + [ 0x5a, 0x16, 0x45, 0xb2, 0x76, 0xd5, 0x92, 0xa1, ], + [ 0xb2, 0x74, 0xcb, 0x8e, 0xbf, 0x87, 0x87, 0x0a, ], + [ 0x6f, 0x9b, 0xb4, 0x20, 0x3d, 0xe7, 0xb3, 0x81, ], + [ 0xea, 0xec, 0xb2, 0xa3, 0x0b, 0x22, 0xa8, 0x7f, ], + [ 0x99, 0x24, 0xa4, 0x3c, 0xc1, 0x31, 0x57, 0x24, ], + [ 0xbd, 0x83, 0x8d, 0x3a, 0xaf, 0xbf, 0x8d, 0xb7, ], + [ 0x0b, 0x1a, 0x2a, 0x32, 0x65, 0xd5, 0x1a, 0xea, ], + [ 0x13, 0x50, 0x79, 0xa3, 0x23, 0x1c, 0xe6, 0x60, ], + [ 0x93, 0x2b, 0x28, 0x46, 0xe4, 0xd7, 0x06, 0x66, ], + [ 0xe1, 0x91, 0x5f, 0x5c, 0xb1, 0xec, 0xa4, 0x6c, ], + [ 0xf3, 0x25, 0x96, 0x5c, 0xa1, 0x6d, 0x62, 0x9f, ], + [ 0x57, 0x5f, 0xf2, 0x8e, 0x60, 0x38, 0x1b, 0xe5, ], + [ 0x72, 0x45, 0x06, 0xeb, 0x4c, 0x32, 0x8a, 0x95, ], +] +const siphashreferencetestvector = {ctx + var key = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] + var e, h, msg : byte[64] + for var i = 0; i < 64; i++ + msg[i] = i + h = std.siphash24(msg[:i], key) + e = std.getle64(siphashtestvector[i][:]) + testr.check(ctx, e == h, "wrong siphash value for entry {}: got {x}\n", i, h) + ;; } diff --git a/lib/sys/bld.sub b/lib/sys/bld.sub index 7ffb6c8..abf90f5 100644 --- a/lib/sys/bld.sub +++ b/lib/sys/bld.sub @@ -7,6 +7,7 @@ lib sys = sys+osx-x64.myr sys+openbsd-x64.myr sys+openbsd:6.1-x64.myr + sys+openbsd:6.2-x64.myr sys+plan9-x64.myr syscall+freebsd-x64.s diff --git a/lib/sys/ifreq+netbsd.myr b/lib/sys/ifreq+netbsd.myr new file mode 100644 index 0000000..e7d6400 --- /dev/null +++ b/lib/sys/ifreq+netbsd.myr @@ -0,0 +1,2 @@ +pkg sys = +;; diff --git a/lib/sys/sys+freebsd-x64.myr b/lib/sys/sys+freebsd-x64.myr index 2a77fbe..440f396 100644 --- a/lib/sys/sys+freebsd-x64.myr +++ b/lib/sys/sys+freebsd-x64.myr @@ -1,3 +1,8 @@ +/* + generated-ish source + stitched for freebsd arch:x64 + edit with caution. + */ pkg sys = type size = int64 /* spans entire address space */ type usize = uint64 /* unsigned size */ @@ -792,6 +797,7 @@ pkg sys = extern const syscall : (sc:scno, args:... -> int64) extern var __cenvp : byte## + const Sysnosys : scno = 0 const Sysexit : scno = 1 @@ -1129,7 +1135,8 @@ pkg sys = const Sysfutimens : scno = 546 const Sysutimensat : scno = 547 - /* manual overrides */ const exit : (status:int -> void) + /* start manual overrides { */ + const exit : (status:int -> void) const getpid : ( -> pid) const kill : (pid:pid, sig:int64 -> int64) const fork : (-> pid) @@ -1188,6 +1195,10 @@ pkg sys = old : void#, oldsz : size#, \ new : void#, newsz : size# \ -> int) + extern const cstring : (str : byte[:] -> byte#) + extern const alloca : (sz : size -> byte#) + extern const __freebsd_pipe : (fds : fd[2]# -> int64) + /* } end manual overrides */ const nosys : ( -> int) const link : (path : byte#, link : byte# -> int) @@ -1196,24 +1207,24 @@ pkg sys = const chmod : (path : byte#, mode : int -> int) const chown : (path : byte#, uid : int, gid : int -> int) const obreak : (nsize : byte# -> int) - const mount : (kind : byte#, path : byte#, flags : int, data : caddr -> int) + const mount : (kind : byte#, path : byte#, flags : int, data : void# -> int) const unmount : (path : byte#, flags : int -> int) const setuid : (uid : uid -> int) const getuid : ( -> uid) const geteuid : ( -> uid) - const ptrace : (req : int, pid : pid, addr : caddr, data : int -> int) + const ptrace : (req : int, pid : pid, addr : void#, data : int -> int) const recvmsg : (s : int, msg : msghdr#, flags : int -> int) const sendmsg : (s : int, msg : msghdr#, flags : int -> int) - const recvfrom : (s : int, buf : caddr, len : size, flags : int, from : sockaddr# , fromlenaddr : socklen# -> int) - const getpeername : (fdes : int, asa : sockaddr# , alen : socklen# -> int) - const getsockname : (fdes : int, asa : sockaddr# , alen : socklen# -> int) + const recvfrom : (s : int, buf : void#, len : size, flags : int, from : sockaddr#, fromlenaddr : int32# -> int) + const getpeername : (fdes : int, asa : sockaddr#, alen : int32# -> int) + const getsockname : (fdes : int, asa : sockaddr#, alen : int32# -> int) const access : (path : byte#, amode : int -> int) const chflags : (path : byte#, flags : uint64 -> int) const fchflags : (fd : int, flags : uint64 -> int) const sync : ( -> int) const getppid : ( -> pid) const getegid : ( -> gid) - const profil : (samples : caddr, size : size, offset : size, scale : uint -> int) + const profil : (samples : void#, size : size, offset : size, scale : uint -> int) const ktrace : (fname : byte#, ops : int, facs : int, pid : int -> int) const getgid : ( -> gid) const getlogin : (namebuf : byte#, namelen : uint -> int) @@ -1256,14 +1267,14 @@ pkg sys = const rename : (from : byte#, to : byte# -> int) const flock : (fd : int, how : int -> int) const mkfifo : (path : byte#, mode : int -> int) - const sendto : (s : int, buf : caddr, len : size, flags : int, to : caddr, tolen : int -> int) + const sendto : (s : int, buf : void#, len : size, flags : int, to : void#, tolen : int -> int) const shutdown : (s : int, how : int -> int) const socketpair : (domain : int, kind : int, protocol : int, rsv : int# -> int) const rmdir : (path : byte# -> int) const utimes : (path : byte#, tptr : timeval# -> int) const adjtime : (delta : timeval#, olddelta : timeval# -> int) const setsid : ( -> int) - const quotactl : (path : byte#, cmd : int, uid : int, arg : caddr -> int) + const quotactl : (path : byte#, cmd : int, uid : int, arg : void# -> int) const lgetfh : (fname : byte#, fhp : fhandle# -> int) const getfh : (fname : byte#, fhp : fhandle# -> int) const sysarch : (op : int, parms : byte# -> int) @@ -1299,7 +1310,7 @@ pkg sys = const lchown : (path : byte#, uid : int, gid : int -> int) const aio_read : (aiocbp : aiocb# -> int) const aio_write : (aiocbp : aiocb# -> int) - const lio_listio : (mode : int, acb_list : aiocb# #, nent : int, sig : sigevent# -> int) + const lio_listio : (mode : int, acb_list : aiocb##, nent : int, sig : sigevent# -> int) const getdents : (fd : int, buf : byte#, count : size -> int) const lchmod : (path : byte#, mode : filemode -> int) const lutimes : (path : byte#, tptr : timeval# -> int) @@ -1322,7 +1333,7 @@ pkg sys = const setresuid : (ruid : uid, euid : uid, suid : uid -> int) const setresgid : (rgid : gid, egid : gid, sgid : gid -> int) const aio_return : (aiocbp : aiocb# -> size) - const aio_suspend : (aiocbp : aiocb# #, nent : int, timeout : timespec# -> int) + const aio_suspend : (aiocbp : aiocb##, nent : int, timeout : timespec# -> int) const aio_cancel : (fd : int, aiocbp : aiocb# -> int) const aio_error : (aiocbp : aiocb# -> int) const mlockall : (how : int -> int) @@ -1467,10 +1478,10 @@ pkg sys = const cap_ioctls_get : (fd : int, cmds : uint64#, maxcmds : size -> size) const cap_fcntls_limit : (fd : int, fcntlrights : uint32 -> int) const cap_fcntls_get : (fd : int, fcntlrightsp : uint32# -> int) - const bindat : (fd : int, s : int, name : caddr, namelen : int -> int) - const connectat : (fd : int, s : int, name : caddr, namelen : int -> int) + const bindat : (fd : int, s : int, name : void#, namelen : int -> int) + const connectat : (fd : int, s : int, name : void#, namelen : int -> int) const chflagsat : (fd : int, path : byte#, flags : uint64, atflag : int -> int) - const accept4 : (s : int, name : sockaddr# , anamelen : socklen# , flags : int -> int) + const accept4 : (s : int, name : sockaddr#, anamelen : int32#, flags : int -> int) const pipe2 : (fildes : int#, flags : int -> int) const aio_mlock : (aiocbp : aiocb# -> int) const procctl : (idtype : idtype, id : id, com : int, data : void# -> int) @@ -1479,7 +1490,8 @@ pkg sys = const utimensat : (fd : int, path : byte#, times : timespec#, flag : int -> int) ;; - /* manual overrides */ /* pkg sys */ + /* start manual overrides { */ + /* pkg sys */ /* process control */ /* wrappers to extract wait status */ @@ -1509,10 +1521,7 @@ pkg sys = */ generic a = {x : @t; -> (x : uint64)} - extern const cstring : (str : byte[:] -> byte#) - extern const alloca : (sz : size -> byte#) - extern const __freebsd_pipe : (fds : fd[2]# -> int64) /* process management */ const exit = {status; syscall(Sysexit, a(status))} @@ -1700,7 +1709,7 @@ pkg sys = ;; mib[0] = 1 /* CTL_KERN */ - mib[1] = 4 /* KERN_OSVERSION */ + mib[1] = 4 /* KERN_VERSION */ ver = (buf.version[:] : void#) versz = buf.version.len ret = sysctl(mib[:], ver, &versz, (0 : void#), (0 : size#)) @@ -1719,35 +1728,36 @@ pkg sys = -> 0 } + /* } end manual overrides */ const nosys = { -> (syscall(Sysnosys) : int) } const link = {path, link - -> (syscall(Syslink, a(link)) : int) + -> (syscall(Syslink, a(path), a(link)) : int) } const fchdir = {fd - -> (syscall(Sysfchdir) : int) + -> (syscall(Sysfchdir, a(fd)) : int) } const mknod = {path, mode, dev - -> (syscall(Sysmknod, a(mode), a(dev)) : int) + -> (syscall(Sysmknod, a(path), a(mode), a(dev)) : int) } const chmod = {path, mode - -> (syscall(Syschmod, a(mode)) : int) + -> (syscall(Syschmod, a(path), a(mode)) : int) } const chown = {path, uid, gid - -> (syscall(Syschown, a(uid), a(gid)) : int) + -> (syscall(Syschown, a(path), a(uid), a(gid)) : int) } const obreak = {nsize - -> (syscall(Sysobreak) : int) + -> (syscall(Sysobreak, a(nsize)) : int) } const mount = {kind, path, flags, data - -> (syscall(Sysmount, a(path), a(flags), a(data)) : int) + -> (syscall(Sysmount, a(kind), a(path), a(flags), a(data)) : int) } const unmount = {path, flags - -> (syscall(Sysunmount, a(flags)) : int) + -> (syscall(Sysunmount, a(path), a(flags)) : int) } const setuid = {uid - -> (syscall(Syssetuid) : int) + -> (syscall(Syssetuid, a(uid)) : int) } const getuid = { -> (syscall(Sysgetuid) : uid) @@ -1756,31 +1766,31 @@ const geteuid = { -> (syscall(Sysgeteuid) : uid) } const ptrace = {req, pid, addr, data - -> (syscall(Sysptrace, a(pid), a(addr), a(data)) : int) + -> (syscall(Sysptrace, a(req), a(pid), a(addr), a(data)) : int) } const recvmsg = {s, msg, flags - -> (syscall(Sysrecvmsg, a(msg), a(flags)) : int) + -> (syscall(Sysrecvmsg, a(s), a(msg), a(flags)) : int) } const sendmsg = {s, msg, flags - -> (syscall(Syssendmsg, a(msg), a(flags)) : int) + -> (syscall(Syssendmsg, a(s), a(msg), a(flags)) : int) } const recvfrom = {s, buf, len, flags, from, fromlenaddr - -> (syscall(Sysrecvfrom, a(buf), a(len), a(flags), a(from), a(fromlenaddr)) : int) + -> (syscall(Sysrecvfrom, a(s), a(buf), a(len), a(flags), a(from), a(fromlenaddr)) : int) } const getpeername = {fdes, asa, alen - -> (syscall(Sysgetpeername, a(asa), a(alen)) : int) + -> (syscall(Sysgetpeername, a(fdes), a(asa), a(alen)) : int) } const getsockname = {fdes, asa, alen - -> (syscall(Sysgetsockname, a(asa), a(alen)) : int) + -> (syscall(Sysgetsockname, a(fdes), a(asa), a(alen)) : int) } const access = {path, amode - -> (syscall(Sysaccess, a(amode)) : int) + -> (syscall(Sysaccess, a(path), a(amode)) : int) } const chflags = {path, flags - -> (syscall(Syschflags, a(flags)) : int) + -> (syscall(Syschflags, a(path), a(flags)) : int) } const fchflags = {fd, flags - -> (syscall(Sysfchflags, a(flags)) : int) + -> (syscall(Sysfchflags, a(fd), a(flags)) : int) } const sync = { -> (syscall(Syssync) : int) @@ -1792,794 +1802,794 @@ const getegid = { -> (syscall(Sysgetegid) : gid) } const profil = {samples, size, offset, scale - -> (syscall(Sysprofil, a(size), a(offset), a(scale)) : int) + -> (syscall(Sysprofil, a(samples), a(size), a(offset), a(scale)) : int) } const ktrace = {fname, ops, facs, pid - -> (syscall(Sysktrace, a(ops), a(facs), a(pid)) : int) + -> (syscall(Sysktrace, a(fname), a(ops), a(facs), a(pid)) : int) } const getgid = { -> (syscall(Sysgetgid) : gid) } const getlogin = {namebuf, namelen - -> (syscall(Sysgetlogin, a(namelen)) : int) + -> (syscall(Sysgetlogin, a(namebuf), a(namelen)) : int) } const setlogin = {namebuf - -> (syscall(Syssetlogin) : int) + -> (syscall(Syssetlogin, a(namebuf)) : int) } const acct = {path - -> (syscall(Sysacct) : int) + -> (syscall(Sysacct, a(path)) : int) } const sigaltstack = {ss, oss - -> (syscall(Syssigaltstack, a(oss)) : int) + -> (syscall(Syssigaltstack, a(ss), a(oss)) : int) } const reboot = {opt - -> (syscall(Sysreboot) : int) + -> (syscall(Sysreboot, a(opt)) : int) } const revoke = {path - -> (syscall(Sysrevoke) : int) + -> (syscall(Sysrevoke, a(path)) : int) } const symlink = {path, link - -> (syscall(Syssymlink, a(link)) : int) + -> (syscall(Syssymlink, a(path), a(link)) : int) } const readlink = {path, buf, count - -> (syscall(Sysreadlink, a(buf), a(count)) : size) + -> (syscall(Sysreadlink, a(path), a(buf), a(count)) : size) } const umask = {newmask - -> (syscall(Sysumask) : int) + -> (syscall(Sysumask, a(newmask)) : int) } const chroot = {path - -> (syscall(Syschroot) : int) + -> (syscall(Syschroot, a(path)) : int) } const msync = {addr, len, flags - -> (syscall(Sysmsync, a(len), a(flags)) : int) + -> (syscall(Sysmsync, a(addr), a(len), a(flags)) : int) } const vfork = { -> (syscall(Sysvfork) : int) } const sbrk = {incr - -> (syscall(Syssbrk) : int) + -> (syscall(Syssbrk, a(incr)) : int) } const sstk = {incr - -> (syscall(Syssstk) : int) + -> (syscall(Syssstk, a(incr)) : int) } const ovadvise = {anom - -> (syscall(Sysovadvise) : int) + -> (syscall(Sysovadvise, a(anom)) : int) } const mprotect = {addr, len, prot - -> (syscall(Sysmprotect, a(len), a(prot)) : int) + -> (syscall(Sysmprotect, a(addr), a(len), a(prot)) : int) } const madvise = {addr, len, behav - -> (syscall(Sysmadvise, a(len), a(behav)) : int) + -> (syscall(Sysmadvise, a(addr), a(len), a(behav)) : int) } const mincore = {addr, len, vec - -> (syscall(Sysmincore, a(len), a(vec)) : int) + -> (syscall(Sysmincore, a(addr), a(len), a(vec)) : int) } const getgroups = {gidsetsize, gidset - -> (syscall(Sysgetgroups, a(gidset)) : int) + -> (syscall(Sysgetgroups, a(gidsetsize), a(gidset)) : int) } const setgroups = {gidsetsize, gidset - -> (syscall(Syssetgroups, a(gidset)) : int) + -> (syscall(Syssetgroups, a(gidsetsize), a(gidset)) : int) } const getpgrp = { -> (syscall(Sysgetpgrp) : int) } const setpgid = {pid, pgid - -> (syscall(Syssetpgid, a(pgid)) : int) + -> (syscall(Syssetpgid, a(pid), a(pgid)) : int) } const setitimer = {which, itv, oitv - -> (syscall(Syssetitimer, a(itv), a(oitv)) : int) + -> (syscall(Syssetitimer, a(which), a(itv), a(oitv)) : int) } const swapon = {name - -> (syscall(Sysswapon) : int) + -> (syscall(Sysswapon, a(name)) : int) } const getitimer = {which, itv - -> (syscall(Sysgetitimer, a(itv)) : int) + -> (syscall(Sysgetitimer, a(which), a(itv)) : int) } const getdtablesize = { -> (syscall(Sysgetdtablesize) : int) } const select = {nd, _in, ou, ex, tv - -> (syscall(Sysselect, a(_in), a(ou), a(ex), a(tv)) : int) + -> (syscall(Sysselect, a(nd), a(_in), a(ou), a(ex), a(tv)) : int) } const fsync = {fd - -> (syscall(Sysfsync) : int) + -> (syscall(Sysfsync, a(fd)) : int) } const setpriority = {which, who, prio - -> (syscall(Syssetpriority, a(who), a(prio)) : int) + -> (syscall(Syssetpriority, a(which), a(who), a(prio)) : int) } const getpriority = {which, who - -> (syscall(Sysgetpriority, a(who)) : int) + -> (syscall(Sysgetpriority, a(which), a(who)) : int) } const gettimeofday = {tp, tzp - -> (syscall(Sysgettimeofday, a(tzp)) : int) + -> (syscall(Sysgettimeofday, a(tp), a(tzp)) : int) } const getrusage = {who, rusage - -> (syscall(Sysgetrusage, a(rusage)) : int) + -> (syscall(Sysgetrusage, a(who), a(rusage)) : int) } const settimeofday = {tv, tzp - -> (syscall(Syssettimeofday, a(tzp)) : int) + -> (syscall(Syssettimeofday, a(tv), a(tzp)) : int) } const fchown = {fd, uid, gid - -> (syscall(Sysfchown, a(uid), a(gid)) : int) + -> (syscall(Sysfchown, a(fd), a(uid), a(gid)) : int) } const fchmod = {fd, mode - -> (syscall(Sysfchmod, a(mode)) : int) + -> (syscall(Sysfchmod, a(fd), a(mode)) : int) } const setreuid = {ruid, euid - -> (syscall(Syssetreuid, a(euid)) : int) + -> (syscall(Syssetreuid, a(ruid), a(euid)) : int) } const setregid = {rgid, egid - -> (syscall(Syssetregid, a(egid)) : int) + -> (syscall(Syssetregid, a(rgid), a(egid)) : int) } const rename = {from, to - -> (syscall(Sysrename, a(to)) : int) + -> (syscall(Sysrename, a(from), a(to)) : int) } const flock = {fd, how - -> (syscall(Sysflock, a(how)) : int) + -> (syscall(Sysflock, a(fd), a(how)) : int) } const mkfifo = {path, mode - -> (syscall(Sysmkfifo, a(mode)) : int) + -> (syscall(Sysmkfifo, a(path), a(mode)) : int) } const sendto = {s, buf, len, flags, to, tolen - -> (syscall(Syssendto, a(buf), a(len), a(flags), a(to), a(tolen)) : int) + -> (syscall(Syssendto, a(s), a(buf), a(len), a(flags), a(to), a(tolen)) : int) } const shutdown = {s, how - -> (syscall(Sysshutdown, a(how)) : int) + -> (syscall(Sysshutdown, a(s), a(how)) : int) } const socketpair = {domain, kind, protocol, rsv - -> (syscall(Syssocketpair, a(kind), a(protocol), a(rsv)) : int) + -> (syscall(Syssocketpair, a(domain), a(kind), a(protocol), a(rsv)) : int) } const rmdir = {path - -> (syscall(Sysrmdir) : int) + -> (syscall(Sysrmdir, a(path)) : int) } const utimes = {path, tptr - -> (syscall(Sysutimes, a(tptr)) : int) + -> (syscall(Sysutimes, a(path), a(tptr)) : int) } const adjtime = {delta, olddelta - -> (syscall(Sysadjtime, a(olddelta)) : int) + -> (syscall(Sysadjtime, a(delta), a(olddelta)) : int) } const setsid = { -> (syscall(Syssetsid) : int) } const quotactl = {path, cmd, uid, arg - -> (syscall(Sysquotactl, a(cmd), a(uid), a(arg)) : int) + -> (syscall(Sysquotactl, a(path), a(cmd), a(uid), a(arg)) : int) } const lgetfh = {fname, fhp - -> (syscall(Syslgetfh, a(fhp)) : int) + -> (syscall(Syslgetfh, a(fname), a(fhp)) : int) } const getfh = {fname, fhp - -> (syscall(Sysgetfh, a(fhp)) : int) + -> (syscall(Sysgetfh, a(fname), a(fhp)) : int) } const sysarch = {op, parms - -> (syscall(Syssysarch, a(parms)) : int) + -> (syscall(Syssysarch, a(op), a(parms)) : int) } const rtprio = {function, pid, rtp - -> (syscall(Sysrtprio, a(pid), a(rtp)) : int) + -> (syscall(Sysrtprio, a(function), a(pid), a(rtp)) : int) } const setfib = {fibnum - -> (syscall(Syssetfib) : int) + -> (syscall(Syssetfib, a(fibnum)) : int) } const ntp_adjtime = {tp - -> (syscall(Sysntp_adjtime) : int) + -> (syscall(Sysntp_adjtime, a(tp)) : int) } const setgid = {gid - -> (syscall(Syssetgid) : int) + -> (syscall(Syssetgid, a(gid)) : int) } const setegid = {egid - -> (syscall(Syssetegid) : int) + -> (syscall(Syssetegid, a(egid)) : int) } const seteuid = {euid - -> (syscall(Sysseteuid) : int) + -> (syscall(Sysseteuid, a(euid)) : int) } const pathconf = {path, name - -> (syscall(Syspathconf, a(name)) : int) + -> (syscall(Syspathconf, a(path), a(name)) : int) } const fpathconf = {fd, name - -> (syscall(Sysfpathconf, a(name)) : int) + -> (syscall(Sysfpathconf, a(fd), a(name)) : int) } const getrlimit = {which, rlp - -> (syscall(Sysgetrlimit, a(rlp)) : int) + -> (syscall(Sysgetrlimit, a(which), a(rlp)) : int) } const setrlimit = {which, rlp - -> (syscall(Syssetrlimit, a(rlp)) : int) + -> (syscall(Syssetrlimit, a(which), a(rlp)) : int) } const __sysctl = {name, namelen, old, oldlenp, new, newlen - -> (syscall(Sys__sysctl, a(namelen), a(old), a(oldlenp), a(new), a(newlen)) : int) + -> (syscall(Sys__sysctl, a(name), a(namelen), a(old), a(oldlenp), a(new), a(newlen)) : int) } const mlock = {addr, len - -> (syscall(Sysmlock, a(len)) : int) + -> (syscall(Sysmlock, a(addr), a(len)) : int) } const munlock = {addr, len - -> (syscall(Sysmunlock, a(len)) : int) + -> (syscall(Sysmunlock, a(addr), a(len)) : int) } const undelete = {path - -> (syscall(Sysundelete) : int) + -> (syscall(Sysundelete, a(path)) : int) } const futimes = {fd, tptr - -> (syscall(Sysfutimes, a(tptr)) : int) + -> (syscall(Sysfutimes, a(fd), a(tptr)) : int) } const getpgid = {pid - -> (syscall(Sysgetpgid) : int) + -> (syscall(Sysgetpgid, a(pid)) : int) } const ktimer_create = {clock_id, evp, timerid - -> (syscall(Sysktimer_create, a(evp), a(timerid)) : int) + -> (syscall(Sysktimer_create, a(clock_id), a(evp), a(timerid)) : int) } const ktimer_delete = {timerid - -> (syscall(Sysktimer_delete) : int) + -> (syscall(Sysktimer_delete, a(timerid)) : int) } const ktimer_settime = {timerid, flags, value, ovalue - -> (syscall(Sysktimer_settime, a(flags), a(value), a(ovalue)) : int) + -> (syscall(Sysktimer_settime, a(timerid), a(flags), a(value), a(ovalue)) : int) } const ktimer_gettime = {timerid, value - -> (syscall(Sysktimer_gettime, a(value)) : int) + -> (syscall(Sysktimer_gettime, a(timerid), a(value)) : int) } const ktimer_getoverrun = {timerid - -> (syscall(Sysktimer_getoverrun) : int) + -> (syscall(Sysktimer_getoverrun, a(timerid)) : int) } const ffclock_getcounter = {ffcount - -> (syscall(Sysffclock_getcounter) : int) + -> (syscall(Sysffclock_getcounter, a(ffcount)) : int) } const ffclock_setestimate = {cest - -> (syscall(Sysffclock_setestimate) : int) + -> (syscall(Sysffclock_setestimate, a(cest)) : int) } const ffclock_getestimate = {cest - -> (syscall(Sysffclock_getestimate) : int) + -> (syscall(Sysffclock_getestimate, a(cest)) : int) } const clock_getcpuclockid2 = {id, which, clock_id - -> (syscall(Sysclock_getcpuclockid2, a(which), a(clock_id)) : int) + -> (syscall(Sysclock_getcpuclockid2, a(id), a(which), a(clock_id)) : int) } const minherit = {addr, len, inherit - -> (syscall(Sysminherit, a(len), a(inherit)) : int) + -> (syscall(Sysminherit, a(addr), a(len), a(inherit)) : int) } const rfork = {flags - -> (syscall(Sysrfork) : int) + -> (syscall(Sysrfork, a(flags)) : int) } const openbsd_poll = {fds, nfds, timeout - -> (syscall(Sysopenbsd_poll, a(nfds), a(timeout)) : int) + -> (syscall(Sysopenbsd_poll, a(fds), a(nfds), a(timeout)) : int) } const issetugid = { -> (syscall(Sysissetugid) : int) } const lchown = {path, uid, gid - -> (syscall(Syslchown, a(uid), a(gid)) : int) + -> (syscall(Syslchown, a(path), a(uid), a(gid)) : int) } const aio_read = {aiocbp - -> (syscall(Sysaio_read) : int) + -> (syscall(Sysaio_read, a(aiocbp)) : int) } const aio_write = {aiocbp - -> (syscall(Sysaio_write) : int) + -> (syscall(Sysaio_write, a(aiocbp)) : int) } const lio_listio = {mode, acb_list, nent, sig - -> (syscall(Syslio_listio, a(acb_list), a(nent), a(sig)) : int) + -> (syscall(Syslio_listio, a(mode), a(acb_list), a(nent), a(sig)) : int) } const getdents = {fd, buf, count - -> (syscall(Sysgetdents, a(buf), a(count)) : int) + -> (syscall(Sysgetdents, a(fd), a(buf), a(count)) : int) } const lchmod = {path, mode - -> (syscall(Syslchmod, a(mode)) : int) + -> (syscall(Syslchmod, a(path), a(mode)) : int) } const lutimes = {path, tptr - -> (syscall(Syslutimes, a(tptr)) : int) + -> (syscall(Syslutimes, a(path), a(tptr)) : int) } const nstat = {path, ub - -> (syscall(Sysnstat, a(ub)) : int) + -> (syscall(Sysnstat, a(path), a(ub)) : int) } const nfstat = {fd, sb - -> (syscall(Sysnfstat, a(sb)) : int) + -> (syscall(Sysnfstat, a(fd), a(sb)) : int) } const nlstat = {path, ub - -> (syscall(Sysnlstat, a(ub)) : int) + -> (syscall(Sysnlstat, a(path), a(ub)) : int) } const preadv = {fd, iovp, iovcnt, offset - -> (syscall(Syspreadv, a(iovp), a(iovcnt), a(offset)) : size) + -> (syscall(Syspreadv, a(fd), a(iovp), a(iovcnt), a(offset)) : size) } const pwritev = {fd, iovp, iovcnt, offset - -> (syscall(Syspwritev, a(iovp), a(iovcnt), a(offset)) : size) + -> (syscall(Syspwritev, a(fd), a(iovp), a(iovcnt), a(offset)) : size) } const fhopen = {u_fhp, flags - -> (syscall(Sysfhopen, a(flags)) : int) + -> (syscall(Sysfhopen, a(u_fhp), a(flags)) : int) } const fhstat = {u_fhp, sb - -> (syscall(Sysfhstat, a(sb)) : int) + -> (syscall(Sysfhstat, a(u_fhp), a(sb)) : int) } const modnext = {modid - -> (syscall(Sysmodnext) : int) + -> (syscall(Sysmodnext, a(modid)) : int) } const modfnext = {modid - -> (syscall(Sysmodfnext) : int) + -> (syscall(Sysmodfnext, a(modid)) : int) } const modfind = {name - -> (syscall(Sysmodfind) : int) + -> (syscall(Sysmodfind, a(name)) : int) } const kldload = {file - -> (syscall(Syskldload) : int) + -> (syscall(Syskldload, a(file)) : int) } const kldunload = {fileid - -> (syscall(Syskldunload) : int) + -> (syscall(Syskldunload, a(fileid)) : int) } const kldfind = {file - -> (syscall(Syskldfind) : int) + -> (syscall(Syskldfind, a(file)) : int) } const kldnext = {fileid - -> (syscall(Syskldnext) : int) + -> (syscall(Syskldnext, a(fileid)) : int) } const kldfirstmod = {fileid - -> (syscall(Syskldfirstmod) : int) + -> (syscall(Syskldfirstmod, a(fileid)) : int) } const getsid = {pid - -> (syscall(Sysgetsid) : int) + -> (syscall(Sysgetsid, a(pid)) : int) } const setresuid = {ruid, euid, suid - -> (syscall(Syssetresuid, a(euid), a(suid)) : int) + -> (syscall(Syssetresuid, a(ruid), a(euid), a(suid)) : int) } const setresgid = {rgid, egid, sgid - -> (syscall(Syssetresgid, a(egid), a(sgid)) : int) + -> (syscall(Syssetresgid, a(rgid), a(egid), a(sgid)) : int) } const aio_return = {aiocbp - -> (syscall(Sysaio_return) : size) + -> (syscall(Sysaio_return, a(aiocbp)) : size) } const aio_suspend = {aiocbp, nent, timeout - -> (syscall(Sysaio_suspend, a(nent), a(timeout)) : int) + -> (syscall(Sysaio_suspend, a(aiocbp), a(nent), a(timeout)) : int) } const aio_cancel = {fd, aiocbp - -> (syscall(Sysaio_cancel, a(aiocbp)) : int) + -> (syscall(Sysaio_cancel, a(fd), a(aiocbp)) : int) } const aio_error = {aiocbp - -> (syscall(Sysaio_error) : int) + -> (syscall(Sysaio_error, a(aiocbp)) : int) } const mlockall = {how - -> (syscall(Sysmlockall) : int) + -> (syscall(Sysmlockall, a(how)) : int) } const munlockall = { -> (syscall(Sysmunlockall) : int) } const sched_setparam = {pid, param - -> (syscall(Syssched_setparam, a(param)) : int) + -> (syscall(Syssched_setparam, a(pid), a(param)) : int) } const sched_getparam = {pid, param - -> (syscall(Syssched_getparam, a(param)) : int) + -> (syscall(Syssched_getparam, a(pid), a(param)) : int) } const sched_setscheduler = {pid, policy, param - -> (syscall(Syssched_setscheduler, a(policy), a(param)) : int) + -> (syscall(Syssched_setscheduler, a(pid), a(policy), a(param)) : int) } const sched_getscheduler = {pid - -> (syscall(Syssched_getscheduler) : int) + -> (syscall(Syssched_getscheduler, a(pid)) : int) } const sched_get_priority_max = {policy - -> (syscall(Syssched_get_priority_max) : int) + -> (syscall(Syssched_get_priority_max, a(policy)) : int) } const sched_get_priority_min = {policy - -> (syscall(Syssched_get_priority_min) : int) + -> (syscall(Syssched_get_priority_min, a(policy)) : int) } const sched_rr_get_interval = {pid, interval - -> (syscall(Syssched_rr_get_interval, a(interval)) : int) + -> (syscall(Syssched_rr_get_interval, a(pid), a(interval)) : int) } const utrace = {addr, len - -> (syscall(Sysutrace, a(len)) : int) + -> (syscall(Sysutrace, a(addr), a(len)) : int) } const kldsym = {fileid, cmd, data - -> (syscall(Syskldsym, a(cmd), a(data)) : int) + -> (syscall(Syskldsym, a(fileid), a(cmd), a(data)) : int) } const jail = {jail - -> (syscall(Sysjail) : int) + -> (syscall(Sysjail, a(jail)) : int) } const sigsuspend = {sigmask - -> (syscall(Syssigsuspend) : int) + -> (syscall(Syssigsuspend, a(sigmask)) : int) } const sigpending = {set - -> (syscall(Syssigpending) : int) + -> (syscall(Syssigpending, a(set)) : int) } const sigtimedwait = {set, info, timeout - -> (syscall(Syssigtimedwait, a(info), a(timeout)) : int) + -> (syscall(Syssigtimedwait, a(set), a(info), a(timeout)) : int) } const sigwaitinfo = {set, info - -> (syscall(Syssigwaitinfo, a(info)) : int) + -> (syscall(Syssigwaitinfo, a(set), a(info)) : int) } const __acl_get_file = {path, kind, aclp - -> (syscall(Sys__acl_get_file, a(kind), a(aclp)) : int) + -> (syscall(Sys__acl_get_file, a(path), a(kind), a(aclp)) : int) } const __acl_set_file = {path, kind, aclp - -> (syscall(Sys__acl_set_file, a(kind), a(aclp)) : int) + -> (syscall(Sys__acl_set_file, a(path), a(kind), a(aclp)) : int) } const __acl_get_fd = {filedes, kind, aclp - -> (syscall(Sys__acl_get_fd, a(kind), a(aclp)) : int) + -> (syscall(Sys__acl_get_fd, a(filedes), a(kind), a(aclp)) : int) } const __acl_set_fd = {filedes, kind, aclp - -> (syscall(Sys__acl_set_fd, a(kind), a(aclp)) : int) + -> (syscall(Sys__acl_set_fd, a(filedes), a(kind), a(aclp)) : int) } const __acl_delete_file = {path, kind - -> (syscall(Sys__acl_delete_file, a(kind)) : int) + -> (syscall(Sys__acl_delete_file, a(path), a(kind)) : int) } const __acl_delete_fd = {filedes, kind - -> (syscall(Sys__acl_delete_fd, a(kind)) : int) + -> (syscall(Sys__acl_delete_fd, a(filedes), a(kind)) : int) } const __acl_aclcheck_file = {path, kind, aclp - -> (syscall(Sys__acl_aclcheck_file, a(kind), a(aclp)) : int) + -> (syscall(Sys__acl_aclcheck_file, a(path), a(kind), a(aclp)) : int) } const __acl_aclcheck_fd = {filedes, kind, aclp - -> (syscall(Sys__acl_aclcheck_fd, a(kind), a(aclp)) : int) + -> (syscall(Sys__acl_aclcheck_fd, a(filedes), a(kind), a(aclp)) : int) } const extattrctl = {path, cmd, filename, attrnamespace, attrname - -> (syscall(Sysextattrctl, a(cmd), a(filename), a(attrnamespace), a(attrname)) : int) + -> (syscall(Sysextattrctl, a(path), a(cmd), a(filename), a(attrnamespace), a(attrname)) : int) } const extattr_set_file = {path, attrnamespace, attrname, data, nbytes - -> (syscall(Sysextattr_set_file, a(attrnamespace), a(attrname), a(data), a(nbytes)) : size) + -> (syscall(Sysextattr_set_file, a(path), a(attrnamespace), a(attrname), a(data), a(nbytes)) : size) } const extattr_get_file = {path, attrnamespace, attrname, data, nbytes - -> (syscall(Sysextattr_get_file, a(attrnamespace), a(attrname), a(data), a(nbytes)) : size) + -> (syscall(Sysextattr_get_file, a(path), a(attrnamespace), a(attrname), a(data), a(nbytes)) : size) } const extattr_delete_file = {path, attrnamespace, attrname - -> (syscall(Sysextattr_delete_file, a(attrnamespace), a(attrname)) : int) + -> (syscall(Sysextattr_delete_file, a(path), a(attrnamespace), a(attrname)) : int) } const aio_waitcomplete = {aiocbp, timeout - -> (syscall(Sysaio_waitcomplete, a(timeout)) : size) + -> (syscall(Sysaio_waitcomplete, a(aiocbp), a(timeout)) : size) } const getresuid = {ruid, euid, suid - -> (syscall(Sysgetresuid, a(euid), a(suid)) : int) + -> (syscall(Sysgetresuid, a(ruid), a(euid), a(suid)) : int) } const getresgid = {rgid, egid, sgid - -> (syscall(Sysgetresgid, a(egid), a(sgid)) : int) + -> (syscall(Sysgetresgid, a(rgid), a(egid), a(sgid)) : int) } const kqueue = { -> (syscall(Syskqueue) : int) } const kevent = {fd, changelist, nchanges, eventlist, nevents, timeout - -> (syscall(Syskevent, a(changelist), a(nchanges), a(eventlist), a(nevents), a(timeout)) : int) + -> (syscall(Syskevent, a(fd), a(changelist), a(nchanges), a(eventlist), a(nevents), a(timeout)) : int) } const extattr_set_fd = {fd, attrnamespace, attrname, data, nbytes - -> (syscall(Sysextattr_set_fd, a(attrnamespace), a(attrname), a(data), a(nbytes)) : size) + -> (syscall(Sysextattr_set_fd, a(fd), a(attrnamespace), a(attrname), a(data), a(nbytes)) : size) } const extattr_get_fd = {fd, attrnamespace, attrname, data, nbytes - -> (syscall(Sysextattr_get_fd, a(attrnamespace), a(attrname), a(data), a(nbytes)) : size) + -> (syscall(Sysextattr_get_fd, a(fd), a(attrnamespace), a(attrname), a(data), a(nbytes)) : size) } const extattr_delete_fd = {fd, attrnamespace, attrname - -> (syscall(Sysextattr_delete_fd, a(attrnamespace), a(attrname)) : int) + -> (syscall(Sysextattr_delete_fd, a(fd), a(attrnamespace), a(attrname)) : int) } const __setugid = {flag - -> (syscall(Sys__setugid) : int) + -> (syscall(Sys__setugid, a(flag)) : int) } const eaccess = {path, amode - -> (syscall(Syseaccess, a(amode)) : int) + -> (syscall(Syseaccess, a(path), a(amode)) : int) } const nmount = {iovp, iovcnt, flags - -> (syscall(Sysnmount, a(iovcnt), a(flags)) : int) + -> (syscall(Sysnmount, a(iovp), a(iovcnt), a(flags)) : int) } const __mac_get_proc = {mac_p - -> (syscall(Sys__mac_get_proc) : int) + -> (syscall(Sys__mac_get_proc, a(mac_p)) : int) } const __mac_set_proc = {mac_p - -> (syscall(Sys__mac_set_proc) : int) + -> (syscall(Sys__mac_set_proc, a(mac_p)) : int) } const __mac_get_fd = {fd, mac_p - -> (syscall(Sys__mac_get_fd, a(mac_p)) : int) + -> (syscall(Sys__mac_get_fd, a(fd), a(mac_p)) : int) } const __mac_get_file = {path_p, mac_p - -> (syscall(Sys__mac_get_file, a(mac_p)) : int) + -> (syscall(Sys__mac_get_file, a(path_p), a(mac_p)) : int) } const __mac_set_fd = {fd, mac_p - -> (syscall(Sys__mac_set_fd, a(mac_p)) : int) + -> (syscall(Sys__mac_set_fd, a(fd), a(mac_p)) : int) } const __mac_set_file = {path_p, mac_p - -> (syscall(Sys__mac_set_file, a(mac_p)) : int) + -> (syscall(Sys__mac_set_file, a(path_p), a(mac_p)) : int) } const kenv = {what, name, value, len - -> (syscall(Syskenv, a(name), a(value), a(len)) : int) + -> (syscall(Syskenv, a(what), a(name), a(value), a(len)) : int) } const lchflags = {path, flags - -> (syscall(Syslchflags, a(flags)) : int) + -> (syscall(Syslchflags, a(path), a(flags)) : int) } const uuidgen = {store, count - -> (syscall(Sysuuidgen, a(count)) : int) + -> (syscall(Sysuuidgen, a(store), a(count)) : int) } const sendfile = {fd, s, offset, nbytes, hdtr, sbytes, flags - -> (syscall(Syssendfile, a(s), a(offset), a(nbytes), a(hdtr), a(sbytes), a(flags)) : int) + -> (syscall(Syssendfile, a(fd), a(s), a(offset), a(nbytes), a(hdtr), a(sbytes), a(flags)) : int) } const mac_syscall = {policy, call, arg - -> (syscall(Sysmac_syscall, a(call), a(arg)) : int) + -> (syscall(Sysmac_syscall, a(policy), a(call), a(arg)) : int) } const getfsstat = {buf, bufsize, flags - -> (syscall(Sysgetfsstat, a(bufsize), a(flags)) : int) + -> (syscall(Sysgetfsstat, a(buf), a(bufsize), a(flags)) : int) } const statfs = {path, buf - -> (syscall(Sysstatfs, a(buf)) : int) + -> (syscall(Sysstatfs, a(path), a(buf)) : int) } const fstatfs = {fd, buf - -> (syscall(Sysfstatfs, a(buf)) : int) + -> (syscall(Sysfstatfs, a(fd), a(buf)) : int) } const fhstatfs = {u_fhp, buf - -> (syscall(Sysfhstatfs, a(buf)) : int) + -> (syscall(Sysfhstatfs, a(u_fhp), a(buf)) : int) } const __mac_get_pid = {pid, mac_p - -> (syscall(Sys__mac_get_pid, a(mac_p)) : int) + -> (syscall(Sys__mac_get_pid, a(pid), a(mac_p)) : int) } const __mac_get_link = {path_p, mac_p - -> (syscall(Sys__mac_get_link, a(mac_p)) : int) + -> (syscall(Sys__mac_get_link, a(path_p), a(mac_p)) : int) } const __mac_set_link = {path_p, mac_p - -> (syscall(Sys__mac_set_link, a(mac_p)) : int) + -> (syscall(Sys__mac_set_link, a(path_p), a(mac_p)) : int) } const extattr_set_link = {path, attrnamespace, attrname, data, nbytes - -> (syscall(Sysextattr_set_link, a(attrnamespace), a(attrname), a(data), a(nbytes)) : size) + -> (syscall(Sysextattr_set_link, a(path), a(attrnamespace), a(attrname), a(data), a(nbytes)) : size) } const extattr_get_link = {path, attrnamespace, attrname, data, nbytes - -> (syscall(Sysextattr_get_link, a(attrnamespace), a(attrname), a(data), a(nbytes)) : size) + -> (syscall(Sysextattr_get_link, a(path), a(attrnamespace), a(attrname), a(data), a(nbytes)) : size) } const extattr_delete_link = {path, attrnamespace, attrname - -> (syscall(Sysextattr_delete_link, a(attrnamespace), a(attrname)) : int) + -> (syscall(Sysextattr_delete_link, a(path), a(attrnamespace), a(attrname)) : int) } const __mac_execve = {fname, argv, envv, mac_p - -> (syscall(Sys__mac_execve, a(argv), a(envv), a(mac_p)) : int) + -> (syscall(Sys__mac_execve, a(fname), a(argv), a(envv), a(mac_p)) : int) } const sigreturn = {sigcntxp - -> (syscall(Syssigreturn) : int) + -> (syscall(Syssigreturn, a(sigcntxp)) : int) } const getcontext = {ucp - -> (syscall(Sysgetcontext) : int) + -> (syscall(Sysgetcontext, a(ucp)) : int) } const setcontext = {ucp - -> (syscall(Syssetcontext) : int) + -> (syscall(Syssetcontext, a(ucp)) : int) } const swapcontext = {oucp, ucp - -> (syscall(Sysswapcontext, a(ucp)) : int) + -> (syscall(Sysswapcontext, a(oucp), a(ucp)) : int) } const swapoff = {name - -> (syscall(Sysswapoff) : int) + -> (syscall(Sysswapoff, a(name)) : int) } const __acl_get_link = {path, kind, aclp - -> (syscall(Sys__acl_get_link, a(kind), a(aclp)) : int) + -> (syscall(Sys__acl_get_link, a(path), a(kind), a(aclp)) : int) } const __acl_set_link = {path, kind, aclp - -> (syscall(Sys__acl_set_link, a(kind), a(aclp)) : int) + -> (syscall(Sys__acl_set_link, a(path), a(kind), a(aclp)) : int) } const __acl_delete_link = {path, kind - -> (syscall(Sys__acl_delete_link, a(kind)) : int) + -> (syscall(Sys__acl_delete_link, a(path), a(kind)) : int) } const __acl_aclcheck_link = {path, kind, aclp - -> (syscall(Sys__acl_aclcheck_link, a(kind), a(aclp)) : int) + -> (syscall(Sys__acl_aclcheck_link, a(path), a(kind), a(aclp)) : int) } const sigwait = {set, sig - -> (syscall(Syssigwait, a(sig)) : int) + -> (syscall(Syssigwait, a(set), a(sig)) : int) } const thr_create = {ctx, id, flags - -> (syscall(Systhr_create, a(id), a(flags)) : int) + -> (syscall(Systhr_create, a(ctx), a(id), a(flags)) : int) } const thr_self = {id - -> (syscall(Systhr_self) : int) + -> (syscall(Systhr_self, a(id)) : int) } const thr_kill = {id, sig - -> (syscall(Systhr_kill, a(sig)) : int) + -> (syscall(Systhr_kill, a(id), a(sig)) : int) } const jail_attach = {jid - -> (syscall(Sysjail_attach) : int) + -> (syscall(Sysjail_attach, a(jid)) : int) } const extattr_list_fd = {fd, attrnamespace, data, nbytes - -> (syscall(Sysextattr_list_fd, a(attrnamespace), a(data), a(nbytes)) : size) + -> (syscall(Sysextattr_list_fd, a(fd), a(attrnamespace), a(data), a(nbytes)) : size) } const extattr_list_file = {path, attrnamespace, data, nbytes - -> (syscall(Sysextattr_list_file, a(attrnamespace), a(data), a(nbytes)) : size) + -> (syscall(Sysextattr_list_file, a(path), a(attrnamespace), a(data), a(nbytes)) : size) } const extattr_list_link = {path, attrnamespace, data, nbytes - -> (syscall(Sysextattr_list_link, a(attrnamespace), a(data), a(nbytes)) : size) + -> (syscall(Sysextattr_list_link, a(path), a(attrnamespace), a(data), a(nbytes)) : size) } const thr_suspend = {timeout - -> (syscall(Systhr_suspend) : int) + -> (syscall(Systhr_suspend, a(timeout)) : int) } const thr_wake = {id - -> (syscall(Systhr_wake) : int) + -> (syscall(Systhr_wake, a(id)) : int) } const kldunloadf = {fileid, flags - -> (syscall(Syskldunloadf, a(flags)) : int) + -> (syscall(Syskldunloadf, a(fileid), a(flags)) : int) } const audit = {record, length - -> (syscall(Sysaudit, a(length)) : int) + -> (syscall(Sysaudit, a(record), a(length)) : int) } const auditon = {cmd, data, length - -> (syscall(Sysauditon, a(data), a(length)) : int) + -> (syscall(Sysauditon, a(cmd), a(data), a(length)) : int) } const _umtx_op = {obj, op, val, uaddr1, uaddr2 - -> (syscall(Sys_umtx_op, a(op), a(val), a(uaddr1), a(uaddr2)) : int) + -> (syscall(Sys_umtx_op, a(obj), a(op), a(val), a(uaddr1), a(uaddr2)) : int) } const sigqueue = {pid, signum, value - -> (syscall(Syssigqueue, a(signum), a(value)) : int) + -> (syscall(Syssigqueue, a(pid), a(signum), a(value)) : int) } const abort2 = {why, nargs, args - -> (syscall(Sysabort2, a(nargs), a(args)) : int) + -> (syscall(Sysabort2, a(why), a(nargs), a(args)) : int) } const thr_set_name = {id, name - -> (syscall(Systhr_set_name, a(name)) : int) + -> (syscall(Systhr_set_name, a(id), a(name)) : int) } const aio_fsync = {op, aiocbp - -> (syscall(Sysaio_fsync, a(aiocbp)) : int) + -> (syscall(Sysaio_fsync, a(op), a(aiocbp)) : int) } const rtprio_thread = {function, lwpid, rtp - -> (syscall(Sysrtprio_thread, a(lwpid), a(rtp)) : int) + -> (syscall(Sysrtprio_thread, a(function), a(lwpid), a(rtp)) : int) } const truncate = {path, length - -> (syscall(Systruncate, a(length)) : int) + -> (syscall(Systruncate, a(path), a(length)) : int) } const ftruncate = {fd, length - -> (syscall(Sysftruncate, a(length)) : int) + -> (syscall(Sysftruncate, a(fd), a(length)) : int) } const thr_kill2 = {pid, id, sig - -> (syscall(Systhr_kill2, a(id), a(sig)) : int) + -> (syscall(Systhr_kill2, a(pid), a(id), a(sig)) : int) } const shm_open = {path, flags, mode - -> (syscall(Sysshm_open, a(flags), a(mode)) : int) + -> (syscall(Sysshm_open, a(path), a(flags), a(mode)) : int) } const shm_unlink = {path - -> (syscall(Sysshm_unlink) : int) + -> (syscall(Sysshm_unlink, a(path)) : int) } const cpuset = {setid - -> (syscall(Syscpuset) : int) + -> (syscall(Syscpuset, a(setid)) : int) } const cpuset_setid = {which, id, setid - -> (syscall(Syscpuset_setid, a(id), a(setid)) : int) + -> (syscall(Syscpuset_setid, a(which), a(id), a(setid)) : int) } const cpuset_getid = {level, which, id, setid - -> (syscall(Syscpuset_getid, a(which), a(id), a(setid)) : int) + -> (syscall(Syscpuset_getid, a(level), a(which), a(id), a(setid)) : int) } const cpuset_getaffinity = {level, which, id, cpusetsize, mask - -> (syscall(Syscpuset_getaffinity, a(which), a(id), a(cpusetsize), a(mask)) : int) + -> (syscall(Syscpuset_getaffinity, a(level), a(which), a(id), a(cpusetsize), a(mask)) : int) } const cpuset_setaffinity = {level, which, id, cpusetsize, mask - -> (syscall(Syscpuset_setaffinity, a(which), a(id), a(cpusetsize), a(mask)) : int) + -> (syscall(Syscpuset_setaffinity, a(level), a(which), a(id), a(cpusetsize), a(mask)) : int) } const faccessat = {fd, path, amode, flag - -> (syscall(Sysfaccessat, a(path), a(amode), a(flag)) : int) + -> (syscall(Sysfaccessat, a(fd), a(path), a(amode), a(flag)) : int) } const fchmodat = {fd, path, mode, flag - -> (syscall(Sysfchmodat, a(path), a(mode), a(flag)) : int) + -> (syscall(Sysfchmodat, a(fd), a(path), a(mode), a(flag)) : int) } const fchownat = {fd, path, uid, gid, flag - -> (syscall(Sysfchownat, a(path), a(uid), a(gid), a(flag)) : int) + -> (syscall(Sysfchownat, a(fd), a(path), a(uid), a(gid), a(flag)) : int) } const fexecve = {fd, argv, envv - -> (syscall(Sysfexecve, a(argv), a(envv)) : int) + -> (syscall(Sysfexecve, a(fd), a(argv), a(envv)) : int) } const fstatat = {fd, path, buf, flag - -> (syscall(Sysfstatat, a(path), a(buf), a(flag)) : int) + -> (syscall(Sysfstatat, a(fd), a(path), a(buf), a(flag)) : int) } const futimesat = {fd, path, times - -> (syscall(Sysfutimesat, a(path), a(times)) : int) + -> (syscall(Sysfutimesat, a(fd), a(path), a(times)) : int) } const linkat = {fd1, path1, fd2, path2, flag - -> (syscall(Syslinkat, a(path1), a(fd2), a(path2), a(flag)) : int) + -> (syscall(Syslinkat, a(fd1), a(path1), a(fd2), a(path2), a(flag)) : int) } const mkdirat = {fd, path, mode - -> (syscall(Sysmkdirat, a(path), a(mode)) : int) + -> (syscall(Sysmkdirat, a(fd), a(path), a(mode)) : int) } const mkfifoat = {fd, path, mode - -> (syscall(Sysmkfifoat, a(path), a(mode)) : int) + -> (syscall(Sysmkfifoat, a(fd), a(path), a(mode)) : int) } const mknodat = {fd, path, mode, dev - -> (syscall(Sysmknodat, a(path), a(mode), a(dev)) : int) + -> (syscall(Sysmknodat, a(fd), a(path), a(mode), a(dev)) : int) } const openat = {fd, path, flag, mode - -> (syscall(Sysopenat, a(path), a(flag), a(mode)) : int) + -> (syscall(Sysopenat, a(fd), a(path), a(flag), a(mode)) : int) } const readlinkat = {fd, path, buf, bufsize - -> (syscall(Sysreadlinkat, a(path), a(buf), a(bufsize)) : int) + -> (syscall(Sysreadlinkat, a(fd), a(path), a(buf), a(bufsize)) : int) } const renameat = {oldfd, old, newfd, new - -> (syscall(Sysrenameat, a(old), a(newfd), a(new)) : int) + -> (syscall(Sysrenameat, a(oldfd), a(old), a(newfd), a(new)) : int) } const symlinkat = {path1, fd, path2 - -> (syscall(Syssymlinkat, a(fd), a(path2)) : int) + -> (syscall(Syssymlinkat, a(path1), a(fd), a(path2)) : int) } const unlinkat = {fd, path, flag - -> (syscall(Sysunlinkat, a(path), a(flag)) : int) + -> (syscall(Sysunlinkat, a(fd), a(path), a(flag)) : int) } const posix_openpt = {flags - -> (syscall(Sysposix_openpt) : int) + -> (syscall(Sysposix_openpt, a(flags)) : int) } const jail_get = {iovp, iovcnt, flags - -> (syscall(Sysjail_get, a(iovcnt), a(flags)) : int) + -> (syscall(Sysjail_get, a(iovp), a(iovcnt), a(flags)) : int) } const jail_set = {iovp, iovcnt, flags - -> (syscall(Sysjail_set, a(iovcnt), a(flags)) : int) + -> (syscall(Sysjail_set, a(iovp), a(iovcnt), a(flags)) : int) } const jail_remove = {jid - -> (syscall(Sysjail_remove) : int) + -> (syscall(Sysjail_remove, a(jid)) : int) } const closefrom = {lowfd - -> (syscall(Sysclosefrom) : int) + -> (syscall(Sysclosefrom, a(lowfd)) : int) } const lpathconf = {path, name - -> (syscall(Syslpathconf, a(name)) : int) + -> (syscall(Syslpathconf, a(path), a(name)) : int) } const __cap_rights_get = {version, fd, rightsp - -> (syscall(Sys__cap_rights_get, a(fd), a(rightsp)) : int) + -> (syscall(Sys__cap_rights_get, a(version), a(fd), a(rightsp)) : int) } const cap_enter = { -> (syscall(Syscap_enter) : int) } const cap_getmode = {modep - -> (syscall(Syscap_getmode) : int) + -> (syscall(Syscap_getmode, a(modep)) : int) } const pdfork = {fdp, flags - -> (syscall(Syspdfork, a(flags)) : int) + -> (syscall(Syspdfork, a(fdp), a(flags)) : int) } const pdkill = {fd, signum - -> (syscall(Syspdkill, a(signum)) : int) + -> (syscall(Syspdkill, a(fd), a(signum)) : int) } const pdgetpid = {fd, pidp - -> (syscall(Syspdgetpid, a(pidp)) : int) + -> (syscall(Syspdgetpid, a(fd), a(pidp)) : int) } const pselect = {nd, _in, ou, ex, ts, sm - -> (syscall(Syspselect, a(_in), a(ou), a(ex), a(ts), a(sm)) : int) + -> (syscall(Syspselect, a(nd), a(_in), a(ou), a(ex), a(ts), a(sm)) : int) } const getloginclass = {namebuf, namelen - -> (syscall(Sysgetloginclass, a(namelen)) : int) + -> (syscall(Sysgetloginclass, a(namebuf), a(namelen)) : int) } const setloginclass = {namebuf - -> (syscall(Syssetloginclass) : int) + -> (syscall(Syssetloginclass, a(namebuf)) : int) } const rctl_get_racct = {inbufp, inbuflen, outbufp, outbuflen - -> (syscall(Sysrctl_get_racct, a(inbuflen), a(outbufp), a(outbuflen)) : int) + -> (syscall(Sysrctl_get_racct, a(inbufp), a(inbuflen), a(outbufp), a(outbuflen)) : int) } const rctl_get_rules = {inbufp, inbuflen, outbufp, outbuflen - -> (syscall(Sysrctl_get_rules, a(inbuflen), a(outbufp), a(outbuflen)) : int) + -> (syscall(Sysrctl_get_rules, a(inbufp), a(inbuflen), a(outbufp), a(outbuflen)) : int) } const rctl_get_limits = {inbufp, inbuflen, outbufp, outbuflen - -> (syscall(Sysrctl_get_limits, a(inbuflen), a(outbufp), a(outbuflen)) : int) + -> (syscall(Sysrctl_get_limits, a(inbufp), a(inbuflen), a(outbufp), a(outbuflen)) : int) } const rctl_add_rule = {inbufp, inbuflen, outbufp, outbuflen - -> (syscall(Sysrctl_add_rule, a(inbuflen), a(outbufp), a(outbuflen)) : int) + -> (syscall(Sysrctl_add_rule, a(inbufp), a(inbuflen), a(outbufp), a(outbuflen)) : int) } const rctl_remove_rule = {inbufp, inbuflen, outbufp, outbuflen - -> (syscall(Sysrctl_remove_rule, a(inbuflen), a(outbufp), a(outbuflen)) : int) + -> (syscall(Sysrctl_remove_rule, a(inbufp), a(inbuflen), a(outbufp), a(outbuflen)) : int) } const posix_fallocate = {fd, offset, len - -> (syscall(Sysposix_fallocate, a(offset), a(len)) : int) + -> (syscall(Sysposix_fallocate, a(fd), a(offset), a(len)) : int) } const posix_fadvise = {fd, offset, len, advice - -> (syscall(Sysposix_fadvise, a(offset), a(len), a(advice)) : int) + -> (syscall(Sysposix_fadvise, a(fd), a(offset), a(len), a(advice)) : int) } const wait6 = {idtype, id, status, options, wrusage, info - -> (syscall(Syswait6, a(id), a(status), a(options), a(wrusage), a(info)) : int) + -> (syscall(Syswait6, a(idtype), a(id), a(status), a(options), a(wrusage), a(info)) : int) } const cap_rights_limit = {fd, rightsp - -> (syscall(Syscap_rights_limit, a(rightsp)) : int) + -> (syscall(Syscap_rights_limit, a(fd), a(rightsp)) : int) } const cap_ioctls_limit = {fd, cmds, ncmds - -> (syscall(Syscap_ioctls_limit, a(cmds), a(ncmds)) : int) + -> (syscall(Syscap_ioctls_limit, a(fd), a(cmds), a(ncmds)) : int) } const cap_ioctls_get = {fd, cmds, maxcmds - -> (syscall(Syscap_ioctls_get, a(cmds), a(maxcmds)) : size) + -> (syscall(Syscap_ioctls_get, a(fd), a(cmds), a(maxcmds)) : size) } const cap_fcntls_limit = {fd, fcntlrights - -> (syscall(Syscap_fcntls_limit, a(fcntlrights)) : int) + -> (syscall(Syscap_fcntls_limit, a(fd), a(fcntlrights)) : int) } const cap_fcntls_get = {fd, fcntlrightsp - -> (syscall(Syscap_fcntls_get, a(fcntlrightsp)) : int) + -> (syscall(Syscap_fcntls_get, a(fd), a(fcntlrightsp)) : int) } const bindat = {fd, s, name, namelen - -> (syscall(Sysbindat, a(s), a(name), a(namelen)) : int) + -> (syscall(Sysbindat, a(fd), a(s), a(name), a(namelen)) : int) } const connectat = {fd, s, name, namelen - -> (syscall(Sysconnectat, a(s), a(name), a(namelen)) : int) + -> (syscall(Sysconnectat, a(fd), a(s), a(name), a(namelen)) : int) } const chflagsat = {fd, path, flags, atflag - -> (syscall(Syschflagsat, a(path), a(flags), a(atflag)) : int) + -> (syscall(Syschflagsat, a(fd), a(path), a(flags), a(atflag)) : int) } const accept4 = {s, name, anamelen, flags - -> (syscall(Sysaccept4, a(name), a(anamelen), a(flags)) : int) + -> (syscall(Sysaccept4, a(s), a(name), a(anamelen), a(flags)) : int) } const pipe2 = {fildes, flags - -> (syscall(Syspipe2, a(flags)) : int) + -> (syscall(Syspipe2, a(fildes), a(flags)) : int) } const aio_mlock = {aiocbp - -> (syscall(Sysaio_mlock) : int) + -> (syscall(Sysaio_mlock, a(aiocbp)) : int) } const procctl = {idtype, id, com, data - -> (syscall(Sysprocctl, a(id), a(com), a(data)) : int) + -> (syscall(Sysprocctl, a(idtype), a(id), a(com), a(data)) : int) } const ppoll = {fds, nfds, ts, set - -> (syscall(Sysppoll, a(nfds), a(ts), a(set)) : int) + -> (syscall(Sysppoll, a(fds), a(nfds), a(ts), a(set)) : int) } const futimens = {fd, times - -> (syscall(Sysfutimens, a(times)) : int) + -> (syscall(Sysfutimens, a(fd), a(times)) : int) } const utimensat = {fd, path, times, flag - -> (syscall(Sysutimensat, a(path), a(times), a(flag)) : int) + -> (syscall(Sysutimensat, a(fd), a(path), a(times), a(flag)) : int) } diff --git a/lib/sys/sys+linux-x64.myr b/lib/sys/sys+linux-x64.myr index d8a1d96..e5c8d35 100644 --- a/lib/sys/sys+linux-x64.myr +++ b/lib/sys/sys+linux-x64.myr @@ -10,6 +10,7 @@ pkg sys = type intptr = uint64 /* can hold any pointer losslessly */ type time = int64 /* milliseconds since epoch */ type scno = int64 /* syscall */ + type ioctlno = int64 /* ioctl */ /* processes/threads */ type pid = int /* process id */ @@ -1177,6 +1178,49 @@ pkg sys = const Syspkey_alloc : scno = 330 const Syspkey_free : scno = 331 + const Tcsetaf : ioctlno = 0x00005408 + const Tcsbrk : ioctlno = 0x00005409 + const Tcxonc : ioctlno = 0x0000540A + const Tcflsh : ioctlno = 0x0000540B + const Tiocexcl : ioctlno = 0x0000540C + const Tiocnxcl : ioctlno = 0x0000540D + const Tiocsctty : ioctlno = 0x0000540E + const Tiocgpgrp : ioctlno = 0x0000540F + const Tiocspgrp : ioctlno = 0x00005410 + const Tiocoutq : ioctlno = 0x00005411 + const Tiocsti : ioctlno = 0x00005412 + const Tiocgwinsz : ioctlno = 0x00005413 + const Tiocswinsz : ioctlno = 0x00005414 + const Tiocmget : ioctlno = 0x00005415 + const Tiocmbis : ioctlno = 0x00005416 + const Tiocmbic : ioctlno = 0x00005417 + const Tiocmset : ioctlno = 0x00005418 + const Tiocgsoftcar : ioctlno = 0x00005419 + const Tiocssoftcar : ioctlno = 0x0000541A + const Fionread : ioctlno = 0x0000541B + const Tiocinq : ioctlno = 0x0000541B + const Tioclinux : ioctlno = 0x0000541C + const Tioccons : ioctlno = 0x0000541D + const Tiocgserial : ioctlno = 0x0000541E + const Tiocsserial : ioctlno = 0x0000541F + const Tiocpkt : ioctlno = 0x00005420 + const Fionbio : ioctlno = 0x00005421 + const Tiocnotty : ioctlno = 0x00005422 + const Tiocsetd : ioctlno = 0x00005423 + const Tiocgetd : ioctlno = 0x00005424 + const Tcsbrkp : ioctlno = 0x00005425 + const Tiocttygstruct : ioctlno = 0x00005426 + const Fionclex : ioctlno = 0x00005450 + const Fioclex : ioctlno = 0x00005451 + const Fioasync : ioctlno = 0x00005452 + const Tiocserconfig : ioctlno = 0x00005453 + const Tiocsergwild : ioctlno = 0x00005454 + const Tiocserswild : ioctlno = 0x00005455 + const Tiocglcktrmios : ioctlno = 0x00005456 + const Tiocslcktrmios : ioctlno = 0x00005457 + const Tiocsergstruct : ioctlno = 0x00005458 + const Tiocsergetlsr : ioctlno = 0x00005459 + /* start manual overrides { */ extern const syscall : (sc:scno, args:... -> int64) extern const sigreturn : (-> void) @@ -1215,7 +1259,7 @@ pkg sys = const lstat : (path:byte[:], sb:statbuf# -> int64) const fstat : (fd:fd, sb:statbuf# -> int64) const mkdir : (path : byte[:], mode : int64 -> int64) - generic ioctl : (fd:fd, req : int64, arg:@a# -> int64) + generic ioctl : (fd:fd, req : ioctlno, arg:@a# -> int64) const getdents64 : (fd:fd, buf : byte[:] -> int64) const chdir : (p : byte[:] -> int64) const getcwd : (buf : byte[:] -> int64) @@ -1721,25 +1765,25 @@ pkg sys = } /* } end manual overrides */ const time = {tloc - -> (syscall(Systime) : int64) + -> (syscall(Systime, a(tloc)) : int64) } const gettimeofday = {tv, tz - -> (syscall(Sysgettimeofday, a(tz)) : int64) + -> (syscall(Sysgettimeofday, a(tv), a(tz)) : int64) } const settimeofday = {tv, tz - -> (syscall(Syssettimeofday, a(tz)) : int64) + -> (syscall(Syssettimeofday, a(tv), a(tz)) : int64) } const adjtimex = {txc_p - -> (syscall(Sysadjtimex) : int64) + -> (syscall(Sysadjtimex, a(txc_p)) : int64) } const times = {tbuf - -> (syscall(Systimes) : int64) + -> (syscall(Systimes, a(tbuf)) : int64) } const gettid = { -> (syscall(Sysgettid) : int64) } const alarm = {seconds - -> (syscall(Sysalarm) : int64) + -> (syscall(Sysalarm, a(seconds)) : int64) } const getppid = { -> (syscall(Sysgetppid) : int64) @@ -1751,187 +1795,187 @@ const getegid = { -> (syscall(Sysgetegid) : int64) } const getresuid = {ruid, euid, suid - -> (syscall(Sysgetresuid, a(euid), a(suid)) : int64) + -> (syscall(Sysgetresuid, a(ruid), a(euid), a(suid)) : int64) } const getresgid = {rgid, egid, sgid - -> (syscall(Sysgetresgid, a(egid), a(sgid)) : int64) + -> (syscall(Sysgetresgid, a(rgid), a(egid), a(sgid)) : int64) } const getpgid = {pid - -> (syscall(Sysgetpgid) : int64) + -> (syscall(Sysgetpgid, a(pid)) : int64) } const getpgrp = { -> (syscall(Sysgetpgrp) : int64) } const getsid = {pid - -> (syscall(Sysgetsid) : int64) + -> (syscall(Sysgetsid, a(pid)) : int64) } const getgroups = {gidsetsize, grouplist - -> (syscall(Sysgetgroups, a(grouplist)) : int64) + -> (syscall(Sysgetgroups, a(gidsetsize), a(grouplist)) : int64) } const setregid = {rgid, egid - -> (syscall(Syssetregid, a(egid)) : int64) + -> (syscall(Syssetregid, a(rgid), a(egid)) : int64) } const setreuid = {ruid, euid - -> (syscall(Syssetreuid, a(euid)) : int64) + -> (syscall(Syssetreuid, a(ruid), a(euid)) : int64) } const setresuid = {ruid, euid, suid - -> (syscall(Syssetresuid, a(euid), a(suid)) : int64) + -> (syscall(Syssetresuid, a(ruid), a(euid), a(suid)) : int64) } const setresgid = {rgid, egid, sgid - -> (syscall(Syssetresgid, a(egid), a(sgid)) : int64) + -> (syscall(Syssetresgid, a(rgid), a(egid), a(sgid)) : int64) } const setfsuid = {uid - -> (syscall(Syssetfsuid) : int64) + -> (syscall(Syssetfsuid, a(uid)) : int64) } const setfsgid = {gid - -> (syscall(Syssetfsgid) : int64) + -> (syscall(Syssetfsgid, a(gid)) : int64) } const setpgid = {pid, pgid - -> (syscall(Syssetpgid, a(pgid)) : int64) + -> (syscall(Syssetpgid, a(pid), a(pgid)) : int64) } const setsid = { -> (syscall(Syssetsid) : int64) } const setgroups = {gidsetsize, grouplist - -> (syscall(Syssetgroups, a(grouplist)) : int64) + -> (syscall(Syssetgroups, a(gidsetsize), a(grouplist)) : int64) } const acct = {name - -> (syscall(Sysacct) : int64) + -> (syscall(Sysacct, a(name)) : int64) } const capget = {header, dataptr - -> (syscall(Syscapget, a(dataptr)) : int64) + -> (syscall(Syscapget, a(header), a(dataptr)) : int64) } const capset = {header, data - -> (syscall(Syscapset, a(data)) : int64) + -> (syscall(Syscapset, a(header), a(data)) : int64) } const personality = {personality - -> (syscall(Syspersonality) : int64) + -> (syscall(Syspersonality, a(personality)) : int64) } const sigaltstack = {uss, uoss - -> (syscall(Syssigaltstack, a(uoss)) : int64) + -> (syscall(Syssigaltstack, a(uss), a(uoss)) : int64) } const getitimer = {which, value - -> (syscall(Sysgetitimer, a(value)) : int64) + -> (syscall(Sysgetitimer, a(which), a(value)) : int64) } const setitimer = {which, value, ovalue - -> (syscall(Syssetitimer, a(value), a(ovalue)) : int64) + -> (syscall(Syssetitimer, a(which), a(value), a(ovalue)) : int64) } const timer_create = {which_clock, timer_event_spec, created_timer_id - -> (syscall(Systimer_create, a(timer_event_spec), a(created_timer_id)) : int64) + -> (syscall(Systimer_create, a(which_clock), a(timer_event_spec), a(created_timer_id)) : int64) } const timer_gettime = {timer_id, setting - -> (syscall(Systimer_gettime, a(setting)) : int64) + -> (syscall(Systimer_gettime, a(timer_id), a(setting)) : int64) } const timer_getoverrun = {timer_id - -> (syscall(Systimer_getoverrun) : int64) + -> (syscall(Systimer_getoverrun, a(timer_id)) : int64) } const timer_settime = {timer_id, flags, new_setting, old_setting - -> (syscall(Systimer_settime, a(flags), a(new_setting), a(old_setting)) : int64) + -> (syscall(Systimer_settime, a(timer_id), a(flags), a(new_setting), a(old_setting)) : int64) } const timer_delete = {timer_id - -> (syscall(Systimer_delete) : int64) + -> (syscall(Systimer_delete, a(timer_id)) : int64) } const clock_adjtime = {which_clock, tx - -> (syscall(Sysclock_adjtime, a(tx)) : int64) + -> (syscall(Sysclock_adjtime, a(which_clock), a(tx)) : int64) } const clock_nanosleep = {which_clock, flags, rqtp, rmtp - -> (syscall(Sysclock_nanosleep, a(flags), a(rqtp), a(rmtp)) : int64) + -> (syscall(Sysclock_nanosleep, a(which_clock), a(flags), a(rqtp), a(rmtp)) : int64) } const sched_setscheduler = {pid, policy, param - -> (syscall(Syssched_setscheduler, a(policy), a(param)) : int64) + -> (syscall(Syssched_setscheduler, a(pid), a(policy), a(param)) : int64) } const sched_setparam = {pid, param - -> (syscall(Syssched_setparam, a(param)) : int64) + -> (syscall(Syssched_setparam, a(pid), a(param)) : int64) } const sched_setattr = {pid, attr, flags - -> (syscall(Syssched_setattr, a(attr), a(flags)) : int64) + -> (syscall(Syssched_setattr, a(pid), a(attr), a(flags)) : int64) } const sched_getscheduler = {pid - -> (syscall(Syssched_getscheduler) : int64) + -> (syscall(Syssched_getscheduler, a(pid)) : int64) } const sched_getparam = {pid, param - -> (syscall(Syssched_getparam, a(param)) : int64) + -> (syscall(Syssched_getparam, a(pid), a(param)) : int64) } const sched_getattr = {pid, attr, size, flags - -> (syscall(Syssched_getattr, a(attr), a(size), a(flags)) : int64) + -> (syscall(Syssched_getattr, a(pid), a(attr), a(size), a(flags)) : int64) } const sched_setaffinity = {pid, len, user_mask_ptr - -> (syscall(Syssched_setaffinity, a(len), a(user_mask_ptr)) : int64) + -> (syscall(Syssched_setaffinity, a(pid), a(len), a(user_mask_ptr)) : int64) } const sched_getaffinity = {pid, len, user_mask_ptr - -> (syscall(Syssched_getaffinity, a(len), a(user_mask_ptr)) : int64) + -> (syscall(Syssched_getaffinity, a(pid), a(len), a(user_mask_ptr)) : int64) } const sched_yield = { -> (syscall(Syssched_yield) : int64) } const sched_get_priority_max = {policy - -> (syscall(Syssched_get_priority_max) : int64) + -> (syscall(Syssched_get_priority_max, a(policy)) : int64) } const sched_get_priority_min = {policy - -> (syscall(Syssched_get_priority_min) : int64) + -> (syscall(Syssched_get_priority_min, a(policy)) : int64) } const sched_rr_get_interval = {pid, interval - -> (syscall(Syssched_rr_get_interval, a(interval)) : int64) + -> (syscall(Syssched_rr_get_interval, a(pid), a(interval)) : int64) } const setpriority = {which, who, niceval - -> (syscall(Syssetpriority, a(who), a(niceval)) : int64) + -> (syscall(Syssetpriority, a(which), a(who), a(niceval)) : int64) } const getpriority = {which, who - -> (syscall(Sysgetpriority, a(who)) : int64) + -> (syscall(Sysgetpriority, a(which), a(who)) : int64) } const shutdown = {_a0, _a1 - -> (syscall(Sysshutdown, a(_a1)) : int64) + -> (syscall(Sysshutdown, a(_a0), a(_a1)) : int64) } const reboot = {magic1, magic2, cmd, arg - -> (syscall(Sysreboot, a(magic2), a(cmd), a(arg)) : int64) + -> (syscall(Sysreboot, a(magic1), a(magic2), a(cmd), a(arg)) : int64) } const restart_syscall = { -> (syscall(Sysrestart_syscall) : int64) } const kexec_load = {entry, nr_segments, segments, flags - -> (syscall(Syskexec_load, a(nr_segments), a(segments), a(flags)) : int64) + -> (syscall(Syskexec_load, a(entry), a(nr_segments), a(segments), a(flags)) : int64) } const kexec_file_load = {kernel_fd, initrd_fd, cmdline_len, cmdline_ptr, flags - -> (syscall(Syskexec_file_load, a(initrd_fd), a(cmdline_len), a(cmdline_ptr), a(flags)) : int64) + -> (syscall(Syskexec_file_load, a(kernel_fd), a(initrd_fd), a(cmdline_len), a(cmdline_ptr), a(flags)) : int64) } const waitid = {which, pid, infop, options, ru - -> (syscall(Syswaitid, a(pid), a(infop), a(options), a(ru)) : int64) + -> (syscall(Syswaitid, a(which), a(pid), a(infop), a(options), a(ru)) : int64) } const set_tid_address = {tidptr - -> (syscall(Sysset_tid_address) : int64) + -> (syscall(Sysset_tid_address, a(tidptr)) : int64) } const init_module = {umod, len, uargs - -> (syscall(Sysinit_module, a(len), a(uargs)) : int64) + -> (syscall(Sysinit_module, a(umod), a(len), a(uargs)) : int64) } const delete_module = {name_user, flags - -> (syscall(Sysdelete_module, a(flags)) : int64) + -> (syscall(Sysdelete_module, a(name_user), a(flags)) : int64) } const rt_sigsuspend = {unewset, sigsetsize - -> (syscall(Sysrt_sigsuspend, a(sigsetsize)) : int64) + -> (syscall(Sysrt_sigsuspend, a(unewset), a(sigsetsize)) : int64) } const rt_sigaction = {_a0, _a1, _a2, _a3 - -> (syscall(Sysrt_sigaction, a(_a1), a(_a2), a(_a3)) : int64) + -> (syscall(Sysrt_sigaction, a(_a0), a(_a1), a(_a2), a(_a3)) : int64) } const rt_sigprocmask = {how, set, oset, sigsetsize - -> (syscall(Sysrt_sigprocmask, a(set), a(oset), a(sigsetsize)) : int64) + -> (syscall(Sysrt_sigprocmask, a(how), a(set), a(oset), a(sigsetsize)) : int64) } const rt_sigpending = {set, sigsetsize - -> (syscall(Sysrt_sigpending, a(sigsetsize)) : int64) + -> (syscall(Sysrt_sigpending, a(set), a(sigsetsize)) : int64) } const rt_sigtimedwait = {uthese, uinfo, uts, sigsetsize - -> (syscall(Sysrt_sigtimedwait, a(uinfo), a(uts), a(sigsetsize)) : int64) + -> (syscall(Sysrt_sigtimedwait, a(uthese), a(uinfo), a(uts), a(sigsetsize)) : int64) } const rt_tgsigqueueinfo = {tgid, pid, sig, uinfo - -> (syscall(Sysrt_tgsigqueueinfo, a(pid), a(sig), a(uinfo)) : int64) + -> (syscall(Sysrt_tgsigqueueinfo, a(tgid), a(pid), a(sig), a(uinfo)) : int64) } const tgkill = {tgid, pid, sig - -> (syscall(Systgkill, a(pid), a(sig)) : int64) + -> (syscall(Systgkill, a(tgid), a(pid), a(sig)) : int64) } const tkill = {pid, sig - -> (syscall(Systkill, a(sig)) : int64) + -> (syscall(Systkill, a(pid), a(sig)) : int64) } const rt_sigqueueinfo = {pid, sig, uinfo - -> (syscall(Sysrt_sigqueueinfo, a(sig), a(uinfo)) : int64) + -> (syscall(Sysrt_sigqueueinfo, a(pid), a(sig), a(uinfo)) : int64) } const pause = { -> (syscall(Syspause) : int64) @@ -1940,557 +1984,557 @@ const sync = { -> (syscall(Syssync) : int64) } const fsync = {fd - -> (syscall(Sysfsync) : int64) + -> (syscall(Sysfsync, a(fd)) : int64) } const fdatasync = {fd - -> (syscall(Sysfdatasync) : int64) + -> (syscall(Sysfdatasync, a(fd)) : int64) } const mount = {dev_name, dir_name, kind, flags, data - -> (syscall(Sysmount, a(dir_name), a(kind), a(flags), a(data)) : int64) + -> (syscall(Sysmount, a(dev_name), a(dir_name), a(kind), a(flags), a(data)) : int64) } const umount2 = {name, flags - -> (syscall(Sysumount2, a(flags)) : int64) + -> (syscall(Sysumount2, a(name), a(flags)) : int64) } const truncate = {path, length - -> (syscall(Systruncate, a(length)) : int64) + -> (syscall(Systruncate, a(path), a(length)) : int64) } const ftruncate = {fd, length - -> (syscall(Sysftruncate, a(length)) : int64) + -> (syscall(Sysftruncate, a(fd), a(length)) : int64) } const statfs = {path, buf - -> (syscall(Sysstatfs, a(buf)) : int64) + -> (syscall(Sysstatfs, a(path), a(buf)) : int64) } const fstatfs = {fd, buf - -> (syscall(Sysfstatfs, a(buf)) : int64) + -> (syscall(Sysfstatfs, a(fd), a(buf)) : int64) } const ustat = {dev, ubuf - -> (syscall(Sysustat, a(ubuf)) : int64) + -> (syscall(Sysustat, a(dev), a(ubuf)) : int64) } const setxattr = {path, name, value, size, flags - -> (syscall(Syssetxattr, a(name), a(value), a(size), a(flags)) : int64) + -> (syscall(Syssetxattr, a(path), a(name), a(value), a(size), a(flags)) : int64) } const lsetxattr = {path, name, value, size, flags - -> (syscall(Syslsetxattr, a(name), a(value), a(size), a(flags)) : int64) + -> (syscall(Syslsetxattr, a(path), a(name), a(value), a(size), a(flags)) : int64) } const fsetxattr = {fd, name, value, size, flags - -> (syscall(Sysfsetxattr, a(name), a(value), a(size), a(flags)) : int64) + -> (syscall(Sysfsetxattr, a(fd), a(name), a(value), a(size), a(flags)) : int64) } const getxattr = {path, name, value, size - -> (syscall(Sysgetxattr, a(name), a(value), a(size)) : int64) + -> (syscall(Sysgetxattr, a(path), a(name), a(value), a(size)) : int64) } const lgetxattr = {path, name, value, size - -> (syscall(Syslgetxattr, a(name), a(value), a(size)) : int64) + -> (syscall(Syslgetxattr, a(path), a(name), a(value), a(size)) : int64) } const fgetxattr = {fd, name, value, size - -> (syscall(Sysfgetxattr, a(name), a(value), a(size)) : int64) + -> (syscall(Sysfgetxattr, a(fd), a(name), a(value), a(size)) : int64) } const listxattr = {path, list, size - -> (syscall(Syslistxattr, a(list), a(size)) : int64) + -> (syscall(Syslistxattr, a(path), a(list), a(size)) : int64) } const llistxattr = {path, list, size - -> (syscall(Sysllistxattr, a(list), a(size)) : int64) + -> (syscall(Sysllistxattr, a(path), a(list), a(size)) : int64) } const flistxattr = {fd, list, size - -> (syscall(Sysflistxattr, a(list), a(size)) : int64) + -> (syscall(Sysflistxattr, a(fd), a(list), a(size)) : int64) } const removexattr = {path, name - -> (syscall(Sysremovexattr, a(name)) : int64) + -> (syscall(Sysremovexattr, a(path), a(name)) : int64) } const lremovexattr = {path, name - -> (syscall(Syslremovexattr, a(name)) : int64) + -> (syscall(Syslremovexattr, a(path), a(name)) : int64) } const fremovexattr = {fd, name - -> (syscall(Sysfremovexattr, a(name)) : int64) + -> (syscall(Sysfremovexattr, a(fd), a(name)) : int64) } const brk = {brk - -> (syscall(Sysbrk) : int64) + -> (syscall(Sysbrk, a(brk)) : int64) } const mprotect = {start, len, prot - -> (syscall(Sysmprotect, a(len), a(prot)) : int64) + -> (syscall(Sysmprotect, a(start), a(len), a(prot)) : int64) } const mremap = {addr, old_len, new_len, flags, new_addr - -> (syscall(Sysmremap, a(old_len), a(new_len), a(flags), a(new_addr)) : int64) + -> (syscall(Sysmremap, a(addr), a(old_len), a(new_len), a(flags), a(new_addr)) : int64) } const remap_file_pages = {start, size, prot, pgoff, flags - -> (syscall(Sysremap_file_pages, a(size), a(prot), a(pgoff), a(flags)) : int64) + -> (syscall(Sysremap_file_pages, a(start), a(size), a(prot), a(pgoff), a(flags)) : int64) } const msync = {start, len, flags - -> (syscall(Sysmsync, a(len), a(flags)) : int64) + -> (syscall(Sysmsync, a(start), a(len), a(flags)) : int64) } const fadvise = {fd, offset, len, advice - -> (syscall(Sysfadvise, a(offset), a(len), a(advice)) : int64) + -> (syscall(Sysfadvise, a(fd), a(offset), a(len), a(advice)) : int64) } const mlock = {start, len - -> (syscall(Sysmlock, a(len)) : int64) + -> (syscall(Sysmlock, a(start), a(len)) : int64) } const munlock = {start, len - -> (syscall(Sysmunlock, a(len)) : int64) + -> (syscall(Sysmunlock, a(start), a(len)) : int64) } const mlockall = {flags - -> (syscall(Sysmlockall) : int64) + -> (syscall(Sysmlockall, a(flags)) : int64) } const munlockall = { -> (syscall(Sysmunlockall) : int64) } const madvise = {start, len, behavior - -> (syscall(Sysmadvise, a(len), a(behavior)) : int64) + -> (syscall(Sysmadvise, a(start), a(len), a(behavior)) : int64) } const mincore = {start, len, vec - -> (syscall(Sysmincore, a(len), a(vec)) : int64) + -> (syscall(Sysmincore, a(start), a(len), a(vec)) : int64) } const pivot_root = {new_root, put_old - -> (syscall(Syspivot_root, a(put_old)) : int64) + -> (syscall(Syspivot_root, a(new_root), a(put_old)) : int64) } const chroot = {filename - -> (syscall(Syschroot) : int64) + -> (syscall(Syschroot, a(filename)) : int64) } const mknod = {filename, mode, dev - -> (syscall(Sysmknod, a(mode), a(dev)) : int64) + -> (syscall(Sysmknod, a(filename), a(mode), a(dev)) : int64) } const link = {oldname, newname - -> (syscall(Syslink, a(newname)) : int64) + -> (syscall(Syslink, a(oldname), a(newname)) : int64) } const symlink = {old, new - -> (syscall(Syssymlink, a(new)) : int64) + -> (syscall(Syssymlink, a(old), a(new)) : int64) } const chmod = {filename, mode - -> (syscall(Syschmod, a(mode)) : int64) + -> (syscall(Syschmod, a(filename), a(mode)) : int64) } const fchmod = {fd, mode - -> (syscall(Sysfchmod, a(mode)) : int64) + -> (syscall(Sysfchmod, a(fd), a(mode)) : int64) } const fcntl = {fd, cmd, arg - -> (syscall(Sysfcntl, a(cmd), a(arg)) : int64) + -> (syscall(Sysfcntl, a(fd), a(cmd), a(arg)) : int64) } const pipe2 = {fildes, flags - -> (syscall(Syspipe2, a(flags)) : int64) + -> (syscall(Syspipe2, a(fildes), a(flags)) : int64) } const dup3 = {oldfd, newfd, flags - -> (syscall(Sysdup3, a(newfd), a(flags)) : int64) + -> (syscall(Sysdup3, a(oldfd), a(newfd), a(flags)) : int64) } const ioperm = {from, num, on - -> (syscall(Sysioperm, a(num), a(on)) : int64) + -> (syscall(Sysioperm, a(from), a(num), a(on)) : int64) } const flock = {fd, cmd - -> (syscall(Sysflock, a(cmd)) : int64) + -> (syscall(Sysflock, a(fd), a(cmd)) : int64) } const io_setup = {nr_reqs, ctx - -> (syscall(Sysio_setup, a(ctx)) : int64) + -> (syscall(Sysio_setup, a(nr_reqs), a(ctx)) : int64) } const io_destroy = {ctx - -> (syscall(Sysio_destroy) : int64) + -> (syscall(Sysio_destroy, a(ctx)) : int64) } const io_getevents = {ctx_id, min_nr, nr, events, timeout - -> (syscall(Sysio_getevents, a(min_nr), a(nr), a(events), a(timeout)) : int64) + -> (syscall(Sysio_getevents, a(ctx_id), a(min_nr), a(nr), a(events), a(timeout)) : int64) } const io_submit = {_a0, _a1, _a2 - -> (syscall(Sysio_submit, a(_a1), a(_a2)) : int64) + -> (syscall(Sysio_submit, a(_a0), a(_a1), a(_a2)) : int64) } const io_cancel = {ctx_id, iocb, result - -> (syscall(Sysio_cancel, a(iocb), a(result)) : int64) + -> (syscall(Sysio_cancel, a(ctx_id), a(iocb), a(result)) : int64) } const sendfile = {out_fd, in_fd, offset, count - -> (syscall(Syssendfile, a(in_fd), a(offset), a(count)) : int64) + -> (syscall(Syssendfile, a(out_fd), a(in_fd), a(offset), a(count)) : int64) } const access = {filename, mode - -> (syscall(Sysaccess, a(mode)) : int64) + -> (syscall(Sysaccess, a(filename), a(mode)) : int64) } const vhangup = { -> (syscall(Sysvhangup) : int64) } const chown = {filename, user, group - -> (syscall(Syschown, a(user), a(group)) : int64) + -> (syscall(Syschown, a(filename), a(user), a(group)) : int64) } const lchown = {filename, user, group - -> (syscall(Syslchown, a(user), a(group)) : int64) + -> (syscall(Syslchown, a(filename), a(user), a(group)) : int64) } const fchown = {fd, user, group - -> (syscall(Sysfchown, a(user), a(group)) : int64) + -> (syscall(Sysfchown, a(fd), a(user), a(group)) : int64) } const utime = {filename, times - -> (syscall(Sysutime, a(times)) : int64) + -> (syscall(Sysutime, a(filename), a(times)) : int64) } const utimes = {filename, utimes - -> (syscall(Sysutimes, a(utimes)) : int64) + -> (syscall(Sysutimes, a(filename), a(utimes)) : int64) } const readahead = {fd, offset, count - -> (syscall(Sysreadahead, a(offset), a(count)) : int64) + -> (syscall(Sysreadahead, a(fd), a(offset), a(count)) : int64) } const readv = {fd, vec, vlen - -> (syscall(Sysreadv, a(vec), a(vlen)) : int64) + -> (syscall(Sysreadv, a(fd), a(vec), a(vlen)) : int64) } const writev = {fd, vec, vlen - -> (syscall(Syswritev, a(vec), a(vlen)) : int64) + -> (syscall(Syswritev, a(fd), a(vec), a(vlen)) : int64) } const preadv = {fd, vec, vlen, pos_l, pos_h - -> (syscall(Syspreadv, a(vec), a(vlen), a(pos_l), a(pos_h)) : int64) + -> (syscall(Syspreadv, a(fd), a(vec), a(vlen), a(pos_l), a(pos_h)) : int64) } const preadv2 = {fd, vec, vlen, pos_l, pos_h, flags - -> (syscall(Syspreadv2, a(vec), a(vlen), a(pos_l), a(pos_h), a(flags)) : int64) + -> (syscall(Syspreadv2, a(fd), a(vec), a(vlen), a(pos_l), a(pos_h), a(flags)) : int64) } const pwritev = {fd, vec, vlen, pos_l, pos_h - -> (syscall(Syspwritev, a(vec), a(vlen), a(pos_l), a(pos_h)) : int64) + -> (syscall(Syspwritev, a(fd), a(vec), a(vlen), a(pos_l), a(pos_h)) : int64) } const pwritev2 = {fd, vec, vlen, pos_l, pos_h, flags - -> (syscall(Syspwritev2, a(vec), a(vlen), a(pos_l), a(pos_h), a(flags)) : int64) + -> (syscall(Syspwritev2, a(fd), a(vec), a(vlen), a(pos_l), a(pos_h), a(flags)) : int64) } const fchdir = {fd - -> (syscall(Sysfchdir) : int64) + -> (syscall(Sysfchdir, a(fd)) : int64) } const rmdir = {pathname - -> (syscall(Sysrmdir) : int64) + -> (syscall(Sysrmdir, a(pathname)) : int64) } const lookup_dcookie = {cookie64, buf, len - -> (syscall(Syslookup_dcookie, a(buf), a(len)) : int64) + -> (syscall(Syslookup_dcookie, a(cookie64), a(buf), a(len)) : int64) } const quotactl = {cmd, special, id, addr - -> (syscall(Sysquotactl, a(special), a(id), a(addr)) : int64) + -> (syscall(Sysquotactl, a(cmd), a(special), a(id), a(addr)) : int64) } const accept4 = {_a0, _a1, _a2, _a3 - -> (syscall(Sysaccept4, a(_a1), a(_a2), a(_a3)) : int64) + -> (syscall(Sysaccept4, a(_a0), a(_a1), a(_a2), a(_a3)) : int64) } const getsockname = {_a0, _a1, _a2 - -> (syscall(Sysgetsockname, a(_a1), a(_a2)) : int64) + -> (syscall(Sysgetsockname, a(_a0), a(_a1), a(_a2)) : int64) } const getpeername = {_a0, _a1, _a2 - -> (syscall(Sysgetpeername, a(_a1), a(_a2)) : int64) + -> (syscall(Sysgetpeername, a(_a0), a(_a1), a(_a2)) : int64) } const sendto = {_a0, _a1, _a2, _a3, _a4, _a5 - -> (syscall(Syssendto, a(_a1), a(_a2), a(_a3), a(_a4), a(_a5)) : int64) + -> (syscall(Syssendto, a(_a0), a(_a1), a(_a2), a(_a3), a(_a4), a(_a5)) : int64) } const sendmmsg = {fd, msg, vlen, flags - -> (syscall(Syssendmmsg, a(msg), a(vlen), a(flags)) : int64) + -> (syscall(Syssendmmsg, a(fd), a(msg), a(vlen), a(flags)) : int64) } const recvfrom = {_a0, _a1, _a2, _a3, _a4, _a5 - -> (syscall(Sysrecvfrom, a(_a1), a(_a2), a(_a3), a(_a4), a(_a5)) : int64) + -> (syscall(Sysrecvfrom, a(_a0), a(_a1), a(_a2), a(_a3), a(_a4), a(_a5)) : int64) } const recvmmsg = {fd, msg, vlen, flags, timeout - -> (syscall(Sysrecvmmsg, a(msg), a(vlen), a(flags), a(timeout)) : int64) + -> (syscall(Sysrecvmmsg, a(fd), a(msg), a(vlen), a(flags), a(timeout)) : int64) } const socketpair = {_a0, _a1, _a2, _a3 - -> (syscall(Syssocketpair, a(_a1), a(_a2), a(_a3)) : int64) + -> (syscall(Syssocketpair, a(_a0), a(_a1), a(_a2), a(_a3)) : int64) } const select = {n, inp, outp, exp, tvp - -> (syscall(Sysselect, a(inp), a(outp), a(exp), a(tvp)) : int64) + -> (syscall(Sysselect, a(n), a(inp), a(outp), a(exp), a(tvp)) : int64) } const epoll_create = {size - -> (syscall(Sysepoll_create) : int64) + -> (syscall(Sysepoll_create, a(size)) : int64) } const epoll_create1 = {flags - -> (syscall(Sysepoll_create1) : int64) + -> (syscall(Sysepoll_create1, a(flags)) : int64) } const epoll_ctl = {epfd, op, fd, event - -> (syscall(Sysepoll_ctl, a(op), a(fd), a(event)) : int64) + -> (syscall(Sysepoll_ctl, a(epfd), a(op), a(fd), a(event)) : int64) } const epoll_wait = {epfd, events, maxevents, timeout - -> (syscall(Sysepoll_wait, a(events), a(maxevents), a(timeout)) : int64) + -> (syscall(Sysepoll_wait, a(epfd), a(events), a(maxevents), a(timeout)) : int64) } const epoll_pwait = {epfd, events, maxevents, timeout, sigmask, sigsetsize - -> (syscall(Sysepoll_pwait, a(events), a(maxevents), a(timeout), a(sigmask), a(sigsetsize)) : int64) + -> (syscall(Sysepoll_pwait, a(epfd), a(events), a(maxevents), a(timeout), a(sigmask), a(sigsetsize)) : int64) } const sethostname = {name, len - -> (syscall(Syssethostname, a(len)) : int64) + -> (syscall(Syssethostname, a(name), a(len)) : int64) } const setdomainname = {name, len - -> (syscall(Syssetdomainname, a(len)) : int64) + -> (syscall(Syssetdomainname, a(name), a(len)) : int64) } const getrlimit = {resource, rlim - -> (syscall(Sysgetrlimit, a(rlim)) : int64) + -> (syscall(Sysgetrlimit, a(resource), a(rlim)) : int64) } const setrlimit = {resource, rlim - -> (syscall(Syssetrlimit, a(rlim)) : int64) + -> (syscall(Syssetrlimit, a(resource), a(rlim)) : int64) } const prlimit = {pid, resource, new_rlim, old_rlim - -> (syscall(Sysprlimit, a(resource), a(new_rlim), a(old_rlim)) : int64) + -> (syscall(Sysprlimit, a(pid), a(resource), a(new_rlim), a(old_rlim)) : int64) } const getrusage = {who, ru - -> (syscall(Sysgetrusage, a(ru)) : int64) + -> (syscall(Sysgetrusage, a(who), a(ru)) : int64) } const umask = {mask - -> (syscall(Sysumask) : int64) + -> (syscall(Sysumask, a(mask)) : int64) } const msgget = {key, msgflg - -> (syscall(Sysmsgget, a(msgflg)) : int64) + -> (syscall(Sysmsgget, a(key), a(msgflg)) : int64) } const msgsnd = {msqid, msgp, msgsz, msgflg - -> (syscall(Sysmsgsnd, a(msgp), a(msgsz), a(msgflg)) : int64) + -> (syscall(Sysmsgsnd, a(msqid), a(msgp), a(msgsz), a(msgflg)) : int64) } const msgrcv = {msqid, msgp, msgsz, msgtyp, msgflg - -> (syscall(Sysmsgrcv, a(msgp), a(msgsz), a(msgtyp), a(msgflg)) : int64) + -> (syscall(Sysmsgrcv, a(msqid), a(msgp), a(msgsz), a(msgtyp), a(msgflg)) : int64) } const msgctl = {msqid, cmd, buf - -> (syscall(Sysmsgctl, a(cmd), a(buf)) : int64) + -> (syscall(Sysmsgctl, a(msqid), a(cmd), a(buf)) : int64) } const semget = {key, nsems, semflg - -> (syscall(Syssemget, a(nsems), a(semflg)) : int64) + -> (syscall(Syssemget, a(key), a(nsems), a(semflg)) : int64) } const semop = {semid, sops, nsops - -> (syscall(Syssemop, a(sops), a(nsops)) : int64) + -> (syscall(Syssemop, a(semid), a(sops), a(nsops)) : int64) } const semtimedop = {semid, sops, nsops, timeout - -> (syscall(Syssemtimedop, a(sops), a(nsops), a(timeout)) : int64) + -> (syscall(Syssemtimedop, a(semid), a(sops), a(nsops), a(timeout)) : int64) } const shmat = {shmid, shmaddr, shmflg - -> (syscall(Sysshmat, a(shmaddr), a(shmflg)) : int64) + -> (syscall(Sysshmat, a(shmid), a(shmaddr), a(shmflg)) : int64) } const shmget = {key, size, flag - -> (syscall(Sysshmget, a(size), a(flag)) : int64) + -> (syscall(Sysshmget, a(key), a(size), a(flag)) : int64) } const shmdt = {shmaddr - -> (syscall(Sysshmdt) : int64) + -> (syscall(Sysshmdt, a(shmaddr)) : int64) } const shmctl = {shmid, cmd, buf - -> (syscall(Sysshmctl, a(cmd), a(buf)) : int64) + -> (syscall(Sysshmctl, a(shmid), a(cmd), a(buf)) : int64) } const mq_open = {name, oflag, mode, attr - -> (syscall(Sysmq_open, a(oflag), a(mode), a(attr)) : int64) + -> (syscall(Sysmq_open, a(name), a(oflag), a(mode), a(attr)) : int64) } const mq_unlink = {name - -> (syscall(Sysmq_unlink) : int64) + -> (syscall(Sysmq_unlink, a(name)) : int64) } const mq_timedsend = {mqdes, msg_ptr, msg_len, msg_prio, abs_timeout - -> (syscall(Sysmq_timedsend, a(msg_ptr), a(msg_len), a(msg_prio), a(abs_timeout)) : int64) + -> (syscall(Sysmq_timedsend, a(mqdes), a(msg_ptr), a(msg_len), a(msg_prio), a(abs_timeout)) : int64) } const mq_timedreceive = {mqdes, msg_ptr, msg_len, msg_prio, abs_timeout - -> (syscall(Sysmq_timedreceive, a(msg_ptr), a(msg_len), a(msg_prio), a(abs_timeout)) : int64) + -> (syscall(Sysmq_timedreceive, a(mqdes), a(msg_ptr), a(msg_len), a(msg_prio), a(abs_timeout)) : int64) } const mq_notify = {mqdes, notification - -> (syscall(Sysmq_notify, a(notification)) : int64) + -> (syscall(Sysmq_notify, a(mqdes), a(notification)) : int64) } const mq_getsetattr = {mqdes, mqstat, omqstat - -> (syscall(Sysmq_getsetattr, a(mqstat), a(omqstat)) : int64) + -> (syscall(Sysmq_getsetattr, a(mqdes), a(mqstat), a(omqstat)) : int64) } const prctl = {option, arg2, arg3, arg4, arg5 - -> (syscall(Sysprctl, a(arg2), a(arg3), a(arg4), a(arg5)) : int64) + -> (syscall(Sysprctl, a(option), a(arg2), a(arg3), a(arg4), a(arg5)) : int64) } const swapon = {specialfile, swap_flags - -> (syscall(Sysswapon, a(swap_flags)) : int64) + -> (syscall(Sysswapon, a(specialfile), a(swap_flags)) : int64) } const swapoff = {specialfile - -> (syscall(Sysswapoff) : int64) + -> (syscall(Sysswapoff, a(specialfile)) : int64) } const _sysctl = {args - -> (syscall(Sys_sysctl) : int64) + -> (syscall(Sys_sysctl, a(args)) : int64) } const sysinfo = {info - -> (syscall(Syssysinfo) : int64) + -> (syscall(Syssysinfo, a(info)) : int64) } const sysfs = {option, arg1, arg2 - -> (syscall(Syssysfs, a(arg1), a(arg2)) : int64) + -> (syscall(Syssysfs, a(option), a(arg1), a(arg2)) : int64) } const syslog = {kind, buf, len - -> (syscall(Syssyslog, a(buf), a(len)) : int64) + -> (syscall(Syssyslog, a(kind), a(buf), a(len)) : int64) } const ptrace = {request, pid, addr, data - -> (syscall(Sysptrace, a(pid), a(addr), a(data)) : int64) + -> (syscall(Sysptrace, a(request), a(pid), a(addr), a(data)) : int64) } const add_key = {_type, _description, _payload, plen, destringid - -> (syscall(Sysadd_key, a(_description), a(_payload), a(plen), a(destringid)) : int64) + -> (syscall(Sysadd_key, a(_type), a(_description), a(_payload), a(plen), a(destringid)) : int64) } const request_key = {_type, _description, _callout_info, destringid - -> (syscall(Sysrequest_key, a(_description), a(_callout_info), a(destringid)) : int64) + -> (syscall(Sysrequest_key, a(_type), a(_description), a(_callout_info), a(destringid)) : int64) } const keyctl = {cmd, arg2, arg3, arg4, arg5 - -> (syscall(Syskeyctl, a(arg2), a(arg3), a(arg4), a(arg5)) : int64) + -> (syscall(Syskeyctl, a(cmd), a(arg2), a(arg3), a(arg4), a(arg5)) : int64) } const ioprio_set = {which, who, ioprio - -> (syscall(Sysioprio_set, a(who), a(ioprio)) : int64) + -> (syscall(Sysioprio_set, a(which), a(who), a(ioprio)) : int64) } const ioprio_get = {which, who - -> (syscall(Sysioprio_get, a(who)) : int64) + -> (syscall(Sysioprio_get, a(which), a(who)) : int64) } const set_mempolicy = {mode, nmask, maxnode - -> (syscall(Sysset_mempolicy, a(nmask), a(maxnode)) : int64) + -> (syscall(Sysset_mempolicy, a(mode), a(nmask), a(maxnode)) : int64) } const migrate_pages = {pid, maxnode, from, to - -> (syscall(Sysmigrate_pages, a(maxnode), a(from), a(to)) : int64) + -> (syscall(Sysmigrate_pages, a(pid), a(maxnode), a(from), a(to)) : int64) } const move_pages = {pid, nr_pages, pages, nodes, status, flags - -> (syscall(Sysmove_pages, a(nr_pages), a(pages), a(nodes), a(status), a(flags)) : int64) + -> (syscall(Sysmove_pages, a(pid), a(nr_pages), a(pages), a(nodes), a(status), a(flags)) : int64) } const mbind = {start, len, mode, nmask, maxnode, flags - -> (syscall(Sysmbind, a(len), a(mode), a(nmask), a(maxnode), a(flags)) : int64) + -> (syscall(Sysmbind, a(start), a(len), a(mode), a(nmask), a(maxnode), a(flags)) : int64) } const get_mempolicy = {policy, nmask, maxnode, addr, flags - -> (syscall(Sysget_mempolicy, a(nmask), a(maxnode), a(addr), a(flags)) : int64) + -> (syscall(Sysget_mempolicy, a(policy), a(nmask), a(maxnode), a(addr), a(flags)) : int64) } const inotify_init = { -> (syscall(Sysinotify_init) : int64) } const inotify_init1 = {flags - -> (syscall(Sysinotify_init1) : int64) + -> (syscall(Sysinotify_init1, a(flags)) : int64) } const inotify_add_watch = {fd, path, mask - -> (syscall(Sysinotify_add_watch, a(path), a(mask)) : int64) + -> (syscall(Sysinotify_add_watch, a(fd), a(path), a(mask)) : int64) } const inotify_rm_watch = {fd, wd - -> (syscall(Sysinotify_rm_watch, a(wd)) : int64) + -> (syscall(Sysinotify_rm_watch, a(fd), a(wd)) : int64) } const mknodat = {dfd, filename, mode, dev - -> (syscall(Sysmknodat, a(filename), a(mode), a(dev)) : int64) + -> (syscall(Sysmknodat, a(dfd), a(filename), a(mode), a(dev)) : int64) } const mkdirat = {dfd, pathname, mode - -> (syscall(Sysmkdirat, a(pathname), a(mode)) : int64) + -> (syscall(Sysmkdirat, a(dfd), a(pathname), a(mode)) : int64) } const unlinkat = {dfd, pathname, flag - -> (syscall(Sysunlinkat, a(pathname), a(flag)) : int64) + -> (syscall(Sysunlinkat, a(dfd), a(pathname), a(flag)) : int64) } const symlinkat = {oldname, newdfd, newname - -> (syscall(Syssymlinkat, a(newdfd), a(newname)) : int64) + -> (syscall(Syssymlinkat, a(oldname), a(newdfd), a(newname)) : int64) } const linkat = {olddfd, oldname, newdfd, newname, flags - -> (syscall(Syslinkat, a(oldname), a(newdfd), a(newname), a(flags)) : int64) + -> (syscall(Syslinkat, a(olddfd), a(oldname), a(newdfd), a(newname), a(flags)) : int64) } const renameat = {olddfd, oldname, newdfd, newname - -> (syscall(Sysrenameat, a(oldname), a(newdfd), a(newname)) : int64) + -> (syscall(Sysrenameat, a(olddfd), a(oldname), a(newdfd), a(newname)) : int64) } const renameat2 = {olddfd, oldname, newdfd, newname, flags - -> (syscall(Sysrenameat2, a(oldname), a(newdfd), a(newname), a(flags)) : int64) + -> (syscall(Sysrenameat2, a(olddfd), a(oldname), a(newdfd), a(newname), a(flags)) : int64) } const futimesat = {dfd, filename, utimes - -> (syscall(Sysfutimesat, a(filename), a(utimes)) : int64) + -> (syscall(Sysfutimesat, a(dfd), a(filename), a(utimes)) : int64) } const faccessat = {dfd, filename, mode - -> (syscall(Sysfaccessat, a(filename), a(mode)) : int64) + -> (syscall(Sysfaccessat, a(dfd), a(filename), a(mode)) : int64) } const fchmodat = {dfd, filename, mode - -> (syscall(Sysfchmodat, a(filename), a(mode)) : int64) + -> (syscall(Sysfchmodat, a(dfd), a(filename), a(mode)) : int64) } const fchownat = {dfd, filename, user, group, flag - -> (syscall(Sysfchownat, a(filename), a(user), a(group), a(flag)) : int64) + -> (syscall(Sysfchownat, a(dfd), a(filename), a(user), a(group), a(flag)) : int64) } const openat = {dfd, filename, flags, mode - -> (syscall(Sysopenat, a(filename), a(flags), a(mode)) : int64) + -> (syscall(Sysopenat, a(dfd), a(filename), a(flags), a(mode)) : int64) } const newfstatat = {dfd, filename, statbuf, flag - -> (syscall(Sysnewfstatat, a(filename), a(statbuf), a(flag)) : int64) + -> (syscall(Sysnewfstatat, a(dfd), a(filename), a(statbuf), a(flag)) : int64) } const readlinkat = {dfd, path, buf, bufsiz - -> (syscall(Sysreadlinkat, a(path), a(buf), a(bufsiz)) : int64) + -> (syscall(Sysreadlinkat, a(dfd), a(path), a(buf), a(bufsiz)) : int64) } const utimensat = {dfd, filename, utimes, flags - -> (syscall(Sysutimensat, a(filename), a(utimes), a(flags)) : int64) + -> (syscall(Sysutimensat, a(dfd), a(filename), a(utimes), a(flags)) : int64) } const unshare = {unshare_flags - -> (syscall(Sysunshare) : int64) + -> (syscall(Sysunshare, a(unshare_flags)) : int64) } const splice = {fd_in, off_in, fd_out, off_out, len, flags - -> (syscall(Syssplice, a(off_in), a(fd_out), a(off_out), a(len), a(flags)) : int64) + -> (syscall(Syssplice, a(fd_in), a(off_in), a(fd_out), a(off_out), a(len), a(flags)) : int64) } const vmsplice = {fd, iov, nr_segs, flags - -> (syscall(Sysvmsplice, a(iov), a(nr_segs), a(flags)) : int64) + -> (syscall(Sysvmsplice, a(fd), a(iov), a(nr_segs), a(flags)) : int64) } const tee = {fdin, fdout, len, flags - -> (syscall(Systee, a(fdout), a(len), a(flags)) : int64) + -> (syscall(Systee, a(fdin), a(fdout), a(len), a(flags)) : int64) } const sync_file_range = {fd, offset, nbytes, flags - -> (syscall(Syssync_file_range, a(offset), a(nbytes), a(flags)) : int64) + -> (syscall(Syssync_file_range, a(fd), a(offset), a(nbytes), a(flags)) : int64) } const get_robust_list = {pid, head_ptr, len_ptr - -> (syscall(Sysget_robust_list, a(head_ptr), a(len_ptr)) : int64) + -> (syscall(Sysget_robust_list, a(pid), a(head_ptr), a(len_ptr)) : int64) } const set_robust_list = {head, len - -> (syscall(Sysset_robust_list, a(len)) : int64) + -> (syscall(Sysset_robust_list, a(head), a(len)) : int64) } const getcpu = {cpu, node, cache - -> (syscall(Sysgetcpu, a(node), a(cache)) : int64) + -> (syscall(Sysgetcpu, a(cpu), a(node), a(cache)) : int64) } const signalfd = {ufd, user_mask, sizemask - -> (syscall(Syssignalfd, a(user_mask), a(sizemask)) : int64) + -> (syscall(Syssignalfd, a(ufd), a(user_mask), a(sizemask)) : int64) } const signalfd4 = {ufd, user_mask, sizemask, flags - -> (syscall(Syssignalfd4, a(user_mask), a(sizemask), a(flags)) : int64) + -> (syscall(Syssignalfd4, a(ufd), a(user_mask), a(sizemask), a(flags)) : int64) } const timerfd_create = {clockid, flags - -> (syscall(Systimerfd_create, a(flags)) : int64) + -> (syscall(Systimerfd_create, a(clockid), a(flags)) : int64) } const timerfd_settime = {ufd, flags, utmr, otmr - -> (syscall(Systimerfd_settime, a(flags), a(utmr), a(otmr)) : int64) + -> (syscall(Systimerfd_settime, a(ufd), a(flags), a(utmr), a(otmr)) : int64) } const timerfd_gettime = {ufd, otmr - -> (syscall(Systimerfd_gettime, a(otmr)) : int64) + -> (syscall(Systimerfd_gettime, a(ufd), a(otmr)) : int64) } const eventfd = {count - -> (syscall(Syseventfd) : int64) + -> (syscall(Syseventfd, a(count)) : int64) } const eventfd2 = {count, flags - -> (syscall(Syseventfd2, a(flags)) : int64) + -> (syscall(Syseventfd2, a(count), a(flags)) : int64) } const memfd_create = {uname_ptr, flags - -> (syscall(Sysmemfd_create, a(flags)) : int64) + -> (syscall(Sysmemfd_create, a(uname_ptr), a(flags)) : int64) } const userfaultfd = {flags - -> (syscall(Sysuserfaultfd) : int64) + -> (syscall(Sysuserfaultfd, a(flags)) : int64) } const pselect6 = {_a0, _a1, _a2, _a3, _a4, _a5 - -> (syscall(Syspselect6, a(_a1), a(_a2), a(_a3), a(_a4), a(_a5)) : int64) + -> (syscall(Syspselect6, a(_a0), a(_a1), a(_a2), a(_a3), a(_a4), a(_a5)) : int64) } const ppoll = {_a0, int, _a2, _a3, _a4 - -> (syscall(Sysppoll, a(int), a(_a2), a(_a3), a(_a4)) : int64) + -> (syscall(Sysppoll, a(_a0), a(int), a(_a2), a(_a3), a(_a4)) : int64) } const fanotify_init = {flags, event_f_flags - -> (syscall(Sysfanotify_init, a(event_f_flags)) : int64) + -> (syscall(Sysfanotify_init, a(flags), a(event_f_flags)) : int64) } const fanotify_mark = {fanotify_fd, flags, mask, fd, pathname - -> (syscall(Sysfanotify_mark, a(flags), a(mask), a(fd), a(pathname)) : int64) + -> (syscall(Sysfanotify_mark, a(fanotify_fd), a(flags), a(mask), a(fd), a(pathname)) : int64) } const syncfs = {fd - -> (syscall(Syssyncfs) : int64) + -> (syscall(Syssyncfs, a(fd)) : int64) } const vfork = { -> (syscall(Sysvfork) : int64) } const perf_event_open = {attr_uptr, pid, cpu, group_fd, flags - -> (syscall(Sysperf_event_open, a(pid), a(cpu), a(group_fd), a(flags)) : int64) + -> (syscall(Sysperf_event_open, a(attr_uptr), a(pid), a(cpu), a(group_fd), a(flags)) : int64) } const name_to_handle_at = {dfd, name, handle, mnt_id, flag - -> (syscall(Sysname_to_handle_at, a(name), a(handle), a(mnt_id), a(flag)) : int64) + -> (syscall(Sysname_to_handle_at, a(dfd), a(name), a(handle), a(mnt_id), a(flag)) : int64) } const open_by_handle_at = {mountdirfd, handle, flags - -> (syscall(Sysopen_by_handle_at, a(handle), a(flags)) : int64) + -> (syscall(Sysopen_by_handle_at, a(mountdirfd), a(handle), a(flags)) : int64) } const setns = {fd, nstype - -> (syscall(Syssetns, a(nstype)) : int64) + -> (syscall(Syssetns, a(fd), a(nstype)) : int64) } const process_vm_readv = {pid, lvec, liovcnt, rvec, riovcnt, flags - -> (syscall(Sysprocess_vm_readv, a(lvec), a(liovcnt), a(rvec), a(riovcnt), a(flags)) : int64) + -> (syscall(Sysprocess_vm_readv, a(pid), a(lvec), a(liovcnt), a(rvec), a(riovcnt), a(flags)) : int64) } const process_vm_writev = {pid, lvec, liovcnt, rvec, riovcnt, flags - -> (syscall(Sysprocess_vm_writev, a(lvec), a(liovcnt), a(rvec), a(riovcnt), a(flags)) : int64) + -> (syscall(Sysprocess_vm_writev, a(pid), a(lvec), a(liovcnt), a(rvec), a(riovcnt), a(flags)) : int64) } const kcmp = {pid1, pid2, kind, idx1, idx2 - -> (syscall(Syskcmp, a(pid2), a(kind), a(idx1), a(idx2)) : int64) + -> (syscall(Syskcmp, a(pid1), a(pid2), a(kind), a(idx1), a(idx2)) : int64) } const finit_module = {fd, uargs, flags - -> (syscall(Sysfinit_module, a(uargs), a(flags)) : int64) + -> (syscall(Sysfinit_module, a(fd), a(uargs), a(flags)) : int64) } const seccomp = {op, flags, uargs - -> (syscall(Sysseccomp, a(flags), a(uargs)) : int64) + -> (syscall(Sysseccomp, a(op), a(flags), a(uargs)) : int64) } const getrandom = {buf, count, flags - -> (syscall(Sysgetrandom, a(count), a(flags)) : int64) + -> (syscall(Sysgetrandom, a(buf), a(count), a(flags)) : int64) } const bpf = {cmd, attr, size - -> (syscall(Sysbpf, a(attr), a(size)) : int64) + -> (syscall(Sysbpf, a(cmd), a(attr), a(size)) : int64) } const execveat = {dfd, filename, argv, envp, flags - -> (syscall(Sysexecveat, a(filename), a(argv), a(envp), a(flags)) : int64) + -> (syscall(Sysexecveat, a(dfd), a(filename), a(argv), a(envp), a(flags)) : int64) } const membarrier = {cmd, flags - -> (syscall(Sysmembarrier, a(flags)) : int64) + -> (syscall(Sysmembarrier, a(cmd), a(flags)) : int64) } const copy_file_range = {fd_in, off_in, fd_out, off_out, len, flags - -> (syscall(Syscopy_file_range, a(off_in), a(fd_out), a(off_out), a(len), a(flags)) : int64) + -> (syscall(Syscopy_file_range, a(fd_in), a(off_in), a(fd_out), a(off_out), a(len), a(flags)) : int64) } const mlock2 = {start, len, flags - -> (syscall(Sysmlock2, a(len), a(flags)) : int64) + -> (syscall(Sysmlock2, a(start), a(len), a(flags)) : int64) } const pkey_mprotect = {start, len, prot, pkey - -> (syscall(Syspkey_mprotect, a(len), a(prot), a(pkey)) : int64) + -> (syscall(Syspkey_mprotect, a(start), a(len), a(prot), a(pkey)) : int64) } const pkey_alloc = {flags, init_val - -> (syscall(Syspkey_alloc, a(init_val)) : int64) + -> (syscall(Syspkey_alloc, a(flags), a(init_val)) : int64) } const pkey_free = {pkey - -> (syscall(Syspkey_free) : int64) + -> (syscall(Syspkey_free, a(pkey)) : int64) } diff --git a/lib/sys/sys+netbsd-x64.myr b/lib/sys/sys+netbsd-x64.myr index c13d88a..02f9a76 100644 --- a/lib/sys/sys+netbsd-x64.myr +++ b/lib/sys/sys+netbsd-x64.myr @@ -1003,7 +1003,8 @@ const chdir = {dir; -> syscall(Syschdir, cstring(dir))} const __getcwd = {buf; -> syscall(Sys__getcwd, a(buf), a(buf.len))} /* file stuff */ -const pipe = {fds; -> syscall(Syspipe, fds)} +extern const __netbsd_pipe : (fds : fd[2]# -> int64) +const pipe = {fds; -> __netbsd_pipe(fds)} const dup = {fd; -> (syscall(Sysdup, a(fd)) : fd)} const dup2 = {src, dst; -> (syscall(Sysdup2, a(src), a(dst)) : fd)} const fcntl = {fd, cmd, args; -> syscall(Sysfcntl, a(fd), a(cmd), a(args))} diff --git a/lib/sys/sys+openbsd:6.1-x64.myr b/lib/sys/sys+openbsd:6.1-x64.myr index a2a609d..64cc453 100644 --- a/lib/sys/sys+openbsd:6.1-x64.myr +++ b/lib/sys/sys+openbsd:6.1-x64.myr @@ -1263,43 +1263,43 @@ pkg sys = /* } end manual overrides */ const getentropy = {buf, nbyte - -> (syscall(Sysgetentropy, a(nbyte)) : int) + -> (syscall(Sysgetentropy, a(buf), a(nbyte)) : int) } const __tfork = {param, psize - -> (syscall(Sys__tfork, a(psize)) : int) + -> (syscall(Sys__tfork, a(param), a(psize)) : int) } const link = {path, link - -> (syscall(Syslink, a(link)) : int) + -> (syscall(Syslink, a(path), a(link)) : int) } const fchdir = {fd - -> (syscall(Sysfchdir) : int) + -> (syscall(Sysfchdir, a(fd)) : int) } const mknod = {path, mode, dev - -> (syscall(Sysmknod, a(mode), a(dev)) : int) + -> (syscall(Sysmknod, a(path), a(mode), a(dev)) : int) } const chmod = {path, mode - -> (syscall(Syschmod, a(mode)) : int) + -> (syscall(Syschmod, a(path), a(mode)) : int) } const chown = {path, uid, gid - -> (syscall(Syschown, a(uid), a(gid)) : int) + -> (syscall(Syschown, a(path), a(uid), a(gid)) : int) } const obreak = {nsize - -> (syscall(Sysobreak) : int) + -> (syscall(Sysobreak, a(nsize)) : int) } const getdtablecount = { -> (syscall(Sysgetdtablecount) : int) } const getrusage = {who, rusage - -> (syscall(Sysgetrusage, a(rusage)) : int) + -> (syscall(Sysgetrusage, a(who), a(rusage)) : int) } const mount = {kind, path, flags, data - -> (syscall(Sysmount, a(path), a(flags), a(data)) : int) + -> (syscall(Sysmount, a(kind), a(path), a(flags), a(data)) : int) } const unmount = {path, flags - -> (syscall(Sysunmount, a(flags)) : int) + -> (syscall(Sysunmount, a(path), a(flags)) : int) } const setuid = {uid - -> (syscall(Syssetuid) : int) + -> (syscall(Syssetuid, a(uid)) : int) } const getuid = { -> (syscall(Sysgetuid) : uid) @@ -1308,31 +1308,31 @@ const geteuid = { -> (syscall(Sysgeteuid) : uid) } const ptrace = {req, pid, addr, data - -> (syscall(Sysptrace, a(pid), a(addr), a(data)) : int) + -> (syscall(Sysptrace, a(req), a(pid), a(addr), a(data)) : int) } const recvmsg = {s, msg, flags - -> (syscall(Sysrecvmsg, a(msg), a(flags)) : size) + -> (syscall(Sysrecvmsg, a(s), a(msg), a(flags)) : size) } const sendmsg = {s, msg, flags - -> (syscall(Syssendmsg, a(msg), a(flags)) : size) + -> (syscall(Syssendmsg, a(s), a(msg), a(flags)) : size) } const recvfrom = {s, buf, len, flags, from, fromlenaddr - -> (syscall(Sysrecvfrom, a(buf), a(len), a(flags), a(from), a(fromlenaddr)) : size) + -> (syscall(Sysrecvfrom, a(s), a(buf), a(len), a(flags), a(from), a(fromlenaddr)) : size) } const getpeername = {fdes, asa, alen - -> (syscall(Sysgetpeername, a(asa), a(alen)) : int) + -> (syscall(Sysgetpeername, a(fdes), a(asa), a(alen)) : int) } const getsockname = {fdes, asa, alen - -> (syscall(Sysgetsockname, a(asa), a(alen)) : int) + -> (syscall(Sysgetsockname, a(fdes), a(asa), a(alen)) : int) } const access = {path, amode - -> (syscall(Sysaccess, a(amode)) : int) + -> (syscall(Sysaccess, a(path), a(amode)) : int) } const chflags = {path, flags - -> (syscall(Syschflags, a(flags)) : int) + -> (syscall(Syschflags, a(path), a(flags)) : int) } const fchflags = {fd, flags - -> (syscall(Sysfchflags, a(flags)) : int) + -> (syscall(Sysfchflags, a(fd), a(flags)) : int) } const sync = { -> (syscall(Syssync) : void) @@ -1341,349 +1341,349 @@ const getppid = { -> (syscall(Sysgetppid) : pid) } const fstatat = {fd, path, buf, flag - -> (syscall(Sysfstatat, a(path), a(buf), a(flag)) : int) + -> (syscall(Sysfstatat, a(fd), a(path), a(buf), a(flag)) : int) } const getegid = { -> (syscall(Sysgetegid) : gid) } const profil = {samples, size, offset, scale - -> (syscall(Sysprofil, a(size), a(offset), a(scale)) : int) + -> (syscall(Sysprofil, a(samples), a(size), a(offset), a(scale)) : int) } const ktrace = {fname, ops, facs, pid - -> (syscall(Sysktrace, a(ops), a(facs), a(pid)) : int) + -> (syscall(Sysktrace, a(fname), a(ops), a(facs), a(pid)) : int) } const getgid = { -> (syscall(Sysgetgid) : gid) } const getlogin59 = {namebuf, namelen - -> (syscall(Sysgetlogin59, a(namelen)) : int) + -> (syscall(Sysgetlogin59, a(namebuf), a(namelen)) : int) } const setlogin = {namebuf - -> (syscall(Syssetlogin) : int) + -> (syscall(Syssetlogin, a(namebuf)) : int) } const acct = {path - -> (syscall(Sysacct) : int) + -> (syscall(Sysacct, a(path)) : int) } const sigpending = { -> (syscall(Syssigpending) : int) } const reboot = {opt - -> (syscall(Sysreboot) : int) + -> (syscall(Sysreboot, a(opt)) : int) } const revoke = {path - -> (syscall(Sysrevoke) : int) + -> (syscall(Sysrevoke, a(path)) : int) } const symlink = {path, link - -> (syscall(Syssymlink, a(link)) : int) + -> (syscall(Syssymlink, a(path), a(link)) : int) } const readlink = {path, buf, count - -> (syscall(Sysreadlink, a(buf), a(count)) : size) + -> (syscall(Sysreadlink, a(path), a(buf), a(count)) : size) } const umask = {newmask - -> (syscall(Sysumask) : filemode) + -> (syscall(Sysumask, a(newmask)) : filemode) } const chroot = {path - -> (syscall(Syschroot) : int) + -> (syscall(Syschroot, a(path)) : int) } const getfsstat = {buf, bufsize, flags - -> (syscall(Sysgetfsstat, a(bufsize), a(flags)) : int) + -> (syscall(Sysgetfsstat, a(buf), a(bufsize), a(flags)) : int) } const statfs = {path, buf - -> (syscall(Sysstatfs, a(buf)) : int) + -> (syscall(Sysstatfs, a(path), a(buf)) : int) } const fstatfs = {fd, buf - -> (syscall(Sysfstatfs, a(buf)) : int) + -> (syscall(Sysfstatfs, a(fd), a(buf)) : int) } const fhstatfs = {fhp, buf - -> (syscall(Sysfhstatfs, a(buf)) : int) + -> (syscall(Sysfhstatfs, a(fhp), a(buf)) : int) } const vfork = { -> (syscall(Sysvfork) : int) } const gettimeofday = {tp, tzp - -> (syscall(Sysgettimeofday, a(tzp)) : int) + -> (syscall(Sysgettimeofday, a(tp), a(tzp)) : int) } const settimeofday = {tv, tzp - -> (syscall(Syssettimeofday, a(tzp)) : int) + -> (syscall(Syssettimeofday, a(tv), a(tzp)) : int) } const setitimer = {which, itv, oitv - -> (syscall(Syssetitimer, a(itv), a(oitv)) : int) + -> (syscall(Syssetitimer, a(which), a(itv), a(oitv)) : int) } const getitimer = {which, itv - -> (syscall(Sysgetitimer, a(itv)) : int) + -> (syscall(Sysgetitimer, a(which), a(itv)) : int) } const select = {nd, _in, ou, ex, tv - -> (syscall(Sysselect, a(_in), a(ou), a(ex), a(tv)) : int) + -> (syscall(Sysselect, a(nd), a(_in), a(ou), a(ex), a(tv)) : int) } const kevent = {fd, changelist, nchanges, eventlist, nevents, timeout - -> (syscall(Syskevent, a(changelist), a(nchanges), a(eventlist), a(nevents), a(timeout)) : int) + -> (syscall(Syskevent, a(fd), a(changelist), a(nchanges), a(eventlist), a(nevents), a(timeout)) : int) } const mprotect = {addr, len, prot - -> (syscall(Sysmprotect, a(len), a(prot)) : int) + -> (syscall(Sysmprotect, a(addr), a(len), a(prot)) : int) } const madvise = {addr, len, behav - -> (syscall(Sysmadvise, a(len), a(behav)) : int) + -> (syscall(Sysmadvise, a(addr), a(len), a(behav)) : int) } const utimes = {path, tptr - -> (syscall(Sysutimes, a(tptr)) : int) + -> (syscall(Sysutimes, a(path), a(tptr)) : int) } const futimes = {fd, tptr - -> (syscall(Sysfutimes, a(tptr)) : int) + -> (syscall(Sysfutimes, a(fd), a(tptr)) : int) } const mincore = {addr, len, vec - -> (syscall(Sysmincore, a(len), a(vec)) : int) + -> (syscall(Sysmincore, a(addr), a(len), a(vec)) : int) } const getgroups = {gidsetsize, gidset - -> (syscall(Sysgetgroups, a(gidset)) : int) + -> (syscall(Sysgetgroups, a(gidsetsize), a(gidset)) : int) } const setgroups = {gidsetsize, gidset - -> (syscall(Syssetgroups, a(gidset)) : int) + -> (syscall(Syssetgroups, a(gidsetsize), a(gidset)) : int) } const getpgrp = { -> (syscall(Sysgetpgrp) : int) } const setpgid = {pid, pgid - -> (syscall(Syssetpgid, a(pgid)) : int) + -> (syscall(Syssetpgid, a(pid), a(pgid)) : int) } const utimensat = {fd, path, times, flag - -> (syscall(Sysutimensat, a(path), a(times), a(flag)) : int) + -> (syscall(Sysutimensat, a(fd), a(path), a(times), a(flag)) : int) } const futimens = {fd, times - -> (syscall(Sysfutimens, a(times)) : int) + -> (syscall(Sysfutimens, a(fd), a(times)) : int) } const kbind = {param, psize, proc_cookie - -> (syscall(Syskbind, a(psize), a(proc_cookie)) : int) + -> (syscall(Syskbind, a(param), a(psize), a(proc_cookie)) : int) } const accept4 = {s, name, anamelen, flags - -> (syscall(Sysaccept4, a(name), a(anamelen), a(flags)) : int) + -> (syscall(Sysaccept4, a(s), a(name), a(anamelen), a(flags)) : int) } const __thrsleep = {ident, clock_id, tp, lock, abort - -> (syscall(Sys__thrsleep, a(clock_id), a(tp), a(lock), a(abort)) : int) + -> (syscall(Sys__thrsleep, a(ident), a(clock_id), a(tp), a(lock), a(abort)) : int) } const fsync = {fd - -> (syscall(Sysfsync) : int) + -> (syscall(Sysfsync, a(fd)) : int) } const setpriority = {which, who, prio - -> (syscall(Syssetpriority, a(who), a(prio)) : int) + -> (syscall(Syssetpriority, a(which), a(who), a(prio)) : int) } const getpriority = {which, who - -> (syscall(Sysgetpriority, a(who)) : int) + -> (syscall(Sysgetpriority, a(which), a(who)) : int) } const pipe2 = {fdp, flags - -> (syscall(Syspipe2, a(flags)) : int) + -> (syscall(Syspipe2, a(fdp), a(flags)) : int) } const dup3 = {from, to, flags - -> (syscall(Sysdup3, a(to), a(flags)) : int) + -> (syscall(Sysdup3, a(from), a(to), a(flags)) : int) } const sigreturn = {sigcntxp - -> (syscall(Syssigreturn) : int) + -> (syscall(Syssigreturn, a(sigcntxp)) : int) } const chflagsat = {fd, path, flags, atflags - -> (syscall(Syschflagsat, a(path), a(flags), a(atflags)) : int) + -> (syscall(Syschflagsat, a(fd), a(path), a(flags), a(atflags)) : int) } const pledge = {request, paths - -> (syscall(Syspledge, a(paths)) : int) + -> (syscall(Syspledge, a(request), a(paths)) : int) } const ppoll = {fds, nfds, ts, mask - -> (syscall(Sysppoll, a(nfds), a(ts), a(mask)) : int) + -> (syscall(Sysppoll, a(fds), a(nfds), a(ts), a(mask)) : int) } const pselect = {nd, _in, ou, ex, ts, mask - -> (syscall(Syspselect, a(_in), a(ou), a(ex), a(ts), a(mask)) : int) + -> (syscall(Syspselect, a(nd), a(_in), a(ou), a(ex), a(ts), a(mask)) : int) } const sigsuspend = {mask - -> (syscall(Syssigsuspend) : int) + -> (syscall(Syssigsuspend, a(mask)) : int) } const sendsyslog = {buf, nbyte, flags - -> (syscall(Syssendsyslog, a(nbyte), a(flags)) : int) + -> (syscall(Syssendsyslog, a(buf), a(nbyte), a(flags)) : int) } const thrkill = {tid, signum, tcb - -> (syscall(Systhrkill, a(signum), a(tcb)) : int) + -> (syscall(Systhrkill, a(tid), a(signum), a(tcb)) : int) } const fchown = {fd, uid, gid - -> (syscall(Sysfchown, a(uid), a(gid)) : int) + -> (syscall(Sysfchown, a(fd), a(uid), a(gid)) : int) } const fchmod = {fd, mode - -> (syscall(Sysfchmod, a(mode)) : int) + -> (syscall(Sysfchmod, a(fd), a(mode)) : int) } const setreuid = {ruid, euid - -> (syscall(Syssetreuid, a(euid)) : int) + -> (syscall(Syssetreuid, a(ruid), a(euid)) : int) } const setregid = {rgid, egid - -> (syscall(Syssetregid, a(egid)) : int) + -> (syscall(Syssetregid, a(rgid), a(egid)) : int) } const rename = {from, to - -> (syscall(Sysrename, a(to)) : int) + -> (syscall(Sysrename, a(from), a(to)) : int) } const flock = {fd, how - -> (syscall(Sysflock, a(how)) : int) + -> (syscall(Sysflock, a(fd), a(how)) : int) } const mkfifo = {path, mode - -> (syscall(Sysmkfifo, a(mode)) : int) + -> (syscall(Sysmkfifo, a(path), a(mode)) : int) } const sendto = {s, buf, len, flags, to, tolen - -> (syscall(Syssendto, a(buf), a(len), a(flags), a(to), a(tolen)) : size) + -> (syscall(Syssendto, a(s), a(buf), a(len), a(flags), a(to), a(tolen)) : size) } const shutdown = {s, how - -> (syscall(Sysshutdown, a(how)) : int) + -> (syscall(Sysshutdown, a(s), a(how)) : int) } const socketpair = {domain, kind, protocol, rsv - -> (syscall(Syssocketpair, a(kind), a(protocol), a(rsv)) : int) + -> (syscall(Syssocketpair, a(domain), a(kind), a(protocol), a(rsv)) : int) } const rmdir = {path - -> (syscall(Sysrmdir) : int) + -> (syscall(Sysrmdir, a(path)) : int) } const adjtime = {delta, olddelta - -> (syscall(Sysadjtime, a(olddelta)) : int) + -> (syscall(Sysadjtime, a(delta), a(olddelta)) : int) } const getlogin_r = {namebuf, namelen - -> (syscall(Sysgetlogin_r, a(namelen)) : int) + -> (syscall(Sysgetlogin_r, a(namebuf), a(namelen)) : int) } const setsid = { -> (syscall(Syssetsid) : int) } const quotactl = {path, cmd, uid, arg - -> (syscall(Sysquotactl, a(cmd), a(uid), a(arg)) : int) + -> (syscall(Sysquotactl, a(path), a(cmd), a(uid), a(arg)) : int) } const nfssvc = {flag, argp - -> (syscall(Sysnfssvc, a(argp)) : int) + -> (syscall(Sysnfssvc, a(flag), a(argp)) : int) } const getfh = {fname, fhp - -> (syscall(Sysgetfh, a(fhp)) : int) + -> (syscall(Sysgetfh, a(fname), a(fhp)) : int) } const sysarch = {op, parms - -> (syscall(Syssysarch, a(parms)) : int) + -> (syscall(Syssysarch, a(op), a(parms)) : int) } const setgid = {gid - -> (syscall(Syssetgid) : int) + -> (syscall(Syssetgid, a(gid)) : int) } const setegid = {egid - -> (syscall(Syssetegid) : int) + -> (syscall(Syssetegid, a(egid)) : int) } const seteuid = {euid - -> (syscall(Sysseteuid) : int) + -> (syscall(Sysseteuid, a(euid)) : int) } const pathconf = {path, name - -> (syscall(Syspathconf, a(name)) : int64) + -> (syscall(Syspathconf, a(path), a(name)) : int64) } const fpathconf = {fd, name - -> (syscall(Sysfpathconf, a(name)) : int64) + -> (syscall(Sysfpathconf, a(fd), a(name)) : int64) } const swapctl = {cmd, arg, misc - -> (syscall(Sysswapctl, a(arg), a(misc)) : int) + -> (syscall(Sysswapctl, a(cmd), a(arg), a(misc)) : int) } const getrlimit = {which, rlp - -> (syscall(Sysgetrlimit, a(rlp)) : int) + -> (syscall(Sysgetrlimit, a(which), a(rlp)) : int) } const setrlimit = {which, rlp - -> (syscall(Syssetrlimit, a(rlp)) : int) + -> (syscall(Syssetrlimit, a(which), a(rlp)) : int) } const truncate = {path, pad, length - -> (syscall(Systruncate, a(pad), a(length)) : int) + -> (syscall(Systruncate, a(path), a(pad), a(length)) : int) } const ftruncate = {fd, pad, length - -> (syscall(Sysftruncate, a(pad), a(length)) : int) + -> (syscall(Sysftruncate, a(fd), a(pad), a(length)) : int) } const mlock = {addr, len - -> (syscall(Sysmlock, a(len)) : int) + -> (syscall(Sysmlock, a(addr), a(len)) : int) } const munlock = {addr, len - -> (syscall(Sysmunlock, a(len)) : int) + -> (syscall(Sysmunlock, a(addr), a(len)) : int) } const getpgid = {pid - -> (syscall(Sysgetpgid) : pid) + -> (syscall(Sysgetpgid, a(pid)) : pid) } const utrace = {label, addr, len - -> (syscall(Sysutrace, a(addr), a(len)) : int) + -> (syscall(Sysutrace, a(label), a(addr), a(len)) : int) } const semget = {key, nsems, semflg - -> (syscall(Syssemget, a(nsems), a(semflg)) : int) + -> (syscall(Syssemget, a(key), a(nsems), a(semflg)) : int) } const msgget = {key, msgflg - -> (syscall(Sysmsgget, a(msgflg)) : int) + -> (syscall(Sysmsgget, a(key), a(msgflg)) : int) } const msgsnd = {msqid, msgp, msgsz, msgflg - -> (syscall(Sysmsgsnd, a(msgp), a(msgsz), a(msgflg)) : int) + -> (syscall(Sysmsgsnd, a(msqid), a(msgp), a(msgsz), a(msgflg)) : int) } const msgrcv = {msqid, msgp, msgsz, msgtyp, msgflg - -> (syscall(Sysmsgrcv, a(msgp), a(msgsz), a(msgtyp), a(msgflg)) : int) + -> (syscall(Sysmsgrcv, a(msqid), a(msgp), a(msgsz), a(msgtyp), a(msgflg)) : int) } const shmat = {shmid, shmaddr, shmflg - -> (syscall(Sysshmat, a(shmaddr), a(shmflg)) : void) + -> (syscall(Sysshmat, a(shmid), a(shmaddr), a(shmflg)) : void) } const shmdt = {shmaddr - -> (syscall(Sysshmdt) : int) + -> (syscall(Sysshmdt, a(shmaddr)) : int) } const minherit = {addr, len, inherit - -> (syscall(Sysminherit, a(len), a(inherit)) : int) + -> (syscall(Sysminherit, a(addr), a(len), a(inherit)) : int) } const issetugid = { -> (syscall(Sysissetugid) : int) } const lchown = {path, uid, gid - -> (syscall(Syslchown, a(uid), a(gid)) : int) + -> (syscall(Syslchown, a(path), a(uid), a(gid)) : int) } const getsid = {pid - -> (syscall(Sysgetsid) : pid) + -> (syscall(Sysgetsid, a(pid)) : pid) } const msync = {addr, len, flags - -> (syscall(Sysmsync, a(len), a(flags)) : int) + -> (syscall(Sysmsync, a(addr), a(len), a(flags)) : int) } const fhopen = {fhp, flags - -> (syscall(Sysfhopen, a(flags)) : int) + -> (syscall(Sysfhopen, a(fhp), a(flags)) : int) } const preadv = {fd, iovp, iovcnt, pad, offset - -> (syscall(Syspreadv, a(iovp), a(iovcnt), a(pad), a(offset)) : size) + -> (syscall(Syspreadv, a(fd), a(iovp), a(iovcnt), a(pad), a(offset)) : size) } const pwritev = {fd, iovp, iovcnt, pad, offset - -> (syscall(Syspwritev, a(iovp), a(iovcnt), a(pad), a(offset)) : size) + -> (syscall(Syspwritev, a(fd), a(iovp), a(iovcnt), a(pad), a(offset)) : size) } const kqueue = { -> (syscall(Syskqueue) : int) } const mlockall = {flags - -> (syscall(Sysmlockall) : int) + -> (syscall(Sysmlockall, a(flags)) : int) } const munlockall = { -> (syscall(Sysmunlockall) : int) } const getresuid = {ruid, euid, suid - -> (syscall(Sysgetresuid, a(euid), a(suid)) : int) + -> (syscall(Sysgetresuid, a(ruid), a(euid), a(suid)) : int) } const setresuid = {ruid, euid, suid - -> (syscall(Syssetresuid, a(euid), a(suid)) : int) + -> (syscall(Syssetresuid, a(ruid), a(euid), a(suid)) : int) } const getresgid = {rgid, egid, sgid - -> (syscall(Sysgetresgid, a(egid), a(sgid)) : int) + -> (syscall(Sysgetresgid, a(rgid), a(egid), a(sgid)) : int) } const setresgid = {rgid, egid, sgid - -> (syscall(Syssetresgid, a(egid), a(sgid)) : int) + -> (syscall(Syssetresgid, a(rgid), a(egid), a(sgid)) : int) } const mquery = {addr, len, prot, flags, fd, pad, pos - -> (syscall(Sysmquery, a(len), a(prot), a(flags), a(fd), a(pad), a(pos)) : void) + -> (syscall(Sysmquery, a(addr), a(len), a(prot), a(flags), a(fd), a(pad), a(pos)) : void) } const closefrom = {fd - -> (syscall(Sysclosefrom) : int) + -> (syscall(Sysclosefrom, a(fd)) : int) } const sigaltstack = {nss, oss - -> (syscall(Syssigaltstack, a(oss)) : int) + -> (syscall(Syssigaltstack, a(nss), a(oss)) : int) } const shmget = {key, size, shmflg - -> (syscall(Sysshmget, a(size), a(shmflg)) : int) + -> (syscall(Sysshmget, a(key), a(size), a(shmflg)) : int) } const semop = {semid, sops, nsops - -> (syscall(Syssemop, a(sops), a(nsops)) : int) + -> (syscall(Syssemop, a(semid), a(sops), a(nsops)) : int) } const fhstat = {fhp, sb - -> (syscall(Sysfhstat, a(sb)) : int) + -> (syscall(Sysfhstat, a(fhp), a(sb)) : int) } const __semctl = {semid, semnum, cmd, arg - -> (syscall(Sys__semctl, a(semnum), a(cmd), a(arg)) : int) + -> (syscall(Sys__semctl, a(semid), a(semnum), a(cmd), a(arg)) : int) } const shmctl = {shmid, cmd, buf - -> (syscall(Sysshmctl, a(cmd), a(buf)) : int) + -> (syscall(Sysshmctl, a(shmid), a(cmd), a(buf)) : int) } const msgctl = {msqid, cmd, buf - -> (syscall(Sysmsgctl, a(cmd), a(buf)) : int) + -> (syscall(Sysmsgctl, a(msqid), a(cmd), a(buf)) : int) } const sched_yield = { -> (syscall(Syssched_yield) : int) @@ -1692,61 +1692,61 @@ const getthrid = { -> (syscall(Sysgetthrid) : pid) } const __thrwakeup = {ident, n - -> (syscall(Sys__thrwakeup, a(n)) : int) + -> (syscall(Sys__thrwakeup, a(ident), a(n)) : int) } const __threxit = {notdead - -> (syscall(Sys__threxit) : void) + -> (syscall(Sys__threxit, a(notdead)) : void) } const __thrsigdivert = {sigmask, info, timeout - -> (syscall(Sys__thrsigdivert, a(info), a(timeout)) : int) + -> (syscall(Sys__thrsigdivert, a(sigmask), a(info), a(timeout)) : int) } const adjfreq = {freq, oldfreq - -> (syscall(Sysadjfreq, a(oldfreq)) : int) + -> (syscall(Sysadjfreq, a(freq), a(oldfreq)) : int) } const setrtable = {rtableid - -> (syscall(Syssetrtable) : int) + -> (syscall(Syssetrtable, a(rtableid)) : int) } const getrtable = { -> (syscall(Sysgetrtable) : int) } const faccessat = {fd, path, amode, flag - -> (syscall(Sysfaccessat, a(path), a(amode), a(flag)) : int) + -> (syscall(Sysfaccessat, a(fd), a(path), a(amode), a(flag)) : int) } const fchmodat = {fd, path, mode, flag - -> (syscall(Sysfchmodat, a(path), a(mode), a(flag)) : int) + -> (syscall(Sysfchmodat, a(fd), a(path), a(mode), a(flag)) : int) } const fchownat = {fd, path, uid, gid, flag - -> (syscall(Sysfchownat, a(path), a(uid), a(gid), a(flag)) : int) + -> (syscall(Sysfchownat, a(fd), a(path), a(uid), a(gid), a(flag)) : int) } const linkat = {fd1, path1, fd2, path2, flag - -> (syscall(Syslinkat, a(path1), a(fd2), a(path2), a(flag)) : int) + -> (syscall(Syslinkat, a(fd1), a(path1), a(fd2), a(path2), a(flag)) : int) } const mkdirat = {fd, path, mode - -> (syscall(Sysmkdirat, a(path), a(mode)) : int) + -> (syscall(Sysmkdirat, a(fd), a(path), a(mode)) : int) } const mkfifoat = {fd, path, mode - -> (syscall(Sysmkfifoat, a(path), a(mode)) : int) + -> (syscall(Sysmkfifoat, a(fd), a(path), a(mode)) : int) } const mknodat = {fd, path, mode, dev - -> (syscall(Sysmknodat, a(path), a(mode), a(dev)) : int) + -> (syscall(Sysmknodat, a(fd), a(path), a(mode), a(dev)) : int) } const openat = {fd, path, flags, mode - -> (syscall(Sysopenat, a(path), a(flags), a(mode)) : int) + -> (syscall(Sysopenat, a(fd), a(path), a(flags), a(mode)) : int) } const readlinkat = {fd, path, buf, count - -> (syscall(Sysreadlinkat, a(path), a(buf), a(count)) : size) + -> (syscall(Sysreadlinkat, a(fd), a(path), a(buf), a(count)) : size) } const renameat = {fromfd, from, tofd, to - -> (syscall(Sysrenameat, a(from), a(tofd), a(to)) : int) + -> (syscall(Sysrenameat, a(fromfd), a(from), a(tofd), a(to)) : int) } const symlinkat = {path, fd, link - -> (syscall(Syssymlinkat, a(fd), a(link)) : int) + -> (syscall(Syssymlinkat, a(path), a(fd), a(link)) : int) } const unlinkat = {fd, path, flag - -> (syscall(Sysunlinkat, a(path), a(flag)) : int) + -> (syscall(Sysunlinkat, a(fd), a(path), a(flag)) : int) } const __set_tcb = {tcb - -> (syscall(Sys__set_tcb) : void) + -> (syscall(Sys__set_tcb, a(tcb)) : void) } const __get_tcb = { -> (syscall(Sys__get_tcb) : void) diff --git a/lib/sys/sys+openbsd:6.2-x64.myr b/lib/sys/sys+openbsd:6.2-x64.myr new file mode 100644 index 0000000..4a1f0e5 --- /dev/null +++ b/lib/sys/sys+openbsd:6.2-x64.myr @@ -0,0 +1,1762 @@ +/* + generated-ish source + stitched for openbsd:6.2 arch:x64 + edit with caution. + */ +pkg sys = + type size = int64 /* spans entire address space */ + type usize = uint64 /* unsigned size */ + type off = int64 /* file offsets */ + type intptr = uint64/* can hold any pointer losslessly */ + type time = int64 /* milliseconds since epoch */ + type pid = int32 /* process id */ + type scno = int64 /*syscall*/ + type fdopt = int64 /* fd options */ + type fd = int32 /* fd */ + type whence = uint64 /* seek from whence */ + type mprot = int64 /* memory protection */ + type mopt = int64 /* memory mapping options */ + type socktype = int64 /* socket type */ + type sockproto = int64 /* socket protocol */ + type sockopt = int32 /* socket option */ + type sockfam = uint8 /* socket family */ + type filemode = uint32 + type filetype = uint8 + type fcntlcmd = int64 + type signo = int32 + type sigflags = int32 + type sigset = uint32 + type msg = void + + type clock = union + `Clockrealtime + `Clockmonotonic + `Clockproccputime + `Clockthreadcputime + `Clockuptime + ;; + + type waitstatus = union + `Waitfail int32 + `Waitexit int32 + `Waitsig int32 + `Waitstop int32 + ;; + + type rlimit = struct + cur : uint64 /* current (soft) limit */ + max : uint64 /* maximum value for rlim_cur */ + ;; + + type timespec = struct + sec : uint64 + nsec : uint64 + ;; + + type timeval = struct + sec : uint64 + usec : uint64 + ;; + + type timezone = struct + minwest : int32 /* minutes west of Greenwich */ + dsttime : int32 /* type of dst correction */ + ;; + + type pollfd = struct + fd : fd + events : uint16 + revents : uint16 + ;; + + type itimerval = struct + interval : timeval /* timer interval */ + value : timeval /* current value */ + ;; + + type sigaction = struct + handler : byte# /* code pointer */ + mask : sigset + flags : sigflags + ;; + /* + * Information pushed on stack when a signal is delivered. + * This is used by the kernel to restore state following + * execution of the signal handler. It is also made available + * to the handler to allow it to restore state properly if + * a non-standard exit is performed. + */ + type sigcontext = struct + /* plain match trapframe */ + rdi : int64 + rsi : int64 + rdx : int64 + rcx : int64 + r8 : int64 + r9 : int64 + r10 : int64 + r11 : int64 + r12 : int64 + r13 : int64 + r14 : int64 + r15 : int64 + rbp : int64 + rbx : int64 + rax : int64 + gs : int64 + fs : int64 + es : int64 + ds : int64 + trapno : int64 + err : int64 + rip : int64 + cs : int64 + rflags : int64 + rsp : int64 + ss : int64 + + fpstate : fxsave64# + __pad : int32 + mask : int32 + cookie : int64 + ;; + + type sigaltstack = struct + sp : void# + size : size + flags : int32 + ;; + + type fxsave64 = struct + fcw : int16 + fsw : int16 + ftw : int8 + unused1 : int8 + fop : int16 + rip : int64 + rdp : int64 + mxcsr : int32 + mxcsrmask : int32 + st : int64[8][2] /* 8 normal FP regs */ + xmm : int64[16][2] /* 16 SSE2 registers */ + unused3 : int8[96] + ;; + + const Simaxsz = 128 + const Sipad = (Simaxsz / 4) - 3 + type siginfo = struct + signo : int + code : int + errno : int + pad : int[Sipad] + ;; + + type rusage = struct + utime : timeval /* user time */ + stime : timeval /* system time */ + maxrss : uint64 /* max resident set size*/ + ixrss : uint64 /* shared text size */ + idrss : uint64 /* unshared data size */ + isrss : uint64 /* unshared stack size */ + minflt : uint64 /* page reclaims */ + majflt : uint64 /* page faults */ + nswap : uint64 /* swaps */ + inblock : uint64 /* block input ops */ + oublock : uint64 /* block output ops */ + msgsnd : uint64 /* messages sent */ + msgrcv : uint64 /* messages received */ + nsignals : uint64 /* signals received */ + nvcsw : uint64 /* voluntary context switches */ + nivcsw : uint64 /* involuntary context switches */ + ;; + + type tforkparams = struct + tcb : void# + tid : pid# + stk : byte# + ;; + + type statbuf = struct + mode : filemode + dev : uint32 + ino : uint64 + nlink : uint32 + uid : uint32 + gid : uint32 + rdev : uint32 + atime : timespec + mtime : timespec + ctime : timespec + size : off + blocks : int64 + blksize : uint32 + flags : uint32 + gen : uint32 + birthtim : timespec + ;; + + type semun = struct + semarr : void# + ;; + + const Mfsnamelen = 16 /* length of fs type name, including nul */ + const Mnamelen = 90 /* length of buffer for returned name */ + + type statfs = struct + flags : uint32 /* copy of mount flags */ + bsize : uint32 /* file system block size */ + iosize : uint32 /* optimal transfer block size */ + + /* unit is f_bsize */ + blocks : uint64 /* total data blocks in file system */ + bfree : uint64 /* free blocks in fs */ + bavail : int64 /* free blocks avail to non-superuser */ + + files : int64 /* total file nodes in file system */ + ffree : int64 /* free file nodes in fs */ + favail : int64 /* free file nodes avail to non-root */ + + syncwr : int64 /* count of sync writes since mount */ + syncrd : int64 /* count of sync reads since mount */ + asyncwr : int64 /* count of async writes since mount */ + asyncrd : int64 /* count of async reads since mount */ + + fsid : fsid /* file system id */ + namemax : uint32 /* maximum filename length */ + owner : uid /* user that mounted the file system */ + ctime : uint64 /* last mount [-u] time */ + + fstypename : byte[Mfsnamelen]; /* fs type name */ + mntonname : byte[Mnamelen]; /* directory on which mounted */ + mntfromname : byte[Mnamelen]; /* mounted file system */ + mntfromspec : byte[Mnamelen]; /* special for mount request */ + ///union mount_info mount_info; /* per-filesystem mount options */ + __mountinfo : byte[160]; /* storage for 'union mount_info' */ + ;; + + type utsname = struct + system : byte[32] + node : byte[32] + release : byte[32] + version : byte[32] + machine : byte[32] + ;; + + type sockaddr = struct + len : byte + fam : sockfam + data : byte[14] /* what is the *actual* length? */ + ;; + + type sockaddr_in = struct + len : byte + fam : sockfam + port : uint16 + addr : byte[4] + zero : byte[8] + ;; + + type sockaddr_in6 = struct + len : byte + fam : sockfam + port : uint16 + flow : uint32 + addr : byte[16] + scope : uint32 + ;; + + type sockaddr_un = struct + len : uint8 + fam : sockfam + path : byte[104] + ;; + + type sockaddr_storage = struct + len : byte + fam : sockfam + __pad1 : byte[6] + __align : int64 + __pad2 : byte[240] + ;; + + type dirent = struct + fileno : uint64 + off : uint64 + reclen : uint16 + ftype : uint8 + namlen : uint8 + __pad : byte[4] + name : byte[256] + ;; + + type iovec = struct + base : byte# + len : uint64 + ;; + + /* open options */ + const Ordonly : fdopt = 0x0 + const Owronly : fdopt = 0x1 + const Ordwr : fdopt = 0x2 + const Oappend : fdopt = 0x8 + const Ondelay : fdopt = 0x4 + const Oshlock : fdopt = 0x10 /* open with shared file lock */ + const Oexlock : fdopt = 0x20 /* open with exclusive file lock */ + const Oasync : fdopt = 0x40 /* signal pgrp when data ready */ + const Osync : fdopt = 0x80 /* backwards compatibility */ + const Onofollow : fdopt = 0x100 + const Ocreat : fdopt = 0x200 + const Otrunc : fdopt = 0x400 + const Oexcl : fdopt = 0x800 + const Ocloexec : fdopt = 0x10000 + const Odsync : fdopt = Osync /* synchronous data writes */ + const Orsync : fdopt = Osync /* synchronous reads */ + const Odir : fdopt = 0x20000 + + /* poll options */ + const Pollin : uint16 = 0x0001 + const Pollpri : uint16 = 0x0002 + const Pollout : uint16 = 0x0004 + const Pollerr : uint16 = 0x0008 + const Pollhup : uint16 = 0x0010 + const Pollnval : uint16 = 0x0020 + const Pollnorm : uint16 = 0x0040 + const Pollrdband: uint16 = 0x0080 + const Pollwrband: uint16 = 0x0100 + + /* stat modes */ + const Sifmt : filemode = 0xf000 + const Sififo : filemode = 0x1000 + const Sifchr : filemode = 0x2000 + const Sifdir : filemode = 0x4000 + const Sifblk : filemode = 0x6000 + const Sifreg : filemode = 0x8000 + const Siflnk : filemode = 0xa000 + const Sifsock : filemode = 0xc000 + const Sisvtx : filemode = 0x0200 + + /* mmap protection */ + const Mprotnone : mprot = 0x0 + const Mprotrd : mprot = 0x1 + const Mprotwr : mprot = 0x2 + const Mprotexec : mprot = 0x4 + const Mprotrw : mprot = 0x3 + + /* mmap options */ + const Mshared : mopt = 0x1 + const Mpriv : mopt = 0x2 + const Mfixed : mopt = 0x10 + const Mfile : mopt = 0x0 + const Manon : mopt = 0x1000 + const Mnoreplace : mopt = 0x0800 + + /* file types */ + const Dtunknown : filetype = 0 + const Dtfifo : filetype = 1 + const Dtchr : filetype = 2 + const Dtdir : filetype = 4 + const Dtblk : filetype = 6 + const Dtreg : filetype = 8 + const Dtlnk : filetype = 10 + const Dtsock : filetype = 12 + + /* socket families. INCOMPLETE. */ + const Afunspec : sockfam = 0 + const Afunix : sockfam = 1 + const Afinet : sockfam = 2 + const Afinet6 : sockfam = 24 + + /* socket types. */ + const Sockstream : socktype = 1 + const Sockdgram : socktype = 2 + const Sockraw : socktype = 3 + const Sockrdm : socktype = 4 + const Sockseqpacket : socktype = 5 + + /* socket options */ + const Sodebug : sockopt = 0x0001 /* turn on debugging info recording */ + const Soacceptconn : sockopt = 0x0002 /* socket has had listen() */ + const Soreuseaddr : sockopt = 0x0004 /* allow local address reuse */ + const Sokeepalive : sockopt = 0x0008 /* keep connections alive */ + const Sodontroute : sockopt = 0x0010 /* just use interface addresses */ + const Sobroadcast : sockopt = 0x0020 /* permit sending of broadcast msgs */ + const Souseloopback : sockopt = 0x0040 /* bypass hardware when possible */ + const Solinger : sockopt = 0x0080 /* linger on close if data present */ + const Sooobinline : sockopt = 0x0100 /* leave received OOB data in line */ + const Soreuseport : sockopt = 0x0200 /* allow local address & port reuse */ + const Sotimestamp : sockopt = 0x0800 /* timestamp received dgram traffic */ + const Sobindany : sockopt = 0x1000 /* allow bind to any address */ + const Sosndbuf : sockopt = 0x1001 /* send buffer size */ + const Sorcvbuf : sockopt = 0x1002 /* receive buffer size */ + const Sosndlowat : sockopt = 0x1003 /* send low-water mark */ + const Sorcvlowat : sockopt = 0x1004 /* receive low-water mark */ + const Sosndtimeo : sockopt = 0x1005 /* send timeout */ + const Sorcvtimeo : sockopt = 0x1006 /* receive timeout */ + const Soerror : sockopt = 0x1007 /* get error status and clear */ + const Sotype : sockopt = 0x1008 /* get socket type */ + const Sonetproc : sockopt = 0x1020 /* multiplex; network processing */ + const Sortable : sockopt = 0x1021 /* routing table to be used */ + const Sopeercred : sockopt = 0x1022 /* get connect-time credentials */ + const Sosplice : sockopt = 0x1023 /* splice data to other socket */ + + /* socket option levels */ + const Solsocket : sockproto = 0xffff + + /* network protocols */ + const Ipproto_ip : sockproto = 0 + const Ipproto_icmp : sockproto = 1 + const Ipproto_tcp : sockproto = 6 + const Ipproto_udp : sockproto = 17 + const Ipproto_raw : sockproto = 255 + + const Seekset : whence = 0 + const Seekcur : whence = 1 + const Seekend : whence = 2 + + /* system specific constants */ + const Maxpathlen : size = 1024 + + /* fcntl constants */ + const Fdupfd : fcntlcmd = 0 /* duplicate file descriptor */ + const Fgetfd : fcntlcmd = 1 /* get file descriptor flags */ + const Fsetfd : fcntlcmd = 2 /* set file descriptor flags */ + const Fgetfl : fcntlcmd = 3 /* get file status flags */ + const Fsetfl : fcntlcmd = 4 /* set file status flags */ + const Fgetown : fcntlcmd = 5 /* get SIGIO/SIGURG proc/pgrp */ + const Fsetown : fcntlcmd = 6 /* set SIGIO/SIGURG proc/pgrp */ + const Fogetlk : fcntlcmd = 7 /* get record locking information */ + const Fosetlk : fcntlcmd = 8 /* set record locking information */ + + /* return value for a failed mapping */ + const Mapbad : byte# = (-1 : byte#) + + /* signal flags */ + const Saonstack : sigflags = 0x0001 /* take signal on signal stack */ + const Sarestart : sigflags = 0x0002 /* restart system on signal return */ + const Saresethand : sigflags = 0x0004 /* reset to SIG_DFL when taking signal */ + const Sanodefer : sigflags = 0x0010 /* don't mask the signal we're delivering */ + const Sanocldwait : sigflags = 0x0020 /* don't create zombies (assign to pid 1) */ + const Sanocldstop : sigflags = 0x0008 /* do not generate SIGCHLD on child stop */ + const Sasiginfo : sigflags = 0x0040 /* generate siginfo_t */ + + /* signals */ + const Sighup : signo = 1 /* hangup */ + const Sigint : signo = 2 /* interrupt */ + const Sigquit : signo = 3 /* quit */ + const Sigill : signo = 4 /* illegal instruction (not reset when caught) */ + const Sigtrap : signo = 5 /* trace trap (not reset when caught) */ + const Sigabrt : signo = 6 /* abort() */ + const Sigiot : signo = Sigabrt /* compatibility */ + const Sigemt : signo = 7 /* EMT instruction */ + const Sigfpe : signo = 8 /* floating point exception */ + const Sigkill : signo = 9 /* kill (cannot be caught or ignored) */ + const Sigbus : signo = 10 /* bus error */ + const Sigsegv : signo = 11 /* segmentation violation */ + const Sigsys : signo = 12 /* bad argument to system call */ + const Sigpipe : signo = 13 /* write on a pipe with no one to read it */ + const Sigalrm : signo = 14 /* alarm clock */ + const Sigterm : signo = 15 /* software termination signal from kill */ + const Sigurg : signo = 16 /* urgent condition on IO channel */ + const Sigstop : signo = 17 /* sendable stop signal not from tty */ + const Sigtstp : signo = 18 /* stop signal from tty */ + const Sigcont : signo = 19 /* continue a stopped process */ + const Sigchld : signo = 20 /* to parent on child stop or exit */ + const Sigttin : signo = 21 /* to readers pgrp upon background tty read */ + const Sigttou : signo = 22 /* like TTIN for output if (tp->t_local<OSTOP) */ + const Sigio : signo = 23 /* input/output possible signal */ + const Sigxcpu : signo = 24 /* exceeded CPU time limit */ + const Sigxfsz : signo = 25 /* exceeded file size limit */ + const Sigvtalrm : signo = 26 /* virtual time alarm */ + const Sigprof : signo = 27 /* profiling time alarm */ + const Sigwinch : signo = 28 /* window size changes */ + const Siginfo : signo = 29 /* information request */ + const Sigusr1 : signo = 30 /* user defined signal 1 */ + const Sigusr2 : signo = 31 /* user defined signal 2 */ + const Sigthr : signo = 32 /* thread library AST */ + + extern const syscall : (sc:scno, args:... -> int64) + extern var __cenvp : byte## + type dev = int32 + type uid = uint32 + type gid = uint32 + type fd_mask = uint32 + type uintptr = uint64 + type clockid = int32 + type id = uint32 + type key = int64 + type shmatt = int16 + + type tfork = struct + tcb : void# + tid : pid# + stack : void# + + ;; + + type msghdr = struct + name : void# + namelen : int32 + iov : iovec# + iovlen : uint + control : void# + controllen : int32 + flags : int + + ;; + + type fsid = struct + val : int32[2] + + ;; + + type fid = struct + len : uint16 + reserved : uint16 + data : byte[16] + + ;; + + type fhandle = struct + fsid : fsid + fid : fid + + ;; + + type fdset = struct + bits : fd_mask[32] + + ;; + + type kevent = struct + ident : uintptr + filter : int16 + flags : uint16 + fflags : uint + data : int64 + udata : void# + + ;; + + type kbind = struct + addr : void# + size : size + + ;; + + type sembuf = struct + num : uint16 + op : int16 + flg : int16 + + ;; + + type ipc_perm = struct + cuid : uid + cgid : gid + uid : uid + gid : gid + mode : filemode + seq : uint16 + key : key + + ;; + + type shmid_ds = struct + perm : ipc_perm + segsz : int + lpid : pid + cpid : pid + nattch : shmatt + atime : time + atimensec : int64 + dtime : time + dtimensec : int64 + ctime : time + ctimensec : int64 + internal : void# + + ;; + + type msqid_ds = struct + perm : ipc_perm + first : msg# + last : msg# + cbytes : uint64 + qnum : uint64 + qbytes : uint64 + lspid : pid + lrpid : pid + stime : time + pad1 : int64 + rtime : time + pad2 : int64 + ctime : time + pad3 : int64 + pad4 : int64[4] + + ;; + + + const Futexwait : int = 1 + const Futexwake : int = 2 + const Futexrequeue : int = 3 + + const Sysexit : scno = 1 + const Sysfork : scno = 2 + const Sysread : scno = 3 + const Syswrite : scno = 4 + const Sysopen : scno = 5 + const Sysclose : scno = 6 + const Sysgetentropy : scno = 7 + const Sys__tfork : scno = 8 + const Syslink : scno = 9 + const Sysunlink : scno = 10 + const Syswait4 : scno = 11 + const Syschdir : scno = 12 + const Sysfchdir : scno = 13 + const Sysmknod : scno = 14 + const Syschmod : scno = 15 + const Syschown : scno = 16 + const Sysobreak : scno = 17 + const Sysgetdtablecount : scno = 18 + const Sysgetrusage : scno = 19 + const Sysgetpid : scno = 20 + const Sysmount : scno = 21 + const Sysunmount : scno = 22 + const Syssetuid : scno = 23 + const Sysgetuid : scno = 24 + const Sysgeteuid : scno = 25 + const Sysptrace : scno = 26 + const Sysrecvmsg : scno = 27 + const Syssendmsg : scno = 28 + const Sysrecvfrom : scno = 29 + const Sysaccept : scno = 30 + const Sysgetpeername : scno = 31 + const Sysgetsockname : scno = 32 + const Sysaccess : scno = 33 + const Syschflags : scno = 34 + const Sysfchflags : scno = 35 + const Syssync : scno = 36 + const Sysstat : scno = 38 + const Sysgetppid : scno = 39 + const Syslstat : scno = 40 + const Sysdup : scno = 41 + const Sysfstatat : scno = 42 + const Sysgetegid : scno = 43 + const Sysprofil : scno = 44 + const Sysktrace : scno = 45 + const Syssigaction : scno = 46 + const Sysgetgid : scno = 47 + const Syssigprocmask : scno = 48 + const Syssetlogin : scno = 50 + const Sysacct : scno = 51 + const Syssigpending : scno = 52 + const Sysfstat : scno = 53 + const Sysioctl : scno = 54 + const Sysreboot : scno = 55 + const Sysrevoke : scno = 56 + const Syssymlink : scno = 57 + const Sysreadlink : scno = 58 + const Sysexecve : scno = 59 + const Sysumask : scno = 60 + const Syschroot : scno = 61 + const Sysgetfsstat : scno = 62 + const Sysstatfs : scno = 63 + const Sysfstatfs : scno = 64 + const Sysfhstatfs : scno = 65 + const Sysvfork : scno = 66 + const Sysgettimeofday : scno = 67 + const Syssettimeofday : scno = 68 + const Syssetitimer : scno = 69 + const Sysgetitimer : scno = 70 + const Sysselect : scno = 71 + const Syskevent : scno = 72 + const Sysmunmap : scno = 73 + const Sysmprotect : scno = 74 + const Sysmadvise : scno = 75 + const Sysutimes : scno = 76 + const Sysfutimes : scno = 77 + const Sysmincore : scno = 78 + const Sysgetgroups : scno = 79 + const Syssetgroups : scno = 80 + const Sysgetpgrp : scno = 81 + const Syssetpgid : scno = 82 + const Sysfutex : scno = 83 + const Sysutimensat : scno = 84 + const Sysfutimens : scno = 85 + const Syskbind : scno = 86 + const Sysclock_gettime : scno = 87 + const Sysclock_settime : scno = 88 + const Sysclock_getres : scno = 89 + const Sysdup2 : scno = 90 + const Sysnanosleep : scno = 91 + const Sysfcntl : scno = 92 + const Sysaccept4 : scno = 93 + const Sys__thrsleep : scno = 94 + const Sysfsync : scno = 95 + const Syssetpriority : scno = 96 + const Syssocket : scno = 97 + const Sysconnect : scno = 98 + const Sysgetdents : scno = 99 + const Sysgetpriority : scno = 100 + const Syspipe2 : scno = 101 + const Sysdup3 : scno = 102 + const Syssigreturn : scno = 103 + const Sysbind : scno = 104 + const Syssetsockopt : scno = 105 + const Syslisten : scno = 106 + const Syschflagsat : scno = 107 + const Syspledge : scno = 108 + const Sysppoll : scno = 109 + const Syspselect : scno = 110 + const Syssigsuspend : scno = 111 + const Syssendsyslog : scno = 112 + const Sysfktrace : scno = 113 + const Sysgetsockopt : scno = 118 + const Systhrkill : scno = 119 + const Sysreadv : scno = 120 + const Syswritev : scno = 121 + const Syskill : scno = 122 + const Sysfchown : scno = 123 + const Sysfchmod : scno = 124 + const Syssetreuid : scno = 126 + const Syssetregid : scno = 127 + const Sysrename : scno = 128 + const Sysflock : scno = 131 + const Sysmkfifo : scno = 132 + const Syssendto : scno = 133 + const Sysshutdown : scno = 134 + const Syssocketpair : scno = 135 + const Sysmkdir : scno = 136 + const Sysrmdir : scno = 137 + const Sysadjtime : scno = 140 + const Sysgetlogin_r : scno = 141 + const Syssetsid : scno = 147 + const Sysquotactl : scno = 148 + const Sysnfssvc : scno = 155 + const Sysgetfh : scno = 161 + const Syssysarch : scno = 165 + const Syspread : scno = 173 + const Syspwrite : scno = 174 + const Syssetgid : scno = 181 + const Syssetegid : scno = 182 + const Sysseteuid : scno = 183 + const Syspathconf : scno = 191 + const Sysfpathconf : scno = 192 + const Sysswapctl : scno = 193 + const Sysgetrlimit : scno = 194 + const Syssetrlimit : scno = 195 + const Sysmmap : scno = 197 + const Syslseek : scno = 199 + const Systruncate : scno = 200 + const Sysftruncate : scno = 201 + const Syssysctl : scno = 202 + const Sysmlock : scno = 203 + const Sysmunlock : scno = 204 + const Sysgetpgid : scno = 207 + const Sysutrace : scno = 209 + const Syssemget : scno = 221 + const Sysmsgget : scno = 225 + const Sysmsgsnd : scno = 226 + const Sysmsgrcv : scno = 227 + const Sysshmat : scno = 228 + const Sysshmdt : scno = 230 + const Sysminherit : scno = 250 + const Syspoll : scno = 252 + const Sysissetugid : scno = 253 + const Syslchown : scno = 254 + const Sysgetsid : scno = 255 + const Sysmsync : scno = 256 + const Syspipe : scno = 263 + const Sysfhopen : scno = 264 + const Syspreadv : scno = 267 + const Syspwritev : scno = 268 + const Syskqueue : scno = 269 + const Sysmlockall : scno = 271 + const Sysmunlockall : scno = 272 + const Sysgetresuid : scno = 281 + const Syssetresuid : scno = 282 + const Sysgetresgid : scno = 283 + const Syssetresgid : scno = 284 + const Sysmquery : scno = 286 + const Sysclosefrom : scno = 287 + const Syssigaltstack : scno = 288 + const Sysshmget : scno = 289 + const Syssemop : scno = 290 + const Sysfhstat : scno = 294 + const Sys__semctl : scno = 295 + const Sysshmctl : scno = 296 + const Sysmsgctl : scno = 297 + const Syssched_yield : scno = 298 + const Sysgetthrid : scno = 299 + const Sys__thrwakeup : scno = 301 + const Sys__threxit : scno = 302 + const Sys__thrsigdivert : scno = 303 + const Sys__getcwd : scno = 304 + const Sysadjfreq : scno = 305 + const Syssetrtable : scno = 310 + const Sysgetrtable : scno = 311 + const Sysfaccessat : scno = 313 + const Sysfchmodat : scno = 314 + const Sysfchownat : scno = 315 + const Syslinkat : scno = 317 + const Sysmkdirat : scno = 318 + const Sysmkfifoat : scno = 319 + const Sysmknodat : scno = 320 + const Sysopenat : scno = 321 + const Sysreadlinkat : scno = 322 + const Sysrenameat : scno = 323 + const Syssymlinkat : scno = 324 + const Sysunlinkat : scno = 325 + const Sys__set_tcb : scno = 329 + const Sys__get_tcb : scno = 330 + + /* start manual overrides { */ + const exit : (status:int -> void) + 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 waitpid : (pid:pid, loc:int32#, opt : int64 -> int64) + const execv : (cmd : byte[:], args : byte[:][:] -> int64) + const execve : (cmd : byte[:], args : byte[:][:], env : byte[:][:] -> int64) + const waitstatus : (st : int32 -> waitstatus) + extern const __tfork_thread : (tfp : tforkparams#, sz : size, fn : void#, arg : void# -> pid) + const open : (path:byte[:], opts:fdopt -> fd) + const openmode : (path:byte[:], opts:fdopt, mode:int64 -> fd) + const close : (fd:fd -> int64) + const creat : (path:byte[:], mode:int64 -> fd) + const unlink : (path:byte[:] -> int) + const read : (fd:fd, buf:byte[:] -> size) + const pread : (fd:fd, buf:byte[:], off : off -> size) + const readv : (fd:fd, iov:iovec[:] -> size) + const write : (fd:fd, buf:byte[:] -> size) + const pwrite : (fd:fd, buf:byte[:], off : off -> size) + const writev : (fd:fd, iov:iovec[:] -> size) + const lseek : (fd:fd, off : off, whence : whence -> int64) + const stat : (path:byte[:], sb:statbuf# -> int64) + const lstat : (path:byte[:], sb:statbuf# -> int64) + const fstat : (fd:fd, sb:statbuf# -> int64) + const mkdir : (path : byte[:], mode : int64 -> int64) + generic ioctl : (fd:fd, req : int64, arg:@a# -> int64) + const getdents : (fd : fd, buf : byte[:] -> int64) + const chdir : (p : byte[:] -> int64) + const __getcwd : (buf : byte[:] -> int64) + const poll : (pfd : pollfd[:], tm : int -> int) + const sigaction : (sig : signo, act : sigaction#, oact : sigaction# -> int) + const sigprocmask : (how : int32, set : sigset#, oset : sigset# -> int) + const pipe : (fds : fd[2]# -> int64) + const dup : (fd : fd -> fd) + const dup2 : (src : fd, dst : fd -> fd) + const fcntl : (fd : fd, cmd : fcntlcmd, args : byte# -> int64) + const socket : (dom : sockfam, stype : socktype, proto : sockproto -> fd) + const connect : (sock : fd, addr : sockaddr#, len : size -> int) + const accept : (sock : fd, addr : sockaddr#, len : size# -> fd) + const listen : (sock : fd, backlog : int -> int) + const bind : (sock : fd, addr : sockaddr#, len : size -> int) + const setsockopt : (sock : fd, lev : sockproto, opt : sockopt, val : void#, len : size -> int) + const getsockopt : (sock : fd, lev : sockproto, opt : sockopt, val : void#, len : size# -> int) + const munmap : (addr:byte#, len:size -> int64) + const mmap : (addr:byte#, len:size, prot:mprot, flags:mopt, fd:fd, off:off -> byte#) + const clock_getres : (clk : clock, ts : timespec# -> int32) + const clock_gettime : (clk : clock, ts : timespec# -> int32) + const clock_settime : (clk : clock, ts : timespec# -> int32) + const sleep : (time : uint64 -> int32) + const nanosleep : (req : timespec#, rem : timespec# -> int32) + const uname : (buf : utsname# -> int) + const sysctl : (mib : int[:], \ + old : void#, oldsz : size#, \ + new : void#, newsz : size# \ + -> int) + extern const cstring : (str : byte[:] -> byte#) + extern const alloca : (sz : size -> byte#) + extern const __freebsd_pipe : (fds : fd[2]# -> int64) + /* } end manual overrides */ + + const getentropy : (buf : void#, nbyte : size -> int) + const __tfork : (param : tfork#, psize : size -> int) + const link : (path : byte#, link : byte# -> int) + const fchdir : (fd : int -> int) + const mknod : (path : byte#, mode : filemode, dev : dev -> int) + const chmod : (path : byte#, mode : filemode -> int) + const chown : (path : byte#, uid : uid, gid : gid -> int) + const obreak : (nsize : byte# -> int) + const getdtablecount : ( -> int) + const getrusage : (who : int, rusage : rusage# -> int) + const mount : (kind : byte#, path : byte#, flags : int, data : void# -> int) + const unmount : (path : byte#, flags : int -> int) + const setuid : (uid : uid -> int) + const getuid : ( -> uid) + const geteuid : ( -> uid) + const ptrace : (req : int, pid : pid, addr : void#, data : int -> int) + const recvmsg : (s : int, msg : msghdr#, flags : int -> size) + const sendmsg : (s : int, msg : msghdr#, flags : int -> size) + const recvfrom : (s : int, buf : void#, len : size, flags : int, from : sockaddr#, fromlenaddr : int32# -> size) + const getpeername : (fdes : int, asa : sockaddr#, alen : int32# -> int) + const getsockname : (fdes : int, asa : sockaddr#, alen : int32# -> int) + const access : (path : byte#, amode : int -> int) + const chflags : (path : byte#, flags : uint -> int) + const fchflags : (fd : int, flags : uint -> int) + const sync : ( -> void) + const getppid : ( -> pid) + const fstatat : (fd : int, path : byte#, buf : statbuf#, flag : int -> int) + const getegid : ( -> gid) + const profil : (samples : void#, size : size, offset : uint64, scale : uint -> int) + const ktrace : (fname : byte#, ops : int, facs : int, pid : pid -> int) + const getgid : ( -> gid) + const setlogin : (namebuf : byte# -> int) + const acct : (path : byte# -> int) + const sigpending : ( -> int) + const reboot : (opt : int -> int) + const revoke : (path : byte# -> int) + const symlink : (path : byte#, link : byte# -> int) + const readlink : (path : byte#, buf : byte#, count : size -> size) + const umask : (newmask : filemode -> filemode) + const chroot : (path : byte# -> int) + const getfsstat : (buf : statfs#, bufsize : size, flags : int -> int) + const statfs : (path : byte#, buf : statfs# -> int) + const fstatfs : (fd : int, buf : statfs# -> int) + const fhstatfs : (fhp : fhandle#, buf : statfs# -> int) + const vfork : ( -> int) + const gettimeofday : (tp : timeval#, tzp : timezone# -> int) + const settimeofday : (tv : timeval#, tzp : timezone# -> int) + const setitimer : (which : int, itv : itimerval#, oitv : itimerval# -> int) + const getitimer : (which : int, itv : itimerval# -> int) + const select : (nd : int, _in : fdset#, ou : fdset#, ex : fdset#, tv : timeval# -> int) + const kevent : (fd : int, changelist : kevent#, nchanges : int, eventlist : kevent#, nevents : int, timeout : timespec# -> int) + const mprotect : (addr : void#, len : size, prot : int -> int) + const madvise : (addr : void#, len : size, behav : int -> int) + const utimes : (path : byte#, tptr : timeval# -> int) + const futimes : (fd : int, tptr : timeval# -> int) + const mincore : (addr : void#, len : size, vec : byte# -> int) + const getgroups : (gidsetsize : int, gidset : gid# -> int) + const setgroups : (gidsetsize : int, gidset : gid# -> int) + const getpgrp : ( -> int) + const setpgid : (pid : pid, pgid : pid -> int) + const futex : (f : uint32#, op : int, val : int, timeout : timespec#, g : uint32# -> int) + const utimensat : (fd : int, path : byte#, times : timespec#, flag : int -> int) + const futimens : (fd : int, times : timespec# -> int) + const kbind : (param : kbind#, psize : size, proc_cookie : int64 -> int) + const accept4 : (s : int, name : sockaddr#, anamelen : int32#, flags : int -> int) + const __thrsleep : (ident : void#, clock_id : clockid, tp : timespec#, lock : void#, abort : int# -> int) + const fsync : (fd : int -> int) + const setpriority : (which : int, who : id, prio : int -> int) + const getpriority : (which : int, who : id -> int) + const pipe2 : (fdp : int#, flags : int -> int) + const dup3 : (from : int, to : int, flags : int -> int) + const sigreturn : (sigcntxp : sigcontext# -> int) + const chflagsat : (fd : int, path : byte#, flags : uint, atflags : int -> int) + const pledge : (request : byte#, paths : byte## -> int) + const ppoll : (fds : pollfd#, nfds : uint, ts : timespec#, mask : sigset# -> int) + const pselect : (nd : int, _in : fdset#, ou : fdset#, ex : fdset#, ts : timespec#, mask : sigset# -> int) + const sigsuspend : (mask : int -> int) + const sendsyslog : (buf : void#, nbyte : size, flags : int -> int) + const fktrace : (fd : int, ops : int, facs : int, pid : pid -> int) + const thrkill : (tid : pid, signum : int, tcb : void# -> int) + const fchown : (fd : int, uid : uid, gid : gid -> int) + const fchmod : (fd : int, mode : filemode -> int) + const setreuid : (ruid : uid, euid : uid -> int) + const setregid : (rgid : gid, egid : gid -> int) + const rename : (from : byte#, to : byte# -> int) + const flock : (fd : int, how : int -> int) + const mkfifo : (path : byte#, mode : filemode -> int) + const sendto : (s : int, buf : void#, len : size, flags : int, to : sockaddr#, tolen : int32 -> size) + const shutdown : (s : int, how : int -> int) + const socketpair : (domain : int, kind : int, protocol : int, rsv : int# -> int) + const rmdir : (path : byte# -> int) + const adjtime : (delta : timeval#, olddelta : timeval# -> int) + const getlogin_r : (namebuf : byte#, namelen : uint -> int) + const setsid : ( -> int) + const quotactl : (path : byte#, cmd : int, uid : int, arg : byte# -> int) + const nfssvc : (flag : int, argp : void# -> int) + const getfh : (fname : byte#, fhp : fhandle# -> int) + const sysarch : (op : int, parms : void# -> int) + const setgid : (gid : gid -> int) + const setegid : (egid : gid -> int) + const seteuid : (euid : uid -> int) + const pathconf : (path : byte#, name : int -> int64) + const fpathconf : (fd : int, name : int -> int64) + const swapctl : (cmd : int, arg : void#, misc : int -> int) + const getrlimit : (which : int, rlp : rlimit# -> int) + const setrlimit : (which : int, rlp : rlimit# -> int) + const truncate : (path : byte#, pad : int, length : off -> int) + const ftruncate : (fd : int, pad : int, length : off -> int) + const mlock : (addr : void#, len : size -> int) + const munlock : (addr : void#, len : size -> int) + const getpgid : (pid : pid -> pid) + const utrace : (label : byte#, addr : void#, len : size -> int) + const semget : (key : key, nsems : int, semflg : int -> int) + const msgget : (key : key, msgflg : int -> int) + const msgsnd : (msqid : int, msgp : void#, msgsz : size, msgflg : int -> int) + const msgrcv : (msqid : int, msgp : void#, msgsz : size, msgtyp : int64, msgflg : int -> int) + const shmat : (shmid : int, shmaddr : void#, shmflg : int -> void) + const shmdt : (shmaddr : void# -> int) + const minherit : (addr : void#, len : size, inherit : int -> int) + const issetugid : ( -> int) + const lchown : (path : byte#, uid : uid, gid : gid -> int) + const getsid : (pid : pid -> pid) + const msync : (addr : void#, len : size, flags : int -> int) + const fhopen : (fhp : fhandle#, flags : int -> int) + const preadv : (fd : int, iovp : iovec#, iovcnt : int, pad : int, offset : off -> size) + const pwritev : (fd : int, iovp : iovec#, iovcnt : int, pad : int, offset : off -> size) + const kqueue : ( -> int) + const mlockall : (flags : int -> int) + const munlockall : ( -> int) + const getresuid : (ruid : uid#, euid : uid#, suid : uid# -> int) + const setresuid : (ruid : uid, euid : uid, suid : uid -> int) + const getresgid : (rgid : gid#, egid : gid#, sgid : gid# -> int) + const setresgid : (rgid : gid, egid : gid, sgid : gid -> int) + const mquery : (addr : void#, len : size, prot : int, flags : int, fd : int, pad : int64, pos : off -> void) + const closefrom : (fd : int -> int) + const sigaltstack : (nss : sigaltstack#, oss : sigaltstack# -> int) + const shmget : (key : key, size : size, shmflg : int -> int) + const semop : (semid : int, sops : sembuf#, nsops : size -> int) + const fhstat : (fhp : fhandle#, sb : statbuf# -> int) + const __semctl : (semid : int, semnum : int, cmd : int, arg : semun# -> int) + const shmctl : (shmid : int, cmd : int, buf : shmid_ds# -> int) + const msgctl : (msqid : int, cmd : int, buf : msqid_ds# -> int) + const sched_yield : ( -> int) + const getthrid : ( -> pid) + const __thrwakeup : (ident : void#, n : int -> int) + const __threxit : (notdead : pid# -> void) + const __thrsigdivert : (sigmask : sigset, info : siginfo#, timeout : timespec# -> int) + const adjfreq : (freq : int64#, oldfreq : int64# -> int) + const setrtable : (rtableid : int -> int) + const getrtable : ( -> int) + const faccessat : (fd : int, path : byte#, amode : int, flag : int -> int) + const fchmodat : (fd : int, path : byte#, mode : filemode, flag : int -> int) + const fchownat : (fd : int, path : byte#, uid : uid, gid : gid, flag : int -> int) + const linkat : (fd1 : int, path1 : byte#, fd2 : int, path2 : byte#, flag : int -> int) + const mkdirat : (fd : int, path : byte#, mode : filemode -> int) + const mkfifoat : (fd : int, path : byte#, mode : filemode -> int) + const mknodat : (fd : int, path : byte#, mode : filemode, dev : dev -> int) + const openat : (fd : int, path : byte#, flags : int, mode : filemode -> int) + const readlinkat : (fd : int, path : byte#, buf : byte#, count : size -> size) + const renameat : (fromfd : int, from : byte#, tofd : int, to : byte# -> int) + const symlinkat : (path : byte#, fd : int, link : byte# -> int) + const unlinkat : (fd : int, path : byte#, flag : int -> int) + const __set_tcb : (tcb : void# -> void) + const __get_tcb : ( -> void) +;; + + /* start manual overrides { */ + /* process control */ + /* wrappers to extract wait status */ + + /* fd manipulation */ + + /* signals */ + + /* fd stuff */ + /* NB: the C ABI uses '...' for the args. */ + + /* networking */ + + /* memory mapping */ + + /* time - doublecheck if this is right */ + + /* system information */ + + /* + wraps a syscall argument, converting it to 64 bits for the syscall function. This is + the same as casting, but more concise than writing a cast to uint64 + */ + generic a = {x : @t; -> (x : uint64)} + + + + /* process management */ + const exit = {status; syscall(Sysexit, a(status))} + const getpid = {; -> (syscall(Sysgetpid, 1) : pid)} + const kill = {pid, sig; -> syscall(Syskill, pid, sig)} + const fork = {; -> (syscall(Sysfork) : pid)} + const wait4 = {pid, loc, opt, usage; -> syscall(Syswait4, pid, loc, opt, usage)} + const waitpid = {pid, loc, opt; + -> wait4(pid, loc, opt, (0 : rusage#)) + } + + const execv = {cmd, args + var p, cargs, i + + /* 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 : byte##)[:args.len + 1] + for i = 0; i < args.len; i++ + cargs[i] = cstring(args[i]) + ;; + cargs[args.len] = (0 : byte#) + -> syscall(Sysexecve, cstring(cmd), a(p), a(__cenvp)) + } + + const execve = {cmd, args, env + var cargs, cenv, i + var p + + /* copy the args */ + p = alloca((args.len + 1)*sizeof(byte#)) + cargs = (p : byte##)[:args.len] + for i = 0; i < args.len; i++ + cargs[i] = cstring(args[i]) + ;; + cargs[args.len] = (0 : byte#) + + /* + copy the env. + of course we fucking have to duplicate this code everywhere, + since we want to stack allocate... + */ + p = alloca((env.len + 1)*sizeof(byte#)) + cenv = (p : byte##)[:env.len] + for i = 0; i < env.len; i++ + cenv[i] = cstring(env[i]) + ;; + cenv[env.len] = (0 : byte#) + + -> syscall(Sysexecve, cstring(cmd), a(p), a(cenv)) + } + + /* fd manipulation */ + const open = {path, opts; -> (syscall(Sysopen, cstring(path), a(opts), a(0o777)) : fd)} + const openmode = {path, opts, mode; -> (syscall(Sysopen, cstring(path), a(opts), a(mode)) : fd)} + const close = {fd; -> syscall(Sysclose, a(fd))} + const creat = {path, mode; -> (openmode(path, Ocreat | Otrunc | Owronly, mode) : fd)} + const unlink = {path; -> (syscall(Sysunlink, cstring(path)) : int)} + const read = {fd, buf; -> (syscall(Sysread, a(fd), (buf : byte#), a(buf.len)) : size)} + const pread = {fd, buf, off; -> (syscall(Syspread, a(fd), (buf : byte#), a(buf.len), a(off)) : size)} + const readv = {fd, vec; -> (syscall(Sysreadv, a(fd), (vec : iovec#), a(vec.len)) : size)} + const write = {fd, buf; -> (syscall(Syswrite, a(fd), (buf : byte#), a(buf.len)) : size)} + const pwrite = {fd, buf, off; -> (syscall(Syspwrite, a(fd), (buf : byte#), a(buf.len), a(off)) : size)} + const writev = {fd, vec; -> (syscall(Syswritev, a(fd), (vec : iovec#), a(vec.len)) : 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 lstat = {path, sb; -> syscall(Syslstat, cstring(path), a(sb))} + const fstat = {fd, sb; -> syscall(Sysfstat, a(fd), a(sb))} + const mkdir = {path, mode; -> (syscall(Sysmkdir, cstring(path), a(mode)) : int64)} + generic ioctl = {fd, req, arg; -> (syscall(Sysioctl, a(fd), a(req), a(arg)) : int64)} + const chdir = {dir; -> syscall(Syschdir, cstring(dir))} + const __getcwd = {buf; -> syscall(Sys__getcwd, a(buf), a(buf.len))} + const getdents = {fd, buf; -> (syscall(Sysgetdents, a(fd), a(buf), a(buf.len)) : int64)} + + /* signals */ + const sigaction = {sig, act, oact; -> (syscall(Syssigaction, a(sig), a(act), a(oact)) : int)} + const sigprocmask = {sig, act, oact; -> (syscall(Syssigprocmask, a(sig), a(act), a(oact)) : int)} + + /* file stuff */ + const pipe = {fds; -> syscall(Syspipe, fds)} + const dup = {fd; -> (syscall(Sysdup, a(fd)) : fd)} + const dup2 = {src, dst; -> (syscall(Sysdup2, a(src), a(dst)) : fd)} + const fcntl = {fd, cmd, args; -> syscall(Sysfcntl, a(fd), a(cmd), a(args))} + const poll = {pfd, tm; -> (syscall(Syspoll, (pfd : byte#), a(pfd.len), a(tm)) : int)} + + /* networking */ + const socket = {dom, stype, proto; -> (syscall(Syssocket, a(dom), a(stype), a(proto)) : fd)} + const connect = {sock, addr, len; -> (syscall(Sysconnect, a(sock), a(addr), a(len)) : int)} + const accept = {sock, addr, len; -> (syscall(Sysaccept, a(sock), a(addr), a(len)) : fd)} + const listen = {sock, backlog; -> (syscall(Syslisten, a(sock), a(backlog)) : int)} + const bind = {sock, addr, len; -> (syscall(Sysbind, a(sock), a(addr), a(len)) : int)} + const setsockopt = {sock, lev, opt, val, len; -> (syscall(Syssetsockopt, a(sock), a(lev), a(opt), a(val), a(len)) : int)} + const getsockopt = {sock, lev, opt, val, len; -> (syscall(Syssetsockopt, a(sock), a(lev), a(opt), a(val), a(len)) : int)} + + /* memory management */ + const munmap = {addr, len; -> syscall(Sysmunmap, a(addr), a(len))} + const mmap = {addr, len, prot, flags, fd, off; + /* the actual syscall has padding on the offset arg */ + -> (syscall(Sysmmap, a(addr), a(len), a(prot), a(flags), a(fd), a(0), a(off)) : byte#) + } + + /* time */ + const clock_getres = {clk, ts; -> (syscall(Sysclock_getres, clockid(clk), a(ts)) : int32)} + const clock_gettime = {clk, ts; -> (syscall(Sysclock_gettime, clockid(clk), a(ts)) : int32)} + const clock_settime = {clk, ts; -> (syscall(Sysclock_settime, clockid(clk), a(ts)) : int32)} + + const sleep = {time + var req, rem + req = [.sec = time, .nsec = 0] + -> nanosleep(&req, &rem) + } + + const nanosleep = {req, rem; -> (syscall(Sysnanosleep, a(req), a(rem)) : int32)} + + + /* system information */ + const uname = {buf + var mib : int[2] + var ret + 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[:] : void#) + syssz = buf.system.len + ret = sysctl(mib[:], sys, &syssz, (0 : void#), (0 : size#)) + if ret < 0 + -> ret + ;; + + mib[0] = 1 /* CTL_KERN */ + mib[1] = 10 /* KERN_HOSTNAME */ + nod = (buf.node[:] : void#) + nodsz = buf.node.len + ret = sysctl(mib[:], nod, &nodsz, (0 : void#), (0 : size#)) + if ret < 0 + -> ret + ;; + + mib[0] = 1 /* CTL_KERN */ + mib[1] = 2 /* KERN_OSRELEASE */ + rel = (buf.release[:] : void#) + relsz = buf.release.len + ret = sysctl(mib[:], rel, &relsz, (0 : void#), (0 : size#)) + if ret < 0 + -> ret + ;; + + mib[0] = 1 /* CTL_KERN */ + mib[1] = 27 /* KERN_OSVERSION */ + ver = (buf.version[:] : void#) + versz = buf.version.len + ret = sysctl(mib[:], ver, &versz, (0 : void#), (0 : size#)) + if ret < 0 + -> ret + ;; + + mib[0] = 6 /* CTL_HW */ + mib[1] = 1 /* HW_MACHINE */ + mach = (buf.machine[:] : void#) + machsz = buf.machine.len + ret = sysctl(mib[:], mach, &machsz, (0 : void#), (0 : size#)) + if ret < 0 + -> ret + ;; + + -> 0 + } + + const sysctl = {mib, old, oldsz, new, newsz + /* all args already passed through a() or ar ptrs */ + -> (syscall(Syssysctl, \ + (mib : int#), a(mib.len), old, oldsz, new, newsz) : int) + } + + const clockid = {clk + match clk + | `Clockrealtime: -> 0 + | `Clockproccputime: -> 2 + | `Clockmonotonic: -> 3 + | `Clockthreadcputime: -> 4 + | `Clockuptime: -> 5 + ;; + -> -1 + } + + const waitstatus = {st + if st < 0 + -> `Waitfail st + ;; + match st & 0o177 + | 0: -> `Waitexit (st >> 8) + | 0x7f:-> `Waitstop (st >> 8) + | sig: -> `Waitsig sig + ;; + } + + /* } end manual overrides */ +const getentropy = {buf, nbyte + -> (syscall(Sysgetentropy, a(buf), a(nbyte)) : int) +} +const __tfork = {param, psize + -> (syscall(Sys__tfork, a(param), a(psize)) : int) +} +const link = {path, link + -> (syscall(Syslink, a(path), a(link)) : int) +} +const fchdir = {fd + -> (syscall(Sysfchdir, a(fd)) : int) +} +const mknod = {path, mode, dev + -> (syscall(Sysmknod, a(path), a(mode), a(dev)) : int) +} +const chmod = {path, mode + -> (syscall(Syschmod, a(path), a(mode)) : int) +} +const chown = {path, uid, gid + -> (syscall(Syschown, a(path), a(uid), a(gid)) : int) +} +const obreak = {nsize + -> (syscall(Sysobreak, a(nsize)) : int) +} +const getdtablecount = { + -> (syscall(Sysgetdtablecount) : int) +} +const getrusage = {who, rusage + -> (syscall(Sysgetrusage, a(who), a(rusage)) : int) +} +const mount = {kind, path, flags, data + -> (syscall(Sysmount, a(kind), a(path), a(flags), a(data)) : int) +} +const unmount = {path, flags + -> (syscall(Sysunmount, a(path), a(flags)) : int) +} +const setuid = {uid + -> (syscall(Syssetuid, a(uid)) : int) +} +const getuid = { + -> (syscall(Sysgetuid) : uid) +} +const geteuid = { + -> (syscall(Sysgeteuid) : uid) +} +const ptrace = {req, pid, addr, data + -> (syscall(Sysptrace, a(req), a(pid), a(addr), a(data)) : int) +} +const recvmsg = {s, msg, flags + -> (syscall(Sysrecvmsg, a(s), a(msg), a(flags)) : size) +} +const sendmsg = {s, msg, flags + -> (syscall(Syssendmsg, a(s), a(msg), a(flags)) : size) +} +const recvfrom = {s, buf, len, flags, from, fromlenaddr + -> (syscall(Sysrecvfrom, a(s), a(buf), a(len), a(flags), a(from), a(fromlenaddr)) : size) +} +const getpeername = {fdes, asa, alen + -> (syscall(Sysgetpeername, a(fdes), a(asa), a(alen)) : int) +} +const getsockname = {fdes, asa, alen + -> (syscall(Sysgetsockname, a(fdes), a(asa), a(alen)) : int) +} +const access = {path, amode + -> (syscall(Sysaccess, a(path), a(amode)) : int) +} +const chflags = {path, flags + -> (syscall(Syschflags, a(path), a(flags)) : int) +} +const fchflags = {fd, flags + -> (syscall(Sysfchflags, a(fd), a(flags)) : int) +} +const sync = { + -> (syscall(Syssync) : void) +} +const getppid = { + -> (syscall(Sysgetppid) : pid) +} +const fstatat = {fd, path, buf, flag + -> (syscall(Sysfstatat, a(fd), a(path), a(buf), a(flag)) : int) +} +const getegid = { + -> (syscall(Sysgetegid) : gid) +} +const profil = {samples, size, offset, scale + -> (syscall(Sysprofil, a(samples), a(size), a(offset), a(scale)) : int) +} +const ktrace = {fname, ops, facs, pid + -> (syscall(Sysktrace, a(fname), a(ops), a(facs), a(pid)) : int) +} +const getgid = { + -> (syscall(Sysgetgid) : gid) +} +const setlogin = {namebuf + -> (syscall(Syssetlogin, a(namebuf)) : int) +} +const acct = {path + -> (syscall(Sysacct, a(path)) : int) +} +const sigpending = { + -> (syscall(Syssigpending) : int) +} +const reboot = {opt + -> (syscall(Sysreboot, a(opt)) : int) +} +const revoke = {path + -> (syscall(Sysrevoke, a(path)) : int) +} +const symlink = {path, link + -> (syscall(Syssymlink, a(path), a(link)) : int) +} +const readlink = {path, buf, count + -> (syscall(Sysreadlink, a(path), a(buf), a(count)) : size) +} +const umask = {newmask + -> (syscall(Sysumask, a(newmask)) : filemode) +} +const chroot = {path + -> (syscall(Syschroot, a(path)) : int) +} +const getfsstat = {buf, bufsize, flags + -> (syscall(Sysgetfsstat, a(buf), a(bufsize), a(flags)) : int) +} +const statfs = {path, buf + -> (syscall(Sysstatfs, a(path), a(buf)) : int) +} +const fstatfs = {fd, buf + -> (syscall(Sysfstatfs, a(fd), a(buf)) : int) +} +const fhstatfs = {fhp, buf + -> (syscall(Sysfhstatfs, a(fhp), a(buf)) : int) +} +const vfork = { + -> (syscall(Sysvfork) : int) +} +const gettimeofday = {tp, tzp + -> (syscall(Sysgettimeofday, a(tp), a(tzp)) : int) +} +const settimeofday = {tv, tzp + -> (syscall(Syssettimeofday, a(tv), a(tzp)) : int) +} +const setitimer = {which, itv, oitv + -> (syscall(Syssetitimer, a(which), a(itv), a(oitv)) : int) +} +const getitimer = {which, itv + -> (syscall(Sysgetitimer, a(which), a(itv)) : int) +} +const select = {nd, _in, ou, ex, tv + -> (syscall(Sysselect, a(nd), a(_in), a(ou), a(ex), a(tv)) : int) +} +const kevent = {fd, changelist, nchanges, eventlist, nevents, timeout + -> (syscall(Syskevent, a(fd), a(changelist), a(nchanges), a(eventlist), a(nevents), a(timeout)) : int) +} +const mprotect = {addr, len, prot + -> (syscall(Sysmprotect, a(addr), a(len), a(prot)) : int) +} +const madvise = {addr, len, behav + -> (syscall(Sysmadvise, a(addr), a(len), a(behav)) : int) +} +const utimes = {path, tptr + -> (syscall(Sysutimes, a(path), a(tptr)) : int) +} +const futimes = {fd, tptr + -> (syscall(Sysfutimes, a(fd), a(tptr)) : int) +} +const mincore = {addr, len, vec + -> (syscall(Sysmincore, a(addr), a(len), a(vec)) : int) +} +const getgroups = {gidsetsize, gidset + -> (syscall(Sysgetgroups, a(gidsetsize), a(gidset)) : int) +} +const setgroups = {gidsetsize, gidset + -> (syscall(Syssetgroups, a(gidsetsize), a(gidset)) : int) +} +const getpgrp = { + -> (syscall(Sysgetpgrp) : int) +} +const setpgid = {pid, pgid + -> (syscall(Syssetpgid, a(pid), a(pgid)) : int) +} +const futex = {f, op, val, timeout, g + -> (syscall(Sysfutex, a(f), a(op), a(val), a(timeout), a(g)) : int) +} +const utimensat = {fd, path, times, flag + -> (syscall(Sysutimensat, a(fd), a(path), a(times), a(flag)) : int) +} +const futimens = {fd, times + -> (syscall(Sysfutimens, a(fd), a(times)) : int) +} +const kbind = {param, psize, proc_cookie + -> (syscall(Syskbind, a(param), a(psize), a(proc_cookie)) : int) +} +const accept4 = {s, name, anamelen, flags + -> (syscall(Sysaccept4, a(s), a(name), a(anamelen), a(flags)) : int) +} +const __thrsleep = {ident, clock_id, tp, lock, abort + -> (syscall(Sys__thrsleep, a(ident), a(clock_id), a(tp), a(lock), a(abort)) : int) +} +const fsync = {fd + -> (syscall(Sysfsync, a(fd)) : int) +} +const setpriority = {which, who, prio + -> (syscall(Syssetpriority, a(which), a(who), a(prio)) : int) +} +const getpriority = {which, who + -> (syscall(Sysgetpriority, a(which), a(who)) : int) +} +const pipe2 = {fdp, flags + -> (syscall(Syspipe2, a(fdp), a(flags)) : int) +} +const dup3 = {from, to, flags + -> (syscall(Sysdup3, a(from), a(to), a(flags)) : int) +} +const sigreturn = {sigcntxp + -> (syscall(Syssigreturn, a(sigcntxp)) : int) +} +const chflagsat = {fd, path, flags, atflags + -> (syscall(Syschflagsat, a(fd), a(path), a(flags), a(atflags)) : int) +} +const pledge = {request, paths + -> (syscall(Syspledge, a(request), a(paths)) : int) +} +const ppoll = {fds, nfds, ts, mask + -> (syscall(Sysppoll, a(fds), a(nfds), a(ts), a(mask)) : int) +} +const pselect = {nd, _in, ou, ex, ts, mask + -> (syscall(Syspselect, a(nd), a(_in), a(ou), a(ex), a(ts), a(mask)) : int) +} +const sigsuspend = {mask + -> (syscall(Syssigsuspend, a(mask)) : int) +} +const sendsyslog = {buf, nbyte, flags + -> (syscall(Syssendsyslog, a(buf), a(nbyte), a(flags)) : int) +} +const fktrace = {fd, ops, facs, pid + -> (syscall(Sysfktrace, a(fd), a(ops), a(facs), a(pid)) : int) +} +const thrkill = {tid, signum, tcb + -> (syscall(Systhrkill, a(tid), a(signum), a(tcb)) : int) +} +const fchown = {fd, uid, gid + -> (syscall(Sysfchown, a(fd), a(uid), a(gid)) : int) +} +const fchmod = {fd, mode + -> (syscall(Sysfchmod, a(fd), a(mode)) : int) +} +const setreuid = {ruid, euid + -> (syscall(Syssetreuid, a(ruid), a(euid)) : int) +} +const setregid = {rgid, egid + -> (syscall(Syssetregid, a(rgid), a(egid)) : int) +} +const rename = {from, to + -> (syscall(Sysrename, a(from), a(to)) : int) +} +const flock = {fd, how + -> (syscall(Sysflock, a(fd), a(how)) : int) +} +const mkfifo = {path, mode + -> (syscall(Sysmkfifo, a(path), a(mode)) : int) +} +const sendto = {s, buf, len, flags, to, tolen + -> (syscall(Syssendto, a(s), a(buf), a(len), a(flags), a(to), a(tolen)) : size) +} +const shutdown = {s, how + -> (syscall(Sysshutdown, a(s), a(how)) : int) +} +const socketpair = {domain, kind, protocol, rsv + -> (syscall(Syssocketpair, a(domain), a(kind), a(protocol), a(rsv)) : int) +} +const rmdir = {path + -> (syscall(Sysrmdir, a(path)) : int) +} +const adjtime = {delta, olddelta + -> (syscall(Sysadjtime, a(delta), a(olddelta)) : int) +} +const getlogin_r = {namebuf, namelen + -> (syscall(Sysgetlogin_r, a(namebuf), a(namelen)) : int) +} +const setsid = { + -> (syscall(Syssetsid) : int) +} +const quotactl = {path, cmd, uid, arg + -> (syscall(Sysquotactl, a(path), a(cmd), a(uid), a(arg)) : int) +} +const nfssvc = {flag, argp + -> (syscall(Sysnfssvc, a(flag), a(argp)) : int) +} +const getfh = {fname, fhp + -> (syscall(Sysgetfh, a(fname), a(fhp)) : int) +} +const sysarch = {op, parms + -> (syscall(Syssysarch, a(op), a(parms)) : int) +} +const setgid = {gid + -> (syscall(Syssetgid, a(gid)) : int) +} +const setegid = {egid + -> (syscall(Syssetegid, a(egid)) : int) +} +const seteuid = {euid + -> (syscall(Sysseteuid, a(euid)) : int) +} +const pathconf = {path, name + -> (syscall(Syspathconf, a(path), a(name)) : int64) +} +const fpathconf = {fd, name + -> (syscall(Sysfpathconf, a(fd), a(name)) : int64) +} +const swapctl = {cmd, arg, misc + -> (syscall(Sysswapctl, a(cmd), a(arg), a(misc)) : int) +} +const getrlimit = {which, rlp + -> (syscall(Sysgetrlimit, a(which), a(rlp)) : int) +} +const setrlimit = {which, rlp + -> (syscall(Syssetrlimit, a(which), a(rlp)) : int) +} +const truncate = {path, pad, length + -> (syscall(Systruncate, a(path), a(pad), a(length)) : int) +} +const ftruncate = {fd, pad, length + -> (syscall(Sysftruncate, a(fd), a(pad), a(length)) : int) +} +const mlock = {addr, len + -> (syscall(Sysmlock, a(addr), a(len)) : int) +} +const munlock = {addr, len + -> (syscall(Sysmunlock, a(addr), a(len)) : int) +} +const getpgid = {pid + -> (syscall(Sysgetpgid, a(pid)) : pid) +} +const utrace = {label, addr, len + -> (syscall(Sysutrace, a(label), a(addr), a(len)) : int) +} +const semget = {key, nsems, semflg + -> (syscall(Syssemget, a(key), a(nsems), a(semflg)) : int) +} +const msgget = {key, msgflg + -> (syscall(Sysmsgget, a(key), a(msgflg)) : int) +} +const msgsnd = {msqid, msgp, msgsz, msgflg + -> (syscall(Sysmsgsnd, a(msqid), a(msgp), a(msgsz), a(msgflg)) : int) +} +const msgrcv = {msqid, msgp, msgsz, msgtyp, msgflg + -> (syscall(Sysmsgrcv, a(msqid), a(msgp), a(msgsz), a(msgtyp), a(msgflg)) : int) +} +const shmat = {shmid, shmaddr, shmflg + -> (syscall(Sysshmat, a(shmid), a(shmaddr), a(shmflg)) : void) +} +const shmdt = {shmaddr + -> (syscall(Sysshmdt, a(shmaddr)) : int) +} +const minherit = {addr, len, inherit + -> (syscall(Sysminherit, a(addr), a(len), a(inherit)) : int) +} +const issetugid = { + -> (syscall(Sysissetugid) : int) +} +const lchown = {path, uid, gid + -> (syscall(Syslchown, a(path), a(uid), a(gid)) : int) +} +const getsid = {pid + -> (syscall(Sysgetsid, a(pid)) : pid) +} +const msync = {addr, len, flags + -> (syscall(Sysmsync, a(addr), a(len), a(flags)) : int) +} +const fhopen = {fhp, flags + -> (syscall(Sysfhopen, a(fhp), a(flags)) : int) +} +const preadv = {fd, iovp, iovcnt, pad, offset + -> (syscall(Syspreadv, a(fd), a(iovp), a(iovcnt), a(pad), a(offset)) : size) +} +const pwritev = {fd, iovp, iovcnt, pad, offset + -> (syscall(Syspwritev, a(fd), a(iovp), a(iovcnt), a(pad), a(offset)) : size) +} +const kqueue = { + -> (syscall(Syskqueue) : int) +} +const mlockall = {flags + -> (syscall(Sysmlockall, a(flags)) : int) +} +const munlockall = { + -> (syscall(Sysmunlockall) : int) +} +const getresuid = {ruid, euid, suid + -> (syscall(Sysgetresuid, a(ruid), a(euid), a(suid)) : int) +} +const setresuid = {ruid, euid, suid + -> (syscall(Syssetresuid, a(ruid), a(euid), a(suid)) : int) +} +const getresgid = {rgid, egid, sgid + -> (syscall(Sysgetresgid, a(rgid), a(egid), a(sgid)) : int) +} +const setresgid = {rgid, egid, sgid + -> (syscall(Syssetresgid, a(rgid), a(egid), a(sgid)) : int) +} +const mquery = {addr, len, prot, flags, fd, pad, pos + -> (syscall(Sysmquery, a(addr), a(len), a(prot), a(flags), a(fd), a(pad), a(pos)) : void) +} +const closefrom = {fd + -> (syscall(Sysclosefrom, a(fd)) : int) +} +const sigaltstack = {nss, oss + -> (syscall(Syssigaltstack, a(nss), a(oss)) : int) +} +const shmget = {key, size, shmflg + -> (syscall(Sysshmget, a(key), a(size), a(shmflg)) : int) +} +const semop = {semid, sops, nsops + -> (syscall(Syssemop, a(semid), a(sops), a(nsops)) : int) +} +const fhstat = {fhp, sb + -> (syscall(Sysfhstat, a(fhp), a(sb)) : int) +} +const __semctl = {semid, semnum, cmd, arg + -> (syscall(Sys__semctl, a(semid), a(semnum), a(cmd), a(arg)) : int) +} +const shmctl = {shmid, cmd, buf + -> (syscall(Sysshmctl, a(shmid), a(cmd), a(buf)) : int) +} +const msgctl = {msqid, cmd, buf + -> (syscall(Sysmsgctl, a(msqid), a(cmd), a(buf)) : int) +} +const sched_yield = { + -> (syscall(Syssched_yield) : int) +} +const getthrid = { + -> (syscall(Sysgetthrid) : pid) +} +const __thrwakeup = {ident, n + -> (syscall(Sys__thrwakeup, a(ident), a(n)) : int) +} +const __threxit = {notdead + -> (syscall(Sys__threxit, a(notdead)) : void) +} +const __thrsigdivert = {sigmask, info, timeout + -> (syscall(Sys__thrsigdivert, a(sigmask), a(info), a(timeout)) : int) +} +const adjfreq = {freq, oldfreq + -> (syscall(Sysadjfreq, a(freq), a(oldfreq)) : int) +} +const setrtable = {rtableid + -> (syscall(Syssetrtable, a(rtableid)) : int) +} +const getrtable = { + -> (syscall(Sysgetrtable) : int) +} +const faccessat = {fd, path, amode, flag + -> (syscall(Sysfaccessat, a(fd), a(path), a(amode), a(flag)) : int) +} +const fchmodat = {fd, path, mode, flag + -> (syscall(Sysfchmodat, a(fd), a(path), a(mode), a(flag)) : int) +} +const fchownat = {fd, path, uid, gid, flag + -> (syscall(Sysfchownat, a(fd), a(path), a(uid), a(gid), a(flag)) : int) +} +const linkat = {fd1, path1, fd2, path2, flag + -> (syscall(Syslinkat, a(fd1), a(path1), a(fd2), a(path2), a(flag)) : int) +} +const mkdirat = {fd, path, mode + -> (syscall(Sysmkdirat, a(fd), a(path), a(mode)) : int) +} +const mkfifoat = {fd, path, mode + -> (syscall(Sysmkfifoat, a(fd), a(path), a(mode)) : int) +} +const mknodat = {fd, path, mode, dev + -> (syscall(Sysmknodat, a(fd), a(path), a(mode), a(dev)) : int) +} +const openat = {fd, path, flags, mode + -> (syscall(Sysopenat, a(fd), a(path), a(flags), a(mode)) : int) +} +const readlinkat = {fd, path, buf, count + -> (syscall(Sysreadlinkat, a(fd), a(path), a(buf), a(count)) : size) +} +const renameat = {fromfd, from, tofd, to + -> (syscall(Sysrenameat, a(fromfd), a(from), a(tofd), a(to)) : int) +} +const symlinkat = {path, fd, link + -> (syscall(Syssymlinkat, a(path), a(fd), a(link)) : int) +} +const unlinkat = {fd, path, flag + -> (syscall(Sysunlinkat, a(fd), a(path), a(flag)) : int) +} +const __set_tcb = {tcb + -> (syscall(Sys__set_tcb, a(tcb)) : void) +} +const __get_tcb = { + -> (syscall(Sys__get_tcb) : void) +} diff --git a/lib/sys/sys+osx-x64.myr b/lib/sys/sys+osx-x64.myr index 2c42094..3de3875 100644 --- a/lib/sys/sys+osx-x64.myr +++ b/lib/sys/sys+osx-x64.myr @@ -840,7 +840,7 @@ extern const __osx_fork : (-> pid) extern const __osx_pipe : (fd : fd[2]# -> int64) extern const __osx_getpid : (-> pid) extern const __osx_lseek : (fd:fd, off:off, whence:whence -> off) -extern const __osx_gettimeofday : (tv : timeval#, tz : timezone# -> int) +extern const __osx_gettimeofday : (tv : timeval#, tz : timezone#, abstime : uint64# -> int) /* extern const __osx_ptrace extern const __osx_signalstack @@ -988,7 +988,7 @@ const mmap = {addr, len, prot, flags, fd, off; -> (syscall(Sysmmap, a(addr), a(len), a(prot), a(flags), a(fd), a(off)) : byte#)} /* time */ -const gettimeofday = {tv, tz; -> (__osx_gettimeofday(tv, tz) : int)} +const gettimeofday = {tv, tz; -> (__osx_gettimeofday(tv, tz, (0 : uint64#)) : int)} const settimeofday = {tv, tz; -> (syscall(Syssettimeofday, a(tv), a(tz)) : int)} /* faked with gettimeofday */ diff --git a/lib/sys/sys+plan9-x64.myr b/lib/sys/sys+plan9-x64.myr index a42a0a2..c49bde1 100644 --- a/lib/sys/sys+plan9-x64.myr +++ b/lib/sys/sys+plan9-x64.myr @@ -27,8 +27,8 @@ pkg sys = const Maxerr : size = 128 - const Ordonly : fdopt = 0 - const Owronly : fdopt = 1 + const Oread : fdopt = 0 + const Owrite : fdopt = 1 const Ordwr : fdopt = 2 const Oexec : fdopt = 3 diff --git a/lib/sys/syscall+netbsd-x64.s b/lib/sys/syscall+netbsd-x64.s new file mode 100644 index 0000000..3b25573 --- /dev/null +++ b/lib/sys/syscall+netbsd-x64.s @@ -0,0 +1,76 @@ +.globl sys$syscall +sys$syscall: + /* + hack: We load 6 args regardless of + how many we actually have. This may + load junk values, but if the syscall + doesn't use them, it's going to be + harmless. + */ + movq %rdi,%rax + /* 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 + /* + if there syscalls are more than 6 + args (eg, mmap), the remaining args + are on the stack, with 8 dummy bytes + for a return address. + */ + movq 64(%rsp),%rbx + pushq %rbx + pushq %rbx + + syscall + jae .success + negq %rax + +.success: + addq $16,%rsp + ret + +.globl sys$__netbsd_pipe +sys$__netbsd_pipe: + movq $0x2a,%rax + syscall + + jae .pipesuccess + negq %rax + +.pipesuccess: + movl %eax,(%rdi) + movl %edx,4(%rdi) + xorq %rax,%rax + ret + +/* __tfork_thread(tfp : tforkparams#, sz : size, fn : void#, arg : void#-> tid) */ +.globl sys$__tfork_thread +sys$__tfork_thread: + /* syscall */ + movq %rdx, %r8 + movq %rcx, %r9 + movq $8, %rax + syscall + jb .failparent + + /* are we in the parent? */ + cmpq $0,%rax + jnz .doneparent + + /* call the function and __threxit */ + movq %r9, %rdi + callq *%r8 + + movq $302,%rax + xorq %rdi,%rdi + syscall + +.failparent: + negq %rax + +.doneparent: + ret diff --git a/lib/sys/syscall+osx-x64.s b/lib/sys/syscall+osx-x64.s index 5984c24..2618413 100644 --- a/lib/sys/syscall+osx-x64.s +++ b/lib/sys/syscall+osx-x64.s @@ -87,10 +87,15 @@ _sys$__osx_gettimeofday: jae .gettimeofdaysuccess negq %rax + ret .gettimeofdaysuccess: - movq %rax, (%rdi) + cmpq $0,%rax + je .noreg + + movq %rax,0(%rdi) movl %edx,8(%rdi) xorq %rax,%rax +.noreg: ret diff --git a/lib/sys/syserrno+netbsd.myr b/lib/sys/syserrno+netbsd.myr new file mode 100644 index 0000000..e48f893 --- /dev/null +++ b/lib/sys/syserrno+netbsd.myr @@ -0,0 +1,123 @@ +pkg sys = + type errno = int + + const Eperm : errno = -1 /* Operation not permitted */ + const Enoent : errno = -2 /* No such file or directory */ + const Esrch : errno = -3 /* No such process */ + const Eintr : errno = -4 /* Interrupted system call */ + const Eio : errno = -5 /* Input/output error */ + const Enxio : errno = -6 /* Device not configured */ + const E2big : errno = -7 /* Argument list too long */ + const Enoexec : errno = -8 /* Exec format error */ + const Ebadf : errno = -9 /* Bad file descriptor */ + const Echild : errno = -10 /* No child processes */ + const Edeadlk : errno = -11 /* Resource deadlock avoided */ + /* 11 was EAGAIN */ + const Enomem : errno = -12 /* Cannot allocate memory */ + const Eacces : errno = -13 /* Permission denied */ + const Efault : errno = -14 /* Bad address */ + const Enotblk : errno = -15 /* Block device required */ + const Ebusy : errno = -16 /* Device busy */ + const Eexist : errno = -17 /* File exists */ + const Exdev : errno = -18 /* Cross-device link */ + const Enodev : errno = -19 /* Operation not supported by device */ + const Enotdir : errno = -20 /* Not a directory */ + const Eisdir : errno = -21 /* Is a directory */ + const Einval : errno = -22 /* Invalid argument */ + const Enfile : errno = -23 /* Too many open files in system */ + const Emfile : errno = -24 /* Too many open files */ + const Enotty : errno = -25 /* Inappropriate ioctl for device */ + const Etxtbsy : errno = -26 /* Text file busy */ + const Efbig : errno = -27 /* File too large */ + const Enospc : errno = -28 /* No space left on device */ + const Espipe : errno = -29 /* Illegal seek */ + const Erofs : errno = -30 /* Read-only filesystem */ + const Emlink : errno = -31 /* Too many links */ + const Epipe : errno = -32 /* Broken pipe */ + + /* math software */ + const Edom : errno = -33 /* Numerical argument out of domain */ + const Erange : errno = -34 /* Result too large */ + + /* non-blocking and interrupt i/o */ + const Eagain : errno = -35 /* Resource temporarily unavailable */ + const Einprogress : errno = -36 /* Operation now in progress */ + const Ealready : errno = -37 /* Operation already in progress */ + + /* ipc/network software -- argument errors */ + const Enotsock : errno = -38 /* Socket operation on non-socket */ + const Edestaddrreq : errno = -39 /* Destination address required */ + const Emsgsize : errno = -40 /* Message too long */ + const Eprototype : errno = -41 /* Protocol wrong type for socket */ + const Enoprotoopt : errno = -42 /* Protocol not available */ + const Eprotonosupport : errno = -43 /* Protocol not supported */ + const Esocktnosupport : errno = -44 /* Socket type not supported */ + const Eopnotsupp : errno = -45 /* Operation not supported */ + const Epfnosupport : errno = -46 /* Protocol family not supported */ + const Eafnosupport : errno = -47 /* Address family not supported by protocol family */ + const Eaddrinuse : errno = -48 /* Address already in use */ + const Eaddrnotavail : errno = -49 /* Can't assign requested address */ + + /* ipc/network software -- operational errors */ + const Enetdown : errno = -50 /* Network is down */ + const Enetunreach : errno = -51 /* Network is unreachable */ + const Enetreset : errno = -52 /* Network dropped connection on reset */ + const Econnaborted : errno = -53 /* Software caused connection abort */ + const Econnreset : errno = -54 /* Connection reset by peer */ + const Enobufs : errno = -55 /* No buffer space available */ + const Eisconn : errno = -56 /* Socket is already connected */ + const Enotconn : errno = -57 /* Socket is not connected */ + const Eshutdown : errno = -58 /* Can't send after socket shutdown */ + const Etoomanyrefs : errno = -59 /* Too many references: can't splice */ + const Etimedout : errno = -60 /* Operation timed out */ + const Econnrefused : errno = -61 /* Connection refused */ + + const Eloop : errno = -62 /* Too many levels of symbolic links */ + const Enametoolong : errno = -63 /* File name too long */ + + /* should be rearranged */ + const Ehostdown : errno = -64 /* Host is down */ + const Ehostunreach : errno = -65 /* No route to host */ + const Enotempty : errno = -66 /* Directory not empty */ + + /* quotas & mush */ + const Eproclim : errno = -67 /* Too many processes */ + const Eusers : errno = -68 /* Too many users */ + const Edquot : errno = -69 /* Disc quota exceeded */ + + /* Network File System */ + const Estale : errno = -70 /* Stale NFS file handle */ + const Eremote : errno = -71 /* Too many levels of remote in path */ + const Ebadrpc : errno = -72 /* RPC struct is bad */ + const Erpcmismatch : errno = -73 /* RPC version wrong */ + const Eprogunavail : errno = -74 /* RPC prog. not avail */ + const Eprogmismatch : errno = -75 /* Program version wrong */ + const Eprocunavail : errno = -76 /* Bad procedure for program */ + + const Enolck : errno = -77 /* No locks available */ + const Enosys : errno = -78 /* Function not implemented */ + + const Eftype : errno = -79 /* Inappropriate file type or format */ + const Eauth : errno = -80 /* Authentication error */ + const Eneedauth : errno = -81 /* Need authenticator */ + const Eidrm : errno = -82 /* Identifier removed */ + const Enomsg : errno = -83 /* No message of desired type */ + const Eoverflow : errno = -84 /* Value too large to be stored in data type */ + const Ecanceled : errno = -85 /* Operation canceled */ + const Eilseq : errno = -86 /* Illegal byte sequence */ + const Enoattr : errno = -87 /* Attribute not found */ + + const Edoofus : errno = -88 /* Programming error */ + + const Ebadmsg : errno = -89 /* Bad message */ + const Emultihop : errno = -90 /* Multihop attempted */ + const Enolink : errno = -91 /* Link has been severed */ + const Eproto : errno = -92 /* Protocol error */ + + const Enotcapable : errno = -93 /* Capabilities insufficient */ + const Ecapmode : errno = -94 /* Not permitted in capability mode */ + const Enotrecoverable : errno = -95 /* State not recoverable */ + const Eownerdead : errno = -96 /* Previous owner died */ + + const Elast : errno = -96 /* Must be equal largest errno */ +;; diff --git a/lib/testr/testr.myr b/lib/testr/testr.myr index 22a271c..19cdad6 100644 --- a/lib/testr/testr.myr +++ b/lib/testr/testr.myr @@ -13,6 +13,7 @@ pkg testr = ;; const run : (specs : spec[:] -> void) + const bench : (specs : spec[:] -> void) const ok : (ctx : ctx# -> void) const fail : (ctx : ctx#, msg : byte[:], args : ... -> void) const check : (ctx : ctx#, cond : bool, msg : byte[:], args : ... -> void) @@ -20,10 +21,17 @@ pkg testr = const softfail : (ctx : ctx#, msg : byte[:], args : ... -> void) ;; +const bench = {specs + std.put("MTEST {}\n", specs.len) + for s : specs + benchspec(&s) + ;; +} + const run = {specs std.put("MTEST {}\n", specs.len) for s : specs - runspec(&s) + testspec(&s) ;; } @@ -60,13 +68,62 @@ const softfail = {ctx, msg, args } const softfailv = {ctx, msg, ap - ctx.ok = false - ctx.reason = std.fmtv(msg, ap) + /* keep the first failure */ + if ctx.ok + ctx.ok = false + ctx.reason = std.fmtv(msg, ap) + ;; +} + +const benchspec = {ts + var avg, m, d, n, nsamp + var start, dt + var ctx : ctx + var jmpbuf + + ctx.ok = true + ctx.reason = "" + ctx.jmpbuf = &jmpbuf + + avg = 0.0; + m = 0.0; + n = 0.0; + nsamp = 0 + std.put("test {} <<{{!\n", ts.name) + if !std.setjmp(&jmpbuf) + /* estimate samples */ + start = std.now() + ts.fn(&ctx) + dt = (std.now() - start : flt64) + + if dt == 0.0 + nsamp = 1000_000 + else + nsamp = (100_000.0/dt : int64) + nsamp = std.max(10, nsamp) + ;; + + for var i = 0; i < nsamp; i++ + n +=1.0; + start = std.now() + ts.fn(&ctx) + dt = (std.now() - start : flt64)/1_000_000.0 + d = (dt - avg); + avg = avg + d/n; + m = m + d*(dt - avg); + ;; + ;; + + if ctx.ok + std.put("!}}>> timing {} {} {}\n", nsamp, avg, m) + else + std.put("!}}>> fail {}\n", ctx.reason) + std.slfree(ctx.reason) + ;; } -const runspec = {ts +const testspec = {ts var ctx : ctx - var status, reason var jmpbuf ctx.ok = true @@ -79,12 +136,9 @@ const runspec = {ts ;; if ctx.ok - status = "ok" - reason = "" + std.put("!}}>> ok\n") else - status = "fail" - reason = ctx.reason + std.put("!}}>> fail {}\n", ctx.reason) + std.slfree(ctx.reason) ;; - std.put("!}}>> {} {}\n", status, reason) - std.slfree(reason) } diff --git a/lib/thread/bld.sub b/lib/thread/bld.sub index 02e5e50..f386162 100644 --- a/lib/thread/bld.sub +++ b/lib/thread/bld.sub @@ -8,16 +8,17 @@ lib thread = # linux impl of basic thread primitives #condvar+linux.myr + exit+linux-x64.s mutex+linux.myr + ncpu+linux.myr spawn+linux.myr - exit+linux-x64.s # freebsd impl of thread primitives #condvar+freebsd.myr + exit+freebsd-x64.s mutex+freebsd.myr - spawn+freebsd.myr ncpu+freebsd.myr - exit+freebsd-x64.s + spawn+freebsd.myr # netbsd impl of thread primitives #condvar+netbsd.myr @@ -33,14 +34,16 @@ lib thread = # 9front impl of thread primitives #condvar+plan9.myr + atomic-impl+plan9-x64.s mutex+plan9.myr - spawn+plan9.myr ncpu+plan9.myr - atomic-impl+plan9-x64.s + spawn+plan9.myr # openbsd impl of thread primitives - spawn+openbsd.myr exit+openbsd-x64.s + mutex+openbsd:6.2.myr + ncpu+openbsd.myr + spawn+openbsd.myr atomic-impl+x64.s atomic.myr diff --git a/lib/thread/mutex+openbsd:6.2.myr b/lib/thread/mutex+openbsd:6.2.myr new file mode 100644 index 0000000..f2648f5 --- /dev/null +++ b/lib/thread/mutex+openbsd:6.2.myr @@ -0,0 +1,76 @@ +use std +use sys + +use "atomic" +use "common" + +pkg thread = + type mutex = struct + _state : uint32 + ;; + + const mkmtx : (-> mutex) + const mtxlock : (mtx : mutex# -> void) + const mtxtrylock : (mtx : mutex# -> bool) + const mtxunlock : (mtx : mutex# -> void) + + pkglocal const Unlocked : uint32 = 0 + pkglocal const Locked : uint32 = 1 + pkglocal const Contended : uint32 = 2 +;; + +var nspin = 10 /* FIXME: pick a sane number, based on CPU count */ + +const mkmtx = { + -> [._state = Unlocked] +} + +const mtxlock = {mtx + var c + + /* + Uncontended case: we get an unlocked mutex, and we lock it. + */ + c = Locked + for var i = 0; i < nspin; i++ + c = xcas(&mtx._state, Unlocked, Locked) + if c == Unlocked + -> void + ;; + ;; + + /* + Contended case: we set the lock state to Contended. This indicates that there + the lock is locked, and we potentially have threads waiting on it, which means + that we will need to wake them up. + */ + if c == Locked + c = xchg(&mtx._state, Contended) + ;; + + while c != Unlocked + sys.futex(&mtx._state, sys.Futexwait, (Contended : int), Zptr, Zptr) + c = xchg(&mtx._state, Contended) + ;; +} + +const mtxtrylock = {mtx + -> xcas(&mtx._state, Unlocked, Locked) == Unlocked +} + +const mtxunlock = {mtx + /* + Uncontended case: If the mutex state is not contended, and we still + are uncontended by the xchg() call, then it's safe to simply return; + nobody was waiting for us. + */ + if mtx._state == Contended + mtx._state = Unlocked + elif xchg(&mtx._state, Unlocked) == Locked + -> void + ;; + + /* wake one thread */ + sys.futex(&mtx._state, sys.Futexwake, 1, Zptr, Zptr) +} + diff --git a/lib/thread/ncpu+linux.myr b/lib/thread/ncpu+linux.myr new file mode 100644 index 0000000..5c2ea15 --- /dev/null +++ b/lib/thread/ncpu+linux.myr @@ -0,0 +1,30 @@ +use std +use sys + +pkg thread = + const ncpu : (-> int) +;; + +const ncpu = { + var cpubuf : uint64[4] + var n + + sys.sched_getaffinity(sys.getpid(), sizeof(uint64[4]), (&cpubuf : uint64#)) + n = 0 + for b : cpubuf[:] + if b != 0 + n += count(b) + ;; + ;; + -> n +} + +const count = {b + var n = 0 + for var i = 0; i < 8*sizeof(uint64); i++ + if b & (1<<i) != 0 + n++ + ;; + ;; + -> n +} diff --git a/lib/thread/ncpu+openbsd.myr b/lib/thread/ncpu+openbsd.myr new file mode 100644 index 0000000..1aa3dc1 --- /dev/null +++ b/lib/thread/ncpu+openbsd.myr @@ -0,0 +1,23 @@ +use std +use sys + +pkg thread = + const ncpu : (-> int) +;; + +const ncpu = { + var mib : int[2] + var ncpu : int + var ncpusz + var res + + mib[0] = 6 /* CTL_HW */ + mib[1] = 3 /* HW_NCPU */ + ncpusz = sizeof(int) + + res = sys.sysctl(mib[:], (&ncpu : void#), &ncpusz, (0 : void#), (0 : sys.size#)) + if res < 0 || ncpu <= 0 + -> 1 + ;; + -> ncpu +} diff --git a/lib/thread/ncpu+plan9.myr b/lib/thread/ncpu+plan9.myr index 25d09cb..a13725c 100644 --- a/lib/thread/ncpu+plan9.myr +++ b/lib/thread/ncpu+plan9.myr @@ -5,7 +5,7 @@ pkg thread = ;; const ncpu = { - match std.intparse(std.getenvv("NPROC", "")) + match std.intparse(std.getenvv("NPROC", "1")) | `std.Some n: -> n | `std.None: -> 1 ;; diff --git a/lib/thread/spawn+osx.myr b/lib/thread/spawn+osx.myr index bedaa42..4e99598 100644 --- a/lib/thread/spawn+osx.myr +++ b/lib/thread/spawn+osx.myr @@ -34,15 +34,41 @@ const spawn = {fn } const spawnstk = {fn, sz - var tid : tid, ret + var stk : byte#, tid, ret + var szp, f, tos, env, envsz + stk = getstk(sz) + if stk == sys.Mapbad + -> `std.Err "couldn't get stack" + ;; + tid = -1 + + /* find top of stack */ + tos = (stk : std.intptr) + (sz : std.intptr) + + /* store the stack size */ + tos -= sizeof(sys.size) + sz -= sizeof(sys.size) + szp = (tos : sys.size#) + szp# = Stacksz + + /* store the function we call */ + envsz = std.fnenvsz(fn) + tos -= (envsz : std.intptr) + sz -= (envsz : sys.size) + env = tos + tos -= sizeof((->void)) + sz -= sizeof((->void)) + f = (tos : (->void)#) + f# = std.fnbdup(fn, (env : byte#)[:envsz]) + var repr = (&fn : int64[2]#)# ret = sys.bsdthread_create( \ - (fn : void#), \ - envptr(&fn), \ - (sz : void#), \ - (0 : void#), \ - 0) + (tramp : void#), \ /* start */ + (tos : void#), \ /* arg */ + (tos : void#), \ /* stack */ + (0 : void#), \ /* pthread struct */ + 0x01000000) /* flags (PTHREAD_START_CUSTOM): don't alloc stack in kernel */ if ret == (-1 : void#) -> `std.Err "couldn't spawn thread" @@ -50,10 +76,24 @@ const spawnstk = {fn, sz -> `std.Ok (ret : tid) } -const envptr = {fn - var repr : std.intptr[2] +const getstk = {sz + var p, m - repr = (fn : std.intptr[2]#)# - -> (repr[0] : void#) + std.put("allocating stack {x}\n", sz) + p = sys.mmap((0 : byte#), sz, sys.Mprotrw, sys.Mpriv | sys.Manon, -1, 0) + if p == sys.Mapbad + -> p + ;; + m = (p : std.intptr) + -> (m : byte#) } +/* + thread trampoline, called by `start`. We set up the args + for the closure and env on the stack, and then we call it + from here, doing the cleanup and exit at the end. +*/ +const tramp = {f : (-> void)# + f#() + exit() +} diff --git a/lib/thread/start+osx-x64.s b/lib/thread/start+osx-x64.s index bc62d08..bb497bb 100644 --- a/lib/thread/start+osx-x64.s +++ b/lib/thread/start+osx-x64.s @@ -1,22 +1,41 @@ -// The entry point for thread start, registered with bsdthread_register -// %rdi: pthread (0, for us) -// %rsi: mach thread port (ignored) -// %rdx: func -// %rcx: env -// %r8: stack -// %r9: flags (= 0) -// %rsp: stack - C_64_REDZONE_LEN (= stack - 128) +# The entry point for thread start, registered with bsdthread_register +# %rdi: pthread (0, for us) +# %rsi: mach thread port (ignored) +# %rdx: func +# %rcx: env +# %r8: stack +# %r9: flags (= 0) +# %rsp: stack - C_64_REDZONE_LEN (= stack - 128) .globl _thread$start _thread$start: /* call the function */ -# movq %r8, %rsp /* set up stack */ - movq %rcx, %rax /* set up env */ + movq %r8, %rsp /* set up stack */ + movq %rcx,%rdi callq *%rdx /* call function */ + +/* +const thread.exit : (stacksz : std.size -> void) +NOTE: must be called from the bottom of the stack, since +we assume that %rbp is in the top 4k of the stack. +*/ +.globl _thread$exit +_thread$exit: + /* find top of stack */ + movq %rbp,%rdi /* addr */ + andq $~0xfff,%rdi /* align it */ + addq $0x1000,%rdi + + /* munmap(base, size) */ + movq $0x2000049,%rax /* munmap */ + movq -8(%rdi),%rsi /* size */ + subq %rsi,%rdi /* move to base ptr */ + syscall /* exit the thread */ movq $0x2000169, %rax /* Sysbsdthread_terminate */ - movq %rsp, %rdi /* stack */ + movq $0, %rdi /* stack */ movq $0, %rsi /* len */ movq $0, %rdx /* sem */ syscall + diff --git a/lib/thread/test/mutex.myr b/lib/thread/test/mutex.myr index eb15a5e..fd58df1 100644 --- a/lib/thread/test/mutex.myr +++ b/lib/thread/test/mutex.myr @@ -27,7 +27,6 @@ const incvar = { for var i = 0; i < 1000; i++ thread.mtxlock(&mtx) val++ - std.put("val: {}\n", val) thread.mtxunlock(&mtx) ;; thread.xadd(&done, 1) |