hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit e3186db880bb47d9ea6355250d42cf3571634a9f
parent cae9eaf4a2dd514d2ab60498db18a108db7376e6
Author: Mallory Adams <malloryadams@fastmail.com>
Date:   Sun, 26 May 2024 12:12:17 -0400

NetBSD: make the build pass, replace all compat syscalls

compat_13 is a non-builtin kernel module that can be autoloaded if a
compat_13 syscall is called, but the file belongs to the `mi` set and
isn't available in all installations.

The other compat modules are builtin to the GENERIC kernel so they
should be available, but we may as well replace them.

- Replace SYS_compat_13_sigaction13 with SYS___sigaction_sigtramp
- Replace SYS_compat_13_sigprocmask13 with SYS___sigprocmask14
- Replace SYS_compat_43_fstat43 with SYS___fstat50
- Replace SYS_compat_30_getdents with SYS___getdents30
- Replace SYS_compat_50_wait4 with SYS___wait450
- Replace SYS_compat_50_nanosleep with SYS___nanosleep50
- .builds/netbsd.yml: Update the path to the leapseconds file
- .builds/netbsd.yml: Use sudo not doas

Diffstat:
M.builds/netbsd.yml | 8++++----
Mrt/+netbsd/syscalls.ha | 96++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mrt/+netbsd/types.ha | 67+++++++++++++++++++++++++------------------------------------------
3 files changed, 77 insertions(+), 94 deletions(-)

diff --git a/.builds/netbsd.yml b/.builds/netbsd.yml @@ -27,21 +27,21 @@ tasks: fi - ntp-leapseconds: | ftp https://hpiers.obspm.fr/iers/bul/bulc/ntp/leap-seconds.list - doas mv leap-seconds.list /var/db/ntpd.leap-seconds.list + sudo mv leap-seconds.list /usr/share/zoneinfo/leap-seconds.list - qbe: | cd qbe make -j2 PREFIX=/usr - doas make install PREFIX=/usr + sudo make install PREFIX=/usr - harec: | cd harec cp configs/netbsd.mk config.mk make -j2 - doas make install + sudo make install - hare: | cd hare cp configs/netbsd.mk config.mk make -j2 - doas make install + sudo make install - check: | cd hare make -j2 check diff --git a/rt/+netbsd/syscalls.ha b/rt/+netbsd/syscalls.ha @@ -55,28 +55,28 @@ export fn fchownat(dirfd: int, path: path, uid: uint, gid: uint, flags: int) (vo export fn fstatat(fd: int, path: path, _stat: *st, flag: int) (void | errno) = { let path = kpath(path)?; - let fbstat = stat { ... }; + let sb = stat { ... }; wrap_return(syscall4(SYS_fstatat, fd: u64, - path: uintptr: u64, &fbstat: uintptr: u64, flag: u64))?; - _stat.dev = fbstat.st_dev; - _stat.ino = fbstat.st_ino; - _stat.mode = fbstat.st_mode; - _stat.nlink = fbstat.st_nlink; - _stat.uid = fbstat.st_uid; - _stat.gid = fbstat.st_gid; - _stat.rdev = fbstat.st_rdev; - _stat.atime.tv_sec = fbstat.st_atim.tv_sec; - _stat.atime.tv_nsec = fbstat.st_atim.tv_nsec: i64; - _stat.mtime.tv_sec = fbstat.st_mtim.tv_sec; - _stat.mtime.tv_nsec = fbstat.st_mtim.tv_nsec: i64; - _stat.ctime.tv_sec = fbstat.st_ctim.tv_sec; - _stat.ctime.tv_nsec = fbstat.st_ctim.tv_nsec: i64; - _stat.btime.tv_sec = fbstat.st_birthtim.tv_sec; - _stat.btime.tv_nsec = fbstat.st_birthtim.tv_nsec: i64; - _stat.sz = fbstat.st_size; - _stat.blocks = fbstat.st_blocks; - _stat.blksz = fbstat.st_blksize; - _stat.flags = fbstat.st_flags; + path: uintptr: u64, &sb: uintptr: u64, flag: u64))?; + _stat.dev = sb.st_dev; + _stat.ino = sb.st_ino; + _stat.mode = sb.st_mode; + _stat.nlink = sb.st_nlink; + _stat.uid = sb.st_uid; + _stat.gid = sb.st_gid; + _stat.rdev = sb.st_rdev; + _stat.atime.tv_sec = sb.st_atim.tv_sec; + _stat.atime.tv_nsec = sb.st_atim.tv_nsec: i64; + _stat.mtime.tv_sec = sb.st_mtim.tv_sec; + _stat.mtime.tv_nsec = sb.st_mtim.tv_nsec: i64; + _stat.ctime.tv_sec = sb.st_ctim.tv_sec; + _stat.ctime.tv_nsec = sb.st_ctim.tv_nsec: i64; + _stat.btime.tv_sec = sb.st_birthtim.tv_sec; + _stat.btime.tv_nsec = sb.st_birthtim.tv_nsec: i64; + _stat.sz = sb.st_size; + _stat.blocks = sb.st_blocks; + _stat.blksz = sb.st_blksize; + _stat.flags = sb.st_flags; }; export fn futimens(fd: int, ts: *[2]timespec) (void | errno) = { @@ -85,7 +85,7 @@ export fn futimens(fd: int, ts: *[2]timespec) (void | errno) = { }; export fn getdents(dirfd: int, buf: *opaque, nbytes: size) (size | errno) = { - return wrap_return(syscall3(SYS_compat_30_getdents, dirfd: u64, + return wrap_return(syscall3(SYS___getdents30, dirfd: u64, buf: uintptr: u64, nbytes: u64))?: size; }; @@ -208,7 +208,7 @@ export fn wait4( options: int, rusage: nullable *rusage, ) (int | errno) = { - return wrap_return(syscall4(SYS_compat_50_wait4, + return wrap_return(syscall4(SYS___wait450, pid: u64, wstatus: uintptr: u64, options: u64, rusage: uintptr: u64))?: int; }; @@ -290,7 +290,7 @@ export fn ftruncate(fd: int, ln: off_t) (void | errno) = { }; export fn nanosleep(req: *const timespec, rem: *timespec) (void | errno) = { - wrap_return(syscall2(SYS_compat_50_nanosleep, + wrap_return(syscall2(SYS___nanosleep50, req: uintptr: u64, rem: uintptr: u64))?; }; @@ -421,7 +421,7 @@ export fn sigaction( act: *const sigact, old: nullable *sigact, ) (int | errno) = { - return wrap_return(syscall3(SYS_compat_13_sigaction13, + return wrap_return(syscall3(SYS___sigaction_sigtramp, signum: u64, act: uintptr: u64, old: uintptr: u64))?: int; }; @@ -430,7 +430,7 @@ export fn sigprocmask( set: nullable *const sigset, old: nullable *sigset, ) (int | errno) = { - return wrap_return(syscall3(SYS_compat_13_sigprocmask13, + return wrap_return(syscall3(SYS___sigprocmask14, how: u64, set: uintptr: u64, old: uintptr: u64))?: int; }; @@ -445,28 +445,28 @@ export fn open( }; export fn fstat(fd: int, _stat: *st) (void | errno) = { - let fbstat = stat43 { ... }; - wrap_return(syscall2(SYS_compat_43_fstat43, fd: u64, - &fbstat: uintptr: u64))?; - _stat.dev = fbstat.st_dev; - _stat.ino = fbstat.st_ino; - _stat.mode = fbstat.st_mode; - _stat.nlink = fbstat.st_nlink; - _stat.uid = fbstat.st_uid; - _stat.gid = fbstat.st_gid; - _stat.rdev = fbstat.st_rdev; - _stat.atime.tv_sec = fbstat.st_atim.tv_sec; - _stat.atime.tv_nsec = fbstat.st_atim.tv_nsec: i64; - _stat.mtime.tv_sec = fbstat.st_mtim.tv_sec; - _stat.mtime.tv_nsec = fbstat.st_mtim.tv_nsec: i64; - _stat.ctime.tv_sec = fbstat.st_ctim.tv_sec; - _stat.ctime.tv_nsec = fbstat.st_ctim.tv_nsec: i64; - _stat.btime.tv_sec = fbstat.st_birthtim.tv_sec; - _stat.btime.tv_nsec = fbstat.st_birthtim.tv_nsec: i64; - _stat.sz = fbstat.st_size; - _stat.blocks = fbstat.st_blocks; - _stat.blksz = fbstat.st_blksize; - _stat.flags = fbstat.st_flags; + let sb = stat { ... }; + wrap_return(syscall2(SYS___fstat50, fd: u64, + &sb: uintptr: u64))?; + _stat.dev = sb.st_dev; + _stat.ino = sb.st_ino; + _stat.mode = sb.st_mode; + _stat.nlink = sb.st_nlink; + _stat.uid = sb.st_uid; + _stat.gid = sb.st_gid; + _stat.rdev = sb.st_rdev; + _stat.atime.tv_sec = sb.st_atim.tv_sec; + _stat.atime.tv_nsec = sb.st_atim.tv_nsec: i64; + _stat.mtime.tv_sec = sb.st_mtim.tv_sec; + _stat.mtime.tv_nsec = sb.st_mtim.tv_nsec: i64; + _stat.ctime.tv_sec = sb.st_ctim.tv_sec; + _stat.ctime.tv_nsec = sb.st_ctim.tv_nsec: i64; + _stat.btime.tv_sec = sb.st_birthtim.tv_sec; + _stat.btime.tv_nsec = sb.st_birthtim.tv_nsec: i64; + _stat.sz = sb.st_size; + _stat.blocks = sb.st_blocks; + _stat.blksz = sb.st_blksize; + _stat.flags = sb.st_flags; }; export fn fexecve(fd: int, argv: *[*]nullable *const u8, diff --git a/rt/+netbsd/types.ha b/rt/+netbsd/types.ha @@ -23,6 +23,9 @@ export type path = (str | []u8 | *const u8); // Maximum length of a file path including the NUL terminator. export def PATH_MAX = 1024z; +// Max bytes in a file name +export def NAME_MAX: int = 511; + export def NGROUPS_MAX: size = 1023; export def NSIG: int = 32; @@ -49,8 +52,8 @@ export type sigact = struct { sa_handler: *fn (int) void, sa_sigaction: *fn (int, *siginfo, *opaque) void, }, - sa_flags: int, sa_mask: sigset, + sa_flags: int, }; export def SIG_BLOCK: int = 1; @@ -135,32 +138,12 @@ export type stat = struct { st_spare: [2]u32, }; -export type stat43 = struct { - st_dev: u32, - st_ino: u32, - st_mode: mode_t, - st_nlink: u16, - st_uid: uid_t, - st_gid: gid_t, - st_rdev: u32, - st_atim: timespec, - st_mtim: timespec, - st_ctim: timespec, - st_size: off_t, - st_blocks: blkcnt_t, - st_blksize: blksize_t, - st_flags: fflags_t, - st_gen: u32, - st_lspare: u32, - st_birthtim: timespec, -}; - export type dirent = struct { - d_fileno: u32, - d_reclen: u16, - d_type: u8, - d_namlen: u8, - d_name: [*]u8, + d_fileno: ino_t, // file number of entry + d_reclen: u16, // length of this record + d_namlen: u16, // length of d_name + d_type: u8, // file type, see below + d_name: [NAME_MAX + 1]u8, }; export type iovec = struct { @@ -291,22 +274,22 @@ export type ptmget = struct { }; export type rusage = struct { - ru_utime: timeval, - ru_stime: timeval, - ru_maxrss: i64, - ru_ixrss: i64, - ru_idrss: i64, - ru_isrss: i64, - ru_minflt: i64, - ru_majflt: i64, - ru_nswap: i64, - ru_inblock: i64, - ru_oublock: i64, - ru_msgsnd: i64, - ru_msgrcv: i64, - ru_nsignals: i64, - ru_nvcsw: i64, - ru_nivcsw: i64, + ru_utime: timeval, // user time used + ru_stime: timeval, // system time used + ru_maxrss: i64, // max resident set size + ru_ixrss: i64, // integral shared memory size + ru_idrss: i64, // integral unshared data " + ru_isrss: i64, // integral unshared stack " + ru_minflt: i64, // page reclaims + ru_majflt: i64, // page faults + ru_nswap: i64, // swaps + ru_inblock: i64, // block input operations + ru_oublock: i64, // block output operations + ru_msgsnd: i64, // messages sent + ru_msgrcv: i64, // messages received + ru_nsignals: i64, // signals received + ru_nvcsw: i64, // voluntary context switches + ru_nivcsw: i64, // involuntary " }; export def DT_UNKNOWN: u8 = 0;