mmap.ha (1459B)
1 // SPDX-License-Identifier: MPL-2.0 2 // (c) Hare authors <https://harelang.org> 3 4 use errors; 5 use rt; 6 7 // Values for the [[mmap]] prot parameter. Only the EXEC, READ, WRITE, and NONE 8 // values are portable. 9 export type prot = enum uint { 10 NONE = rt::PROT_NONE, 11 READ = rt::PROT_READ, 12 WRITE = rt::PROT_WRITE, 13 EXEC = rt::PROT_EXEC, 14 }; 15 16 // Values for the [[mmap]] flags parameter. Only the SHARED, PRIVATE, and FIXED 17 // values are portable. 18 export type mflag = enum uint { 19 SHARED = rt::MAP_SHARED, 20 PRIVATE = rt::MAP_PRIVATE, 21 FIXED = rt::MAP_FIXED, 22 HASSEMAPHORE = rt::MAP_HASSEMAPHORE , 23 STACK = rt::MAP_STACK, 24 NOSYNC = rt::MAP_NOSYNC, 25 FILE = rt::MAP_FILE, 26 ANON = rt::MAP_ANON, 27 GUARD = rt::MAP_GUARD, 28 EXCL = rt::MAP_EXCL, 29 NOCORE = rt::MAP_NOCORE, 30 PREFAULT_READ = rt::MAP_PREFAULT_READ, 31 _32BIT = rt::MAP_32BIT, 32 }; 33 34 // Performs the mmap syscall. Consult your system for documentation on this 35 // function. 36 export fn mmap( 37 addr: nullable *opaque, 38 length: size, 39 prot: prot, 40 flags: mflag, 41 fd: file, 42 offs: size 43 ) (*opaque | errors::error) = { 44 match (rt::mmap(addr, length, prot, flags, fd, offs)) { 45 case let ptr: *opaque => 46 return ptr; 47 case let err: rt::errno => 48 return errors::errno(err); 49 }; 50 }; 51 52 // Unmaps memory previously mapped with [[mmap]]. 53 export fn munmap(addr: *opaque, length: size) (void | errors::error) = { 54 match (rt::munmap(addr, length)) { 55 case void => 56 return; 57 case let err: rt::errno => 58 return errors::errno(err); 59 }; 60 };