diff options
author | Ori Bernstein <ori@eigenstate.org> | 2021-08-22 20:04:26 -0400 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2021-08-22 20:04:58 -0400 |
commit | 0f3f41fae775b2647cd0cdaf0a9ef395c19b9878 (patch) | |
tree | 90d554de9c36fe4849639413d2c857b2f8d60c7a | |
parent | ba1476058afaffc3f24ca8fbde11234def04d1bf (diff) | |
download | mc-0f3f41fae775b2647cd0cdaf0a9ef395c19b9878.tar.gz |
Add initial openbsd 7.0 support.
There's some ABI breakage and some futex work, but
it's a lot closer than it wast .
-rw-r--r-- | lib/sys/bld.sub | 1 | ||||
-rw-r--r-- | lib/sys/sys+openbsd:7.0-x64.myr (renamed from lib/sys/sys+openbsd:6.1-x64.myr) | 245 | ||||
-rw-r--r-- | support/syscall-gen/c2myr.py | 10 | ||||
-rwxr-xr-x | support/syscall-gen/gensys.sh | 4 | ||||
-rw-r--r-- | support/syscall-gen/specials+openbsd:7.0-x64.frag | 286 | ||||
-rw-r--r-- | support/syscall-gen/syscalls+openbsd:7.0.master | 568 | ||||
-rw-r--r-- | support/syscall-gen/types+openbsd:7.0-x64.frag | 488 |
7 files changed, 1473 insertions, 129 deletions
diff --git a/lib/sys/bld.sub b/lib/sys/bld.sub index ea0794a..68f9e30 100644 --- a/lib/sys/bld.sub +++ b/lib/sys/bld.sub @@ -13,6 +13,7 @@ lib sys = sys+openbsd:6.2-x64.myr sys+openbsd:6.3-x64.myr sys+openbsd:6.4-x64.myr + sys+openbsd:7.0-x64.myr syscall+freebsd-x64.s syscall+netbsd-x64.s diff --git a/lib/sys/sys+openbsd:6.1-x64.myr b/lib/sys/sys+openbsd:7.0-x64.myr index 9ac648a..3b24add 100644 --- a/lib/sys/sys+openbsd:6.1-x64.myr +++ b/lib/sys/sys+openbsd:7.0-x64.myr @@ -1,6 +1,6 @@ /* generated-ish source - stitched for openbsd:6.1 arch:x64 + stitched for openbsd:7.0 arch:x64 edit with caution. */ pkg sys = @@ -10,6 +10,9 @@ pkg sys = type intptr = uint64/* can hold any pointer losslessly */ type time = int64 /* milliseconds since epoch */ type pid = int32 /* process id */ + type uid = int32 /* user id */ + type key = int32 /* sysv ipc key */ + type id = int32 /* id */ type scno = int64 /*syscall*/ type fdopt = int64 /* fd options */ type fd = int32 /* fd */ @@ -26,7 +29,15 @@ pkg sys = type signo = int32 type sigflags = int32 type sigset = uint32 + type clockid = uint32 type msg = void + type msqid_ds = void + type gid = uint32 + + const Futexwait : int = 1 + const Futexwake : int = 2 + const Futexrequeue : int = 3 + type clock = union `Clockrealtime @@ -43,6 +54,11 @@ pkg sys = `Waitstop int32 ;; + type rlimit = struct + cur : uint64 /* current (soft) limit */ + max : uint64 /* maximum value for rlim_cur */ + ;; + type timespec = struct sec : int64 nsec : int64 @@ -53,6 +69,10 @@ pkg sys = usec : int64 ;; + type timezone = struct + minwest : int32 /* minutes west of Greenwich */ + dsttime : int32 /* type of dst correction */ + ;; type pollfd = struct fd : fd @@ -60,11 +80,82 @@ pkg sys = revents : uint16 ;; + type fsid = struct + val : int32[2] + ;; + + 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 @@ -272,7 +363,7 @@ pkg sys = const Mfixed : mopt = 0x10 const Mfile : mopt = 0x0 const Manon : mopt = 0x1000 - const Mstack : mopt = 0 + const Mstack : mopt = 0x4000 const Mnoreplace : mopt = 0x0800 /* file types */ @@ -402,14 +493,8 @@ pkg sys = 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 rlim = uint64 - type key = int64 type shmatt = int16 type tfork = struct @@ -430,11 +515,6 @@ pkg sys = ;; - type fsid = struct - val : int32[2] - - ;; - type fid = struct len : uint16 reserved : uint16 @@ -448,18 +528,6 @@ pkg sys = ;; - type timezone = struct - minuteswest : int - dsttime : int - - ;; - - type itimerval = struct - interval : timeval - value : timeval - - ;; - type fdset = struct bits : fd_mask[32] @@ -481,69 +549,6 @@ pkg sys = ;; - type fxsave64 = struct - fcw : uint16 - fsw : uint16 - ftw : uint8 - unused1 : uint8 - fop : uint16 - rip : uint64 - rdp : uint64 - mxcsr : uint32 - mxcsr_mask : uint32 - st : uint64[2][8] - xmm : uint64[2][16] - unused3 : uint8[96] - - ;; - - type sigcontext = struct - 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# - unused : int - mask : int - cookie : int64 - - ;; - - type rlimit = struct - cur : rlim - max : rlim - - ;; - - type sigaltstack = struct - sp : void# - size : size - flags : int - - ;; - type sembuf = struct num : uint16 op : int16 @@ -578,25 +583,6 @@ pkg sys = ;; - 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 Sysexit : scno = 1 const Sysfork : scno = 2 @@ -634,6 +620,7 @@ pkg sys = const Syschflags : scno = 34 const Sysfchflags : scno = 35 const Syssync : scno = 36 + const Sysmsyscall : scno = 37 const Sysstat : scno = 38 const Sysgetppid : scno = 39 const Syslstat : scno = 40 @@ -645,7 +632,6 @@ pkg sys = const Syssigaction : scno = 46 const Sysgetgid : scno = 47 const Syssigprocmask : scno = 48 - const Sysgetlogin59 : scno = 49 const Syssetlogin : scno = 50 const Sysacct : scno = 51 const Syssigpending : scno = 52 @@ -674,11 +660,11 @@ pkg sys = 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 @@ -708,6 +694,8 @@ pkg sys = const Syspselect : scno = 110 const Syssigsuspend : scno = 111 const Syssendsyslog : scno = 112 + const Sysunveil : scno = 114 + const Sys__realpath : scno = 115 const Sysgetsockopt : scno = 118 const Systhrkill : scno = 119 const Sysreadv : scno = 120 @@ -731,6 +719,7 @@ pkg sys = const Sysquotactl : scno = 148 const Sysnfssvc : scno = 155 const Sysgetfh : scno = 161 + const Sys__tmpfd : scno = 164 const Syssysarch : scno = 165 const Syspread : scno = 173 const Syspwrite : scno = 174 @@ -894,13 +883,13 @@ pkg sys = const chflags : (path : byte#, flags : uint -> int) const fchflags : (fd : int, flags : uint -> int) const sync : ( -> void) + const msyscall : (addr : void#, len : size -> int) 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 getlogin59 : (namebuf : byte#, namelen : uint -> int) const setlogin : (namebuf : byte# -> int) const acct : (path : byte# -> int) const sigpending : ( -> int) @@ -925,11 +914,11 @@ pkg sys = 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) @@ -942,11 +931,13 @@ pkg sys = 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 pledge : (promises : byte#, execpromises : 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 sendsyslog : (buf : byte#, nbyte : size, flags : int -> int) + const unveil : (path : byte#, permissions : byte# -> int) + const __realpath : (pathname : byte#, resolved : byte# -> 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) @@ -965,6 +956,7 @@ pkg sys = 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 __tmpfd : (flags : int -> int) const sysarch : (op : int, parms : void# -> int) const setgid : (gid : gid -> int) const setegid : (egid : gid -> int) @@ -1132,7 +1124,7 @@ pkg sys = 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(buf), a(buf.len)) : int64)} + 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)} @@ -1338,6 +1330,9 @@ const fchflags = {fd, flags const sync = { -> (syscall(Syssync) : void) } +const msyscall = {addr, len + -> (syscall(Sysmsyscall, a(addr), a(len)) : int) +} const getppid = { -> (syscall(Sysgetppid) : pid) } @@ -1356,9 +1351,6 @@ const ktrace = {fname, ops, facs, pid const getgid = { -> (syscall(Sysgetgid) : gid) } -const getlogin59 = {namebuf, namelen - -> (syscall(Sysgetlogin59, a(namebuf), a(namelen)) : int) -} const setlogin = {namebuf -> (syscall(Syssetlogin, a(namebuf)) : int) } @@ -1431,9 +1423,6 @@ const utimes = {path, tptr 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) } @@ -1446,6 +1435,9 @@ const getpgrp = { 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) } @@ -1482,8 +1474,8 @@ const sigreturn = {sigcntxp 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 pledge = {promises, execpromises + -> (syscall(Syspledge, a(promises), a(execpromises)) : int) } const ppoll = {fds, nfds, ts, mask -> (syscall(Sysppoll, a(fds), a(nfds), a(ts), a(mask)) : int) @@ -1497,6 +1489,12 @@ const sigsuspend = {mask const sendsyslog = {buf, nbyte, flags -> (syscall(Syssendsyslog, a(buf), a(nbyte), a(flags)) : int) } +const unveil = {path, permissions + -> (syscall(Sysunveil, a(path), a(permissions)) : int) +} +const __realpath = {pathname, resolved + -> (syscall(Sys__realpath, a(pathname), a(resolved)) : int) +} const thrkill = {tid, signum, tcb -> (syscall(Systhrkill, a(tid), a(signum), a(tcb)) : int) } @@ -1551,6 +1549,9 @@ const nfssvc = {flag, argp const getfh = {fname, fhp -> (syscall(Sysgetfh, a(fname), a(fhp)) : int) } +const __tmpfd = {flags + -> (syscall(Sys__tmpfd, a(flags)) : int) +} const sysarch = {op, parms -> (syscall(Syssysarch, a(op), a(parms)) : int) } diff --git a/support/syscall-gen/c2myr.py b/support/syscall-gen/c2myr.py index 9c262c5..0babd55 100644 --- a/support/syscall-gen/c2myr.py +++ b/support/syscall-gen/c2myr.py @@ -3,7 +3,7 @@ import re import os import traceback import pycparser -import StringIO +import io from pycparser import c_parser, c_ast from pycparser.plyparser import Coord #from pycparser import c_parser, c_ast, parse_file @@ -314,8 +314,8 @@ def myrtype(name, defname=None): return gen if __name__ == '__main__': - structs = StringIO.StringIO() - defs = StringIO.StringIO() + structs = io.StringIO() + defs = io.StringIO() prehdr = ''' #define __builtin_va_list int @@ -355,7 +355,7 @@ if __name__ == '__main__': if os.path.exists("/usr/include/x86_64-linux-gnu/sys"): syshdr = syshdr + ["linux/" + h for h in os.listdir("/usr/include/linux")] for hdr in syshdr: - print 'trying {}'.format(hdr) + print('trying {}'.format(hdr)) if not hdr.endswith(".h"): continue try: @@ -365,7 +365,7 @@ if __name__ == '__main__': pycparser.parse_file('/tmp/myr-includes.h', use_cpp=True) includes.append('#include <{}>'.format(hdr)) except Exception: - print '...skip' + print('...skip') print('importing' + ' '.join(includes)) with open('/tmp/myr-includes.h', 'w') as f: diff --git a/support/syscall-gen/gensys.sh b/support/syscall-gen/gensys.sh index 51415a4..7e508f3 100755 --- a/support/syscall-gen/gensys.sh +++ b/support/syscall-gen/gensys.sh @@ -42,10 +42,10 @@ touch have.txt if [ `uname` = Linux ]; then hdrgen $1 $2 - python ./c2myr.py $1 $2 + python3 ./c2myr.py $1 $2 hdrgen $1 $2 else mastergen $1 $2 - python ./c2myr.py $1 $2 + python3 ./c2myr.py $1 $2 mastergen $1 $2 fi diff --git a/support/syscall-gen/specials+openbsd:7.0-x64.frag b/support/syscall-gen/specials+openbsd:7.0-x64.frag new file mode 100644 index 0000000..b326ec1 --- /dev/null +++ b/support/syscall-gen/specials+openbsd:7.0-x64.frag @@ -0,0 +1,286 @@ +/* process control */ +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) +/* wrappers to extract wait status */ +const waitstatus : (st : int32 -> waitstatus) +extern const __tfork_thread : (tfp : tforkparams#, sz : size, fn : void#, arg : void# -> pid) + +/* fd manipulation */ +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) + +/* signals */ +const sigaction : (sig : signo, act : sigaction#, oact : sigaction# -> int) +const sigprocmask : (how : int32, set : sigset#, oset : sigset# -> int) + +/* fd stuff */ +const pipe : (fds : fd[2]# -> int64) +const dup : (fd : fd -> fd) +const dup2 : (src : fd, dst : fd -> fd) +/* NB: the C ABI uses '...' for the args. */ +const fcntl : (fd : fd, cmd : fcntlcmd, args : byte# -> int64) + +/* networking */ +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) + +/* memory mapping */ +const munmap : (addr:byte#, len:size -> int64) +const mmap : (addr:byte#, len:size, prot:mprot, flags:mopt, fd:fd, off:off -> byte#) + +/* time - doublecheck if this is right */ +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) + +/* system information */ +const uname : (buf : utsname# -> int) +const sysctl : (mib : int[:], \ + old : void#, oldsz : size#, \ + new : void#, newsz : size# \ + -> int) + +/* +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)} + +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))} +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 : int64), .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 + ;; +} + diff --git a/support/syscall-gen/syscalls+openbsd:7.0.master b/support/syscall-gen/syscalls+openbsd:7.0.master new file mode 100644 index 0000000..3580d86 --- /dev/null +++ b/support/syscall-gen/syscalls+openbsd:7.0.master @@ -0,0 +1,568 @@ +; $OpenBSD: syscalls.master,v 1.218 2021/06/04 09:05:19 mvs Exp $ +; $NetBSD: syscalls.master,v 1.32 1996/04/23 10:24:21 mycroft Exp $ + +; @(#)syscalls.master 8.2 (Berkeley) 1/13/94 + +; OpenBSD system call name/number "master" file. +; (See syscalls.conf to see what it is processed into.) +; +; Fields: number type [type-dependent ...] +; number system call number, must be in order +; type one of the types described below, or one of the +; compatibility options defined in syscalls.conf +; +; types: +; INDIR included, but don't define the syscall args structure, +; and allow it to be "really" varargs +; NOARGS included, but don't define the syscall args structure +; NODEF included, but don't define the syscall number +; NOLOCK don't acquire the kernel lock when calling this syscall +; OBSOL obsolete, not included in system +; STD always included +; UNIMPL unimplemented, not included in system +; +; The compat options are defined in the syscalls.conf file, and the +; compat option name is prefixed to the syscall name. Other than +; that, they're like NODEF (for 'compat' options), or STD (for +; 'libcompat' options). +; +; The type-dependent arguments are as follows: +; For STD, NODEF, NOARGS, and compat syscalls: +; { pseudo-proto } [alias] +; For other syscalls: +; [comment] +; +; #ifdef's, etc. may be included, and are copied to the output files. +; #include's are copied to the syscall switch definition file only. + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/signal.h> +#include <sys/mount.h> +#include <sys/syscallargs.h> +#include <sys/poll.h> + +; Reserved/unimplemented system calls in the range 0-150 inclusive +; are reserved for use in future Berkeley releases. +; Additional system calls implemented in vendor and other +; redistributions should be placed in the reserved range at the end +; of the current calls. + +0 INDIR { int sys_syscall(int number, ...); } +1 STD { void sys_exit(int rval); } +2 STD { int sys_fork(void); } +3 STD NOLOCK { ssize_t sys_read(int fd, void *buf, size_t nbyte); } +4 STD NOLOCK { ssize_t sys_write(int fd, const void *buf, \ + size_t nbyte); } +5 STD { int sys_open(const char *path, \ + int flags, ... mode_t mode); } +6 STD NOLOCK { int sys_close(int fd); } +7 STD NOLOCK { int sys_getentropy(void *buf, size_t nbyte); } +8 STD { int sys___tfork(const struct __tfork *param, \ + size_t psize); } +9 STD { int sys_link(const char *path, const char *link); } +10 STD { int sys_unlink(const char *path); } +11 STD { pid_t sys_wait4(pid_t pid, int *status, \ + int options, struct rusage *rusage); } +12 STD { int sys_chdir(const char *path); } +13 STD { int sys_fchdir(int fd); } +14 STD { int sys_mknod(const char *path, mode_t mode, \ + dev_t dev); } +15 STD { int sys_chmod(const char *path, mode_t mode); } +16 STD { int sys_chown(const char *path, uid_t uid, \ + gid_t gid); } +17 STD { int sys_obreak(char *nsize); } break +18 STD NOLOCK { int sys_getdtablecount(void); } +19 STD { int sys_getrusage(int who, \ + struct rusage *rusage); } +20 STD NOLOCK { pid_t sys_getpid(void); } +21 STD { int sys_mount(const char *type, const char *path, \ + int flags, void *data); } +22 STD { int sys_unmount(const char *path, int flags); } +23 STD { int sys_setuid(uid_t uid); } +24 STD NOLOCK { uid_t sys_getuid(void); } +25 STD NOLOCK { uid_t sys_geteuid(void); } +#ifdef PTRACE +26 STD { int sys_ptrace(int req, pid_t pid, caddr_t addr, \ + int data); } +#else +26 UNIMPL ptrace +#endif +27 STD NOLOCK { ssize_t sys_recvmsg(int s, struct msghdr *msg, \ + int flags); } +28 STD NOLOCK { ssize_t sys_sendmsg(int s, \ + const struct msghdr *msg, int flags); } +29 STD NOLOCK { ssize_t sys_recvfrom(int s, void *buf, size_t len, \ + int flags, struct sockaddr *from, \ + socklen_t *fromlenaddr); } +30 STD { int sys_accept(int s, struct sockaddr *name, \ + socklen_t *anamelen); } +31 STD { int sys_getpeername(int fdes, struct sockaddr *asa, \ + socklen_t *alen); } +32 STD { int sys_getsockname(int fdes, struct sockaddr *asa, \ + socklen_t *alen); } +33 STD { int sys_access(const char *path, int amode); } +34 STD { int sys_chflags(const char *path, u_int flags); } +35 STD { int sys_fchflags(int fd, u_int flags); } +36 STD { void sys_sync(void); } +37 STD { int sys_msyscall(void *addr, size_t len); } +38 STD { int sys_stat(const char *path, struct stat *ub); } +39 STD NOLOCK { pid_t sys_getppid(void); } +40 STD { int sys_lstat(const char *path, struct stat *ub); } +41 STD NOLOCK { int sys_dup(int fd); } +42 STD { int sys_fstatat(int fd, const char *path, \ + struct stat *buf, int flag); } +43 STD NOLOCK { gid_t sys_getegid(void); } +44 STD { int sys_profil(caddr_t samples, size_t size, \ + u_long offset, u_int scale); } +#ifdef KTRACE +45 STD { int sys_ktrace(const char *fname, int ops, \ + int facs, pid_t pid); } +#else +45 UNIMPL ktrace +#endif +46 STD { int sys_sigaction(int signum, \ + const struct sigaction *nsa, \ + struct sigaction *osa); } +47 STD NOLOCK { gid_t sys_getgid(void); } +48 STD NOLOCK { int sys_sigprocmask(int how, sigset_t mask); } +49 OBSOL ogetlogin +50 STD { int sys_setlogin(const char *namebuf); } +#ifdef ACCOUNTING +51 STD { int sys_acct(const char *path); } +#else +51 UNIMPL acct +#endif +52 STD { int sys_sigpending(void); } +53 STD { int sys_fstat(int fd, struct stat *sb); } +54 STD NOLOCK { int sys_ioctl(int fd, \ + u_long com, ... void *data); } +55 STD { int sys_reboot(int opt); } +56 STD { int sys_revoke(const char *path); } +57 STD { int sys_symlink(const char *path, \ + const char *link); } +58 STD { ssize_t sys_readlink(const char *path, \ + char *buf, size_t count); } +59 STD { int sys_execve(const char *path, \ + char * const *argp, char * const *envp); } +60 STD { mode_t sys_umask(mode_t newmask); } +61 STD { int sys_chroot(const char *path); } +62 STD { int sys_getfsstat(struct statfs *buf, size_t bufsize, \ + int flags); } +63 STD { int sys_statfs(const char *path, \ + struct statfs *buf); } +64 STD { int sys_fstatfs(int fd, struct statfs *buf); } +65 STD { int sys_fhstatfs(const fhandle_t *fhp, \ + struct statfs *buf); } +66 STD { int sys_vfork(void); } +67 STD NOLOCK { int sys_gettimeofday(struct timeval *tp, \ + struct timezone *tzp); } +68 STD NOLOCK { int sys_settimeofday(const struct timeval *tv, \ + const struct timezone *tzp); } +69 STD NOLOCK { int sys_setitimer(int which, \ + const struct itimerval *itv, \ + struct itimerval *oitv); } +70 STD NOLOCK { int sys_getitimer(int which, \ + struct itimerval *itv); } +71 STD { int sys_select(int nd, fd_set *in, fd_set *ou, \ + fd_set *ex, struct timeval *tv); } +72 STD { int sys_kevent(int fd, \ + const struct kevent *changelist, int nchanges, \ + struct kevent *eventlist, int nevents, \ + const struct timespec *timeout); } +73 STD { int sys_munmap(void *addr, size_t len); } +74 STD { int sys_mprotect(void *addr, size_t len, \ + int prot); } +75 STD { int sys_madvise(void *addr, size_t len, \ + int behav); } +76 STD { int sys_utimes(const char *path, \ + const struct timeval *tptr); } +77 STD { int sys_futimes(int fd, \ + const struct timeval *tptr); } +78 UNIMPL mincore +79 STD NOLOCK { int sys_getgroups(int gidsetsize, \ + gid_t *gidset); } +80 STD { int sys_setgroups(int gidsetsize, \ + const gid_t *gidset); } +81 STD { int sys_getpgrp(void); } +82 STD { int sys_setpgid(pid_t pid, pid_t pgid); } +83 STD NOLOCK { int sys_futex(uint32_t *f, int op, int val, \ + const struct timespec *timeout, uint32_t *g); } +84 STD { int sys_utimensat(int fd, const char *path, \ + const struct timespec *times, int flag); } +85 STD { int sys_futimens(int fd, \ + const struct timespec *times); } +86 STD { int sys_kbind(const struct __kbind *param, \ + size_t psize, int64_t proc_cookie); } +87 STD NOLOCK { int sys_clock_gettime(clockid_t clock_id, \ + struct timespec *tp); } +88 STD NOLOCK { int sys_clock_settime(clockid_t clock_id, \ + const struct timespec *tp); } +89 STD NOLOCK { int sys_clock_getres(clockid_t clock_id, \ + struct timespec *tp); } +90 STD NOLOCK { int sys_dup2(int from, int to); } +91 STD NOLOCK { int sys_nanosleep(const struct timespec *rqtp, \ + struct timespec *rmtp); } +92 STD NOLOCK { int sys_fcntl(int fd, int cmd, ... void *arg); } +93 STD { int sys_accept4(int s, struct sockaddr *name, \ + socklen_t *anamelen, int flags); } +94 STD NOLOCK { int sys___thrsleep(const volatile void *ident, \ + clockid_t clock_id, const struct timespec *tp, \ + void *lock, const int *abort); } +95 STD { int sys_fsync(int fd); } +96 STD { int sys_setpriority(int which, id_t who, int prio); } +97 STD NOLOCK { int sys_socket(int domain, int type, int protocol); } +98 STD NOLOCK { int sys_connect(int s, const struct sockaddr *name, \ + socklen_t namelen); } +99 STD { int sys_getdents(int fd, void *buf, size_t buflen); } +100 STD { int sys_getpriority(int which, id_t who); } +101 STD NOLOCK { int sys_pipe2(int *fdp, int flags); } +102 STD NOLOCK { int sys_dup3(int from, int to, int flags); } +103 STD { int sys_sigreturn(struct sigcontext *sigcntxp); } +104 STD { int sys_bind(int s, const struct sockaddr *name, \ + socklen_t namelen); } +105 STD { int sys_setsockopt(int s, int level, int name, \ + const void *val, socklen_t valsize); } +106 STD { int sys_listen(int s, int backlog); } +107 STD { int sys_chflagsat(int fd, const char *path, \ + u_int flags, int atflags); } +108 STD { int sys_pledge(const char *promises, \ + const char *execpromises); } +109 STD { int sys_ppoll(struct pollfd *fds, \ + u_int nfds, const struct timespec *ts, \ + const sigset_t *mask); } +110 STD { int sys_pselect(int nd, fd_set *in, fd_set *ou, \ + fd_set *ex, const struct timespec *ts, \ + const sigset_t *mask); } +111 STD { int sys_sigsuspend(int mask); } +112 STD NOLOCK { int sys_sendsyslog(const char *buf, size_t nbyte, \ + int flags); } +113 UNIMPL fktrace +114 STD { int sys_unveil(const char *path, \ + const char *permissions); } +115 STD { int sys___realpath(const char *pathname, \ + char *resolved); } +116 OBSOL t32_gettimeofday +117 OBSOL t32_getrusage +118 STD { int sys_getsockopt(int s, int level, int name, \ + void *val, socklen_t *avalsize); } +119 STD { int sys_thrkill(pid_t tid, int signum, void *tcb); } +120 STD NOLOCK { ssize_t sys_readv(int fd, \ + const struct iovec *iovp, int iovcnt); } +121 STD NOLOCK { ssize_t sys_writev(int fd, \ + const struct iovec *iovp, int iovcnt); } +122 STD { int sys_kill(int pid, int signum); } +123 STD { int sys_fchown(int fd, uid_t uid, gid_t gid); } +124 STD { int sys_fchmod(int fd, mode_t mode); } +125 OBSOL orecvfrom +126 STD { int sys_setreuid(uid_t ruid, uid_t euid); } +127 STD { int sys_setregid(gid_t rgid, gid_t egid); } +128 STD { int sys_rename(const char *from, const char *to); } +129 OBSOL otruncate +130 OBSOL oftruncate +131 STD NOLOCK { int sys_flock(int fd, int how); } +132 STD { int sys_mkfifo(const char *path, mode_t mode); } +133 STD NOLOCK { ssize_t sys_sendto(int s, const void *buf, \ + size_t len, int flags, const struct sockaddr *to, \ + socklen_t tolen); } +134 STD { int sys_shutdown(int s, int how); } +135 STD NOLOCK { int sys_socketpair(int domain, int type, \ + int protocol, int *rsv); } +136 STD { int sys_mkdir(const char *path, mode_t mode); } +137 STD { int sys_rmdir(const char *path); } +138 OBSOL t32_utimes +139 OBSOL 4.2 sigreturn +140 STD NOLOCK { int sys_adjtime(const struct timeval *delta, \ + struct timeval *olddelta); } +141 STD { int sys_getlogin_r(char *namebuf, u_int namelen); } +142 OBSOL ogethostid +143 OBSOL osethostid +144 OBSOL ogetrlimit +145 OBSOL osetrlimit +146 OBSOL okillpg +147 STD { int sys_setsid(void); } +148 STD { int sys_quotactl(const char *path, int cmd, \ + int uid, char *arg); } +149 OBSOL oquota +150 OBSOL ogetsockname + +; Syscalls 151-180 inclusive are reserved for vendor-specific +; system calls. (This includes various calls added for compatibility +; with other Unix variants.) +; Some of these calls are now supported by BSD... +151 UNIMPL +152 UNIMPL +153 UNIMPL +154 UNIMPL +#if defined(NFSCLIENT) || defined(NFSSERVER) +155 STD { int sys_nfssvc(int flag, void *argp); } +#else +155 UNIMPL +#endif +156 OBSOL ogetdirentries +157 OBSOL statfs25 +158 OBSOL fstatfs25 +159 UNIMPL +160 UNIMPL +161 STD { int sys_getfh(const char *fname, fhandle_t *fhp); } +162 OBSOL ogetdomainname +163 OBSOL osetdomainname +164 STD { int sys___tmpfd(int flags); } +165 STD { int sys_sysarch(int op, void *parms); } +166 UNIMPL +167 UNIMPL +168 UNIMPL +169 OBSOL semsys10 +170 OBSOL msgsys10 +171 OBSOL shmsys10 +172 UNIMPL +173 STD NOLOCK { ssize_t sys_pread(int fd, void *buf, \ + size_t nbyte, int pad, off_t offset); } +174 STD NOLOCK { ssize_t sys_pwrite(int fd, const void *buf, \ + size_t nbyte, int pad, off_t offset); } +175 UNIMPL ntp_gettime +176 UNIMPL ntp_adjtime +177 UNIMPL +178 UNIMPL +179 UNIMPL +180 UNIMPL + +; Syscalls 181-199 are used by/reserved for BSD +181 STD { int sys_setgid(gid_t gid); } +182 STD { int sys_setegid(gid_t egid); } +183 STD { int sys_seteuid(uid_t euid); } +184 OBSOL lfs_bmapv +185 OBSOL lfs_markv +186 OBSOL lfs_segclean +187 OBSOL lfs_segwait +188 OBSOL stat35 +189 OBSOL fstat35 +190 OBSOL lstat35 +191 STD { long sys_pathconf(const char *path, int name); } +192 STD { long sys_fpathconf(int fd, int name); } +193 STD { int sys_swapctl(int cmd, const void *arg, int misc); } +194 STD NOLOCK { int sys_getrlimit(int which, \ + struct rlimit *rlp); } +195 STD NOLOCK { int sys_setrlimit(int which, \ + const struct rlimit *rlp); } +196 OBSOL ogetdirentries48 +197 STD { void *sys_mmap(void *addr, size_t len, int prot, \ + int flags, int fd, long pad, off_t pos); } +198 INDIR { quad_t sys___syscall(quad_t num, ...); } +199 STD NOLOCK { off_t sys_lseek(int fd, int pad, off_t offset, \ + int whence); } +200 STD { int sys_truncate(const char *path, int pad, \ + off_t length); } +201 STD { int sys_ftruncate(int fd, int pad, off_t length); } +202 STD { int sys_sysctl(const int *name, u_int namelen, \ + void *old, size_t *oldlenp, void *new, \ + size_t newlen); } +203 STD { int sys_mlock(const void *addr, size_t len); } +204 STD { int sys_munlock(const void *addr, size_t len); } +205 UNIMPL sys_undelete +206 OBSOL t32_futimes +207 STD { pid_t sys_getpgid(pid_t pid); } +208 OBSOL nnpfspioctl +209 STD { int sys_utrace(const char *label, const void *addr, \ + size_t len); } +; +; Syscalls 210-219 were reserved for dynamically loaded syscalls +; +210 UNIMPL +211 UNIMPL +212 UNIMPL +213 UNIMPL +214 UNIMPL +215 UNIMPL +216 UNIMPL +217 UNIMPL +218 UNIMPL +219 UNIMPL +; System calls 220-240 are reserved for use by OpenBSD +#ifdef SYSVSEM +220 UNIMPL +221 STD { int sys_semget(key_t key, int nsems, int semflg); } +#else +220 UNIMPL semctl +221 UNIMPL semget +#endif +222 OBSOL semop35 +223 OBSOL semconfig35 +#ifdef SYSVMSG +224 UNIMPL +225 STD { int sys_msgget(key_t key, int msgflg); } +226 STD { int sys_msgsnd(int msqid, const void *msgp, size_t msgsz, \ + int msgflg); } +227 STD { int sys_msgrcv(int msqid, void *msgp, size_t msgsz, \ + long msgtyp, int msgflg); } +#else +224 UNIMPL msgctl +225 UNIMPL msgget +226 UNIMPL msgsnd +227 UNIMPL msgrcv +#endif +#ifdef SYSVSHM +228 STD { void *sys_shmat(int shmid, const void *shmaddr, \ + int shmflg); } +229 UNIMPL +230 STD { int sys_shmdt(const void *shmaddr); } +#else +228 UNIMPL shmat +229 UNIMPL shmctl +230 UNIMPL shmdt +#endif +231 OBSOL shmget35 +232 OBSOL t32_clock_gettime +233 OBSOL t32_clock_settime +234 OBSOL t32_clock_getres +235 UNIMPL timer_create +236 UNIMPL timer_delete +237 UNIMPL timer_settime +238 UNIMPL timer_gettime +239 UNIMPL timer_getoverrun +; +; System calls 240-249 are reserved for other IEEE Std1003.1b syscalls +; +240 OBSOL t32_nanosleep +241 UNIMPL +242 UNIMPL +243 UNIMPL +244 UNIMPL +245 UNIMPL +246 UNIMPL +247 UNIMPL +248 UNIMPL +249 UNIMPL +250 STD { int sys_minherit(void *addr, size_t len, \ + int inherit); } +251 OBSOL rfork +252 STD { int sys_poll(struct pollfd *fds, \ + u_int nfds, int timeout); } +253 STD NOLOCK { int sys_issetugid(void); } +254 STD { int sys_lchown(const char *path, uid_t uid, gid_t gid); } +255 STD { pid_t sys_getsid(pid_t pid); } +256 STD { int sys_msync(void *addr, size_t len, int flags); } +257 OBSOL semctl35 +258 OBSOL shmctl35 +259 OBSOL msgctl35 +260 UNIMPL +261 UNIMPL +262 UNIMPL +263 STD NOLOCK { int sys_pipe(int *fdp); } +264 STD { int sys_fhopen(const fhandle_t *fhp, int flags); } +265 UNIMPL +266 UNIMPL +267 STD NOLOCK { ssize_t sys_preadv(int fd, \ + const struct iovec *iovp, int iovcnt, \ + int pad, off_t offset); } +268 STD NOLOCK { ssize_t sys_pwritev(int fd, \ + const struct iovec *iovp, int iovcnt, \ + int pad, off_t offset); } +269 STD NOLOCK { int sys_kqueue(void); } +270 OBSOL t32_kevent +271 STD { int sys_mlockall(int flags); } +272 STD { int sys_munlockall(void); } +273 UNIMPL sys_getpeereid +274 UNIMPL sys_extattrctl +275 UNIMPL sys_extattr_set_file +276 UNIMPL sys_extattr_get_file +277 UNIMPL sys_extattr_delete_file +278 UNIMPL sys_extattr_set_fd +279 UNIMPL sys_extattr_get_fd +280 UNIMPL sys_extattr_delete_fd +281 STD NOLOCK { int sys_getresuid(uid_t *ruid, uid_t *euid, \ + uid_t *suid); } +282 STD { int sys_setresuid(uid_t ruid, uid_t euid, \ + uid_t suid); } +283 STD NOLOCK { int sys_getresgid(gid_t *rgid, gid_t *egid, \ + gid_t *sgid); } +284 STD { int sys_setresgid(gid_t rgid, gid_t egid, \ + gid_t sgid); } +285 OBSOL sys_omquery +286 STD { void *sys_mquery(void *addr, size_t len, int prot, \ + int flags, int fd, long pad, off_t pos); } +287 STD NOLOCK { int sys_closefrom(int fd); } +288 STD { int sys_sigaltstack(const struct sigaltstack *nss, \ + struct sigaltstack *oss); } +#ifdef SYSVSHM +289 STD { int sys_shmget(key_t key, size_t size, int shmflg); } +#else +289 UNIMPL shmget +#endif +#ifdef SYSVSEM +290 STD { int sys_semop(int semid, struct sembuf *sops, \ + size_t nsops); } +#else +290 UNIMPL semop +#endif +291 OBSOL t32_stat +292 OBSOL t32_fstat +293 OBSOL t32_lstat +294 STD { int sys_fhstat(const fhandle_t *fhp, \ + struct stat *sb); } +#ifdef SYSVSEM +295 STD { int sys___semctl(int semid, int semnum, int cmd, \ + union semun *arg); } +#else +295 UNIMPL +#endif +#ifdef SYSVSHM +296 STD { int sys_shmctl(int shmid, int cmd, \ + struct shmid_ds *buf); } +#else +296 UNIMPL +#endif +#ifdef SYSVMSG +297 STD { int sys_msgctl(int msqid, int cmd, \ + struct msqid_ds *buf); } +#else +297 UNIMPL +#endif +298 STD { int sys_sched_yield(void); } +299 STD NOLOCK { pid_t sys_getthrid(void); } +300 OBSOL t32___thrsleep +301 STD NOLOCK { int sys___thrwakeup(const volatile void *ident, \ + int n); } +302 STD { void sys___threxit(pid_t *notdead); } +303 STD { int sys___thrsigdivert(sigset_t sigmask, \ + siginfo_t *info, const struct timespec *timeout); } +304 STD { int sys___getcwd(char *buf, size_t len); } +305 STD NOLOCK { int sys_adjfreq(const int64_t *freq, \ + int64_t *oldfreq); } +306 OBSOL getfsstat53 +307 OBSOL statfs53 +308 OBSOL fstatfs53 +309 OBSOL fhstatfs53 +310 STD NOLOCK { int sys_setrtable(int rtableid); } +311 STD NOLOCK { int sys_getrtable(void); } +312 OBSOL t32_getdirentries +313 STD { int sys_faccessat(int fd, const char *path, \ + int amode, int flag); } +314 STD { int sys_fchmodat(int fd, const char *path, \ + mode_t mode, int flag); } +315 STD { int sys_fchownat(int fd, const char *path, \ + uid_t uid, gid_t gid, int flag); } +316 OBSOL t32_fstatat +317 STD { int sys_linkat(int fd1, const char *path1, int fd2, \ + const char *path2, int flag); } +318 STD { int sys_mkdirat(int fd, const char *path, \ + mode_t mode); } +319 STD { int sys_mkfifoat(int fd, const char *path, \ + mode_t mode); } +320 STD { int sys_mknodat(int fd, const char *path, \ + mode_t mode, dev_t dev); } +321 STD { int sys_openat(int fd, const char *path, int flags, \ + ... mode_t mode); } +322 STD { ssize_t sys_readlinkat(int fd, const char *path, \ + char *buf, size_t count); } +323 STD { int sys_renameat(int fromfd, const char *from, \ + int tofd, const char *to); } +324 STD { int sys_symlinkat(const char *path, int fd, \ + const char *link); } +325 STD { int sys_unlinkat(int fd, const char *path, \ + int flag); } +326 OBSOL t32_utimensat +327 OBSOL t32_futimens +328 OBSOL __tfork51 +329 STD NOLOCK { void sys___set_tcb(void *tcb); } +330 STD NOLOCK { void *sys___get_tcb(void); } diff --git a/support/syscall-gen/types+openbsd:7.0-x64.frag b/support/syscall-gen/types+openbsd:7.0-x64.frag new file mode 100644 index 0000000..09d48e0 --- /dev/null +++ b/support/syscall-gen/types+openbsd:7.0-x64.frag @@ -0,0 +1,488 @@ +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 uid = int32 /* user id */ +type key = int32 /* sysv ipc key */ +type id = int32 /* 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 clockid = uint32 +type msg = void +type msqid_ds = void +type gid = uint32 + +const Futexwait : int = 1 +const Futexwake : int = 2 +const Futexrequeue : int = 3 + + +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 : int64 + nsec : int64 +;; + +type timeval = struct + sec : int64 + usec : int64 +;; + +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 fsid = struct + val : int32[2] +;; + +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 Mstack : mopt = 0x4000 +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## |