aboutsummaryrefslogtreecommitdiff
path: root/base/sanitizer/memory.odin
blob: b16309a4974f924281254d6c16622d144bd5298e (plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#+no-instrumentation
package sanitizer

@(private="file")
MSAN_ENABLED :: .Memory in ODIN_SANITIZER_FLAGS

@(private="file")
@(default_calling_convention="system")
foreign {
	__msan_unpoison :: proc(addr: rawptr, size: uint) ---
}

/*
Marks a slice as fully initialized.

Code instrumented with `-sanitize:memory` will be permitted to access any
address within the slice as if it had already been initialized.

When msan is not enabled this procedure does nothing.
*/
memory_unpoison_slice :: proc "contextless" (region: $T/[]$E) {
	when MSAN_ENABLED {
		__msan_unpoison(raw_data(region),  size_of(E) * len(region))
	}
}

/*
Marks a pointer as fully initialized.

Code instrumented with `-sanitize:memory` will be permitted to access memory
within the region the pointer points to as if it had already been initialized.

When msan is not enabled this procedure does nothing.
*/
memory_unpoison_ptr :: proc "contextless" (ptr: ^$T) {
	when MSAN_ENABLED {
		__msan_unpoison(ptr, size_of(T))
	}
}

/*
Marks the region covering `[ptr, ptr+len)` as fully initialized.

Code instrumented with `-sanitize:memory` will be permitted to access memory
within this range as if it had already been initialized.

When msan is not enabled this procedure does nothing.
*/
memory_unpoison_rawptr :: proc "contextless" (ptr: rawptr, len: int) {
	when MSAN_ENABLED {
		__msan_unpoison(ptr, uint(len))
	}
}

/*
Marks the region covering `[ptr, ptr+len)` as fully initialized.

Code instrumented with `-sanitize:memory` will be permitted to access memory
within this range as if it had already been initialized.

When msan is not enabled this procedure does nothing.
*/
memory_unpoison_rawptr_uint :: proc "contextless" (ptr: rawptr, len: uint) {
	when MSAN_ENABLED {
		__msan_unpoison(ptr, len)
	}
}

memory_unpoison :: proc {
	memory_unpoison_slice,
	memory_unpoison_ptr,
	memory_unpoison_rawptr,
	memory_unpoison_rawptr_uint,
}