hare

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

mmap.ha (1265B)


      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 int {
     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 int {
     19 	SHARED = rt::MAP_SHARED,
     20 	PRIVATE = rt::MAP_PRIVATE,
     21 	FIXED = rt::MAP_FIXED,
     22 	ANON = rt::MAP_ANON,
     23 	STACK = rt::MAP_STACK,
     24 	CONCEAL = rt::MAP_CONCEAL
     25 };
     26 
     27 // Performs the mmap syscall. Consult your system for documentation on this
     28 // function.
     29 export fn mmap(
     30 	addr: nullable *opaque,
     31 	length: size,
     32 	prot: prot,
     33 	flags: mflag,
     34 	fd: file,
     35 	offs: size
     36 ) (*opaque | errors::error) = {
     37 	match (rt::mmap(addr, length, prot, flags, fd, offs: i64)) {
     38 	case let ptr: *opaque =>
     39 		return ptr;
     40 	case let err: rt::errno =>
     41 		return errors::errno(err);
     42 	};
     43 };
     44 
     45 // Unmaps memory previously mapped with [[mmap]].
     46 export fn munmap(addr: *opaque, length: size) (void | errors::error) = {
     47 	match (rt::munmap(addr, length)) {
     48 	case void =>
     49 		return;
     50 	case let err: rt::errno =>
     51 		return errors::errno(err);
     52 	};
     53 };