memory.ha (1294B)
1 // SPDX-License-Identifier: MPL-2.0 2 // (c) Hare authors <https://harelang.org> 3 4 // TODO: Implement FreeBSD version 5 use errors; 6 use rt; 7 8 // Flags for the [[mlock]] family of operations. 9 export type mcl = enum uint { 10 CURRENT = 1, 11 FUTURE = 2, 12 ONFAULT = 4, 13 }; 14 15 // Locks a region of memory so that it will not be written to swap. 16 export fn mlock( 17 addr: *opaque, 18 length: size, 19 flags: mcl, 20 ) (void | errors::error) = { 21 match (rt::mlock2(addr, length, flags)) { 22 case let err: rt::errno => 23 return errors::errno(err); 24 case void => 25 return; 26 }; 27 }; 28 29 // Unlocks memory previously locked with [[mlock]]. 30 export fn munlock(addr: *opaque, length: size) (void | errors::error) = { 31 match (rt::munlock(addr, length)) { 32 case let err: rt::errno => 33 return errors::errno(err); 34 case void => 35 return; 36 }; 37 }; 38 39 // Locks the entire process's address space so that it will not be written to 40 // swap. 41 export fn mlockall(flags: mcl) (void | errors::error) = { 42 match (rt::mlockall(flags)) { 43 case let err: rt::errno => 44 return errors::errno(err); 45 case void => 46 return; 47 }; 48 }; 49 50 // Unlocks all locked memory in the process's address space. 51 export fn munlockall() (void | errors::error) = { 52 match (rt::munlockall()) { 53 case let err: rt::errno => 54 return errors::errno(err); 55 case void => 56 return; 57 }; 58 };