Debian Codegraph @

io/+dragonfly/mmap.ha

raw
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 NOCORE = rt::MAP_NOCORE,
28 _32BIT = rt::MAP_32BIT,
29 };
30
31 // Performs the mmap syscall. Consult your system for documentation on this
32 // function.
33 export fn mmap(
34 addr: nullable *opaque,
35 length: size,
36 prot: prot,
37 flags: mflag,
38 fd: file,
39 offs: size
40 ) (*opaque | errors::error) = {
41 match (rt::mmap(addr, length, prot, flags, fd, offs)) {
42 case let ptr: *opaque =>
43 return ptr;
44 case let err: rt::errno =>
45 return errors::errno(err);
46 };
47 };
48
49 // Unmaps memory previously mapped with [[mmap]].
50 export fn munmap(addr: *opaque, length: size) (void | errors::error) = {
51 match (rt::munmap(addr, length)) {
52 case void =>
53 return;
54 case let err: rt::errno =>
55 return errors::errno(err);
56 };
57 };