hare

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

commit 876b5929ab8a17c0f9c8dbbf5235ad5134f8bab0
parent e4b65d488e4eac2cb90eea08799c8ba3336bd95c
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue, 29 Mar 2022 21:10:00 +0200

os+linux: add mlock family of functions

Diffstat:
Aos/+linux/memory.ha | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mrt/+linux/syscalls.ha | 2+-
Mscripts/gen-stdlib | 5+++--
Mstdlib.mk | 10++++++----
4 files changed, 65 insertions(+), 7 deletions(-)

diff --git a/os/+linux/memory.ha b/os/+linux/memory.ha @@ -0,0 +1,55 @@ +// TODO: Implement FreeBSD version +use errors; +use rt; + +// Flags for the [[mlock]] family of operations. +export type mcl = enum uint { + CURRENT = 1, + FUTURE = 2, + ONFAULT = 4, +}; + +// Locks a region of memory so that it will not be written to swap. +export fn mlock( + addr: *void, + length: size, + flags: mcl, +) (void | errors::error) = { + match (rt::mlock2(addr, length, flags)) { + case let err: rt::errno => + return errors::errno(err); + case void => + return; + }; +}; + +// Unlocks memory previously locked with [[mlock]]. +export fn munlock(addr: *void, length: size) (void | errors::error) = { + match (rt::munlock(addr, length)) { + case let err: rt::errno => + return errors::errno(err); + case void => + return; + }; +}; + +// Locks the entire process's address space so that it will not be written to +// swap. +export fn mlockall(flags: mcl) (void | errors::error) = { + match (rt::mlockall(flags)) { + case let err: rt::errno => + return errors::errno(err); + case void => + return; + }; +}; + +// Unlocks all locked memory in the process's address space. +export fn munlockall() (void | errors::error) = { + match (rt::munlockall()) { + case let err: rt::errno => + return errors::errno(err); + case void => + return; + }; +}; diff --git a/rt/+linux/syscalls.ha b/rt/+linux/syscalls.ha @@ -718,7 +718,7 @@ export fn munlock(addr: *void, length: size) (void | errno) = { length: u64))?: void; }; -export fn mlockall(flags: int) (void | errno) = { +export fn mlockall(flags: uint) (void | errno) = { return wrap_return(syscall1(SYS_mlockall, flags: u64))?: void; }; diff --git a/scripts/gen-stdlib b/scripts/gen-stdlib @@ -969,11 +969,12 @@ math_random() { os() { gen_srcs -plinux os \ + +linux/dirfdfs.ha \ +linux/environ.ha \ +linux/exit.ha \ - +linux/dirfdfs.ha \ - +linux/stdfd.ha \ +linux/fs.ha \ + +linux/memory.ha \ + +linux/stdfd.ha \ fs.ha gen_ssa -plinux os io strings types fs encoding::utf8 bytes bufio errors diff --git a/stdlib.mk b/stdlib.mk @@ -1526,11 +1526,12 @@ $(HARECACHE)/net/uri/net_uri-any.ssa: $(stdlib_net_uri_any_srcs) $(stdlib_rt) $( # os (+linux) stdlib_os_linux_srcs= \ + $(STDLIB)/os/+linux/dirfdfs.ha \ $(STDLIB)/os/+linux/environ.ha \ $(STDLIB)/os/+linux/exit.ha \ - $(STDLIB)/os/+linux/dirfdfs.ha \ - $(STDLIB)/os/+linux/stdfd.ha \ $(STDLIB)/os/+linux/fs.ha \ + $(STDLIB)/os/+linux/memory.ha \ + $(STDLIB)/os/+linux/stdfd.ha \ $(STDLIB)/os/fs.ha $(HARECACHE)/os/os-linux.ssa: $(stdlib_os_linux_srcs) $(stdlib_rt) $(stdlib_io_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_types_$(PLATFORM)) $(stdlib_fs_$(PLATFORM)) $(stdlib_encoding_utf8_$(PLATFORM)) $(stdlib_bytes_$(PLATFORM)) $(stdlib_bufio_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) @@ -3427,11 +3428,12 @@ $(TESTCACHE)/net/uri/net_uri-any.ssa: $(testlib_net_uri_any_srcs) $(testlib_rt) # os (+linux) testlib_os_linux_srcs= \ + $(STDLIB)/os/+linux/dirfdfs.ha \ $(STDLIB)/os/+linux/environ.ha \ $(STDLIB)/os/+linux/exit.ha \ - $(STDLIB)/os/+linux/dirfdfs.ha \ - $(STDLIB)/os/+linux/stdfd.ha \ $(STDLIB)/os/+linux/fs.ha \ + $(STDLIB)/os/+linux/memory.ha \ + $(STDLIB)/os/+linux/stdfd.ha \ $(STDLIB)/os/fs.ha $(TESTCACHE)/os/os-linux.ssa: $(testlib_os_linux_srcs) $(testlib_rt) $(testlib_io_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_types_$(PLATFORM)) $(testlib_fs_$(PLATFORM)) $(testlib_encoding_utf8_$(PLATFORM)) $(testlib_bytes_$(PLATFORM)) $(testlib_bufio_$(PLATFORM)) $(testlib_errors_$(PLATFORM))