File: memory.ha

package info (click to toggle)
hare 0.25.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,948 kB
  • sloc: asm: 1,264; makefile: 123; sh: 114; lisp: 101
file content (58 lines) | stat: -rw-r--r-- 1,294 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// SPDX-License-Identifier: MPL-2.0
// (c) Hare authors <https://harelang.org>

// 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: *opaque,
	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: *opaque, 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;
	};
};