hare

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

commit 311c41956e32a43afc1c21d9addbfbbab7c59514
parent d89bd967d0f7bce35282251d4e6de12a4e89209b
Author: Sebastian <sebastian@sebsite.pw>
Date:   Mon,  8 May 2023 16:43:35 -0400

rt: add getrlimit and setrlimit

Diffstat:
Mrt/+freebsd/syscalls.ha | 10++++++++++
Mrt/+freebsd/types.ha | 23+++++++++++++++++++++++
Mrt/+linux/syscalls.ha | 10++++++++++
Mrt/+linux/types.ha | 24++++++++++++++++++++++++
4 files changed, 67 insertions(+), 0 deletions(-)

diff --git a/rt/+freebsd/syscalls.ha b/rt/+freebsd/syscalls.ha @@ -523,3 +523,13 @@ export fn shmat(id: int, addr: *const void, flag: int) *void = { return syscall3(SYS_shmat, id: u64, addr: uintptr: u64, flag: u64): uintptr: *void; }; + +export fn getrlimit(resource: int, rlim: *rlimit) (void | errno) = { + wrap_return(syscall2(SYS_getrlimit, + resource: u64, rlim: uintptr: u64))?; +}; + +export fn setrlimit(resource: int, rlim: *const rlimit) (void | errno) = { + wrap_return(syscall2(SYS_setrlimit, + resource: u64, rlim: uintptr: u64))?; +}; diff --git a/rt/+freebsd/types.ha b/rt/+freebsd/types.ha @@ -19,6 +19,7 @@ export type blksize_t = i32; export type fflags_t = u32; export type mode_t = u16; export type nfds_t = uint; +export type rlim_t = u64; export def NGROUPS_MAX: size = 1023; export def NSIG: int = 32; @@ -440,3 +441,25 @@ export def LOCK_SH: int = 1; export def LOCK_EX: int = 2; export def LOCK_NB: int = 4; export def LOCK_UN: int = 8; + +export type rlimit = struct { + rlim_cur: rlim_t, + rlim_max: rlim_t, +}; + +export def RLIMIT_CPU: int = 0; +export def RLIMIT_FSIZE: int = 1; +export def RLIMIT_DATA: int = 2; +export def RLIMIT_STACK: int = 3; +export def RLIMIT_CORE: int = 4; +export def RLIMIT_RSS: int = 5; +export def RLIMIT_MEMLOCK: int = 6; +export def RLIMIT_NPROC: int = 7; +export def RLIMIT_NOFILE: int = 8; +export def RLIMIT_SBSIZE: int = 9; +export def RLIMIT_VMEM: int = 10; +export def RLIMIT_AS: int = RLIMIT_VMEM; +export def RLIMIT_NPTS: int = 11; +export def RLIMIT_SWAP: int = 12; +export def RLIMIT_KQUEUES: int = 13; +export def RLIMIT_UMTXP: int = 14; diff --git a/rt/+linux/syscalls.ha b/rt/+linux/syscalls.ha @@ -950,3 +950,13 @@ export fn sched_setaffinity( wrap_return(syscall3(SYS_sched_setaffinity, pid: u64, cpusetsize: u64, mask: uintptr: u64))?; }; + +export fn getrlimit(resource: int, rlim: *rlimit) (void | errno) = { + wrap_return(syscall2(SYS_getrlimit, + resource: u64, rlim: uintptr: u64))?; +}; + +export fn setrlimit(resource: int, rlim: *const rlimit) (void | errno) = { + wrap_return(syscall2(SYS_setrlimit, + resource: u64, rlim: uintptr: u64))?; +}; diff --git a/rt/+linux/types.ha b/rt/+linux/types.ha @@ -23,6 +23,7 @@ export type pid_t = int; export type timer_t = int; export type clock_t = i64; export type si_band_t = i64; +export type rlim_t = u64; export def NGROUPS_MAX: size = 32; export def NSIG: int = 64; @@ -878,3 +879,26 @@ export def INQOVERFLOW: u32 = 0x00004000; export def INIGNORED: u32 = 0x00008000; export def INMOVE: u32 = INMOVEDFROM | INMOVEDTO; export def INCLOSE: u32 = INCLOSEWRITE | INCLOSENOWRITE; + +export type rlimit = struct { + rlim_cur: rlim_t, + rlim_max: rlim_t, +}; + +export def RLIMIT_CPU: int = 0; +export def RLIMIT_FSIZE: int = 1; +export def RLIMIT_DATA: int = 2; +export def RLIMIT_STACK: int = 3; +export def RLIMIT_CORE: int = 4; +export def RLIMIT_RSS: int = 5; +export def RLIMIT_NPROC: int = 6; +export def RLIMIT_NOFILE: int = 7; +export def RLIMIT_MEMLOCK: int = 8; +export def RLIMIT_AS: int = 9; +export def RLIMIT_LOCKS: int = 10; +export def RLIMIT_SIGPENDING: int = 11; +export def RLIMIT_MSGQUEUE: int = 12; +export def RLIMIT_NICE: int = 13; +export def RLIMIT_RTPRIO: int = 14; +export def RLIMIT_RTTIME: int = 15; +export def RLIMIT_NLIMITS: int = 16;