Debian Codegraph @

libphobos/libdruntime/etc/valgrind/valgrind.d

raw
1 /// D wrapper for the Valgrind client API.
2 /// Note that you must include this file into your program's compilation
3 /// and compile with `-debug=VALGRIND` to access the declarations below.
4 module etc.valgrind.valgrind;
5
6 version (StdDdoc)
7 {
8 /// Mark the memory covered by `mem` as unaddressable.
9 void makeMemNoAccess (const(void)[] mem) nothrow @nogc;
10
11 /// Similarly, mark memory covered by `mem` as addressable but undefined.
12 void makeMemUndefined(const(void)[] mem) nothrow @nogc;
13
14 /// Similarly, mark memory covered by `mem` as addressable and defined.
15 void makeMemDefined (const(void)[] mem) nothrow @nogc;
16
17 /// Get the validity data for the address range covered by `mem` and copy it
18 /// into the provided `bits` array.
19 /// Returns:
20 /// - 0 if not running on valgrind
21 /// - 1 success
22 /// - 2 [previously indicated unaligned arrays; these are now allowed]
23 /// - 3 if any parts of `mem`/`bits` are not addressable.
24 /// The metadata is not copied in cases 0, 2 or 3 so it should be
25 /// impossible to segfault your system by using this call.
26 uint getVBits(const(void)[] mem, ubyte[] bits) nothrow @nogc;
27
28 /// Set the validity data for the address range covered by `mem`, copying it
29 /// from the provided `bits` array.
30 /// Returns:
31 /// - 0 if not running on valgrind
32 /// - 1 success
33 /// - 2 [previously indicated unaligned arrays; these are now allowed]
34 /// - 3 if any parts of `mem`/`bits` are not addressable.
35 /// The metadata is not copied in cases 0, 2 or 3 so it should be
36 /// impossible to segfault your system by using this call.
37 uint setVBits(const(void)[] mem, ubyte[] bits) nothrow @nogc;
38
39 /// Disable and re-enable reporting of addressing errors in the
40 /// address range covered by `mem`.
41 void disableAddrReportingInRange(const(void)[] mem) nothrow @nogc;
42
43 /// ditto
44 void enableAddrReportingInRange(const(void)[] mem) nothrow @nogc;
45 }
46 else:
47
48 debug(VALGRIND):
49
50 private extern(C) nothrow @nogc
51 {
52 void _d_valgrind_make_mem_noaccess (const(void)* addr, size_t len);
53 void _d_valgrind_make_mem_undefined(const(void)* addr, size_t len);
54 void _d_valgrind_make_mem_defined (const(void)* addr, size_t len);
55 uint _d_valgrind_get_vbits(const(void)* addr, ubyte* bits, size_t len);
56 uint _d_valgrind_set_vbits(const(void)* addr, ubyte* bits, size_t len);
57 void _d_valgrind_disable_addr_reporting_in_range(const(void)* addr, size_t len);
58 void _d_valgrind_enable_addr_reporting_in_range (const(void)* addr, size_t len);
59 }
60
61 void makeMemNoAccess (const(void)[] mem) nothrow @nogc { _d_valgrind_make_mem_noaccess (mem.ptr, mem.length); }
62 void makeMemUndefined(const(void)[] mem) nothrow @nogc { _d_valgrind_make_mem_undefined(mem.ptr, mem.length); }
63 void makeMemDefined (const(void)[] mem) nothrow @nogc { _d_valgrind_make_mem_defined (mem.ptr, mem.length); }
64
65 uint getVBits(const(void)[] mem, ubyte[] bits) nothrow @nogc
66 {
67 assert(mem.length == bits.length);
68 return _d_valgrind_get_vbits(mem.ptr, bits.ptr, mem.length);
69 }
70
71 uint setVBits(const(void)[] mem, ubyte[] bits) nothrow @nogc
72 {
73 assert(mem.length == bits.length);
74 return _d_valgrind_set_vbits(mem.ptr, bits.ptr, mem.length);
75 }
76
77 void disableAddrReportingInRange(const(void)[] mem) nothrow @nogc
78 {
79 _d_valgrind_disable_addr_reporting_in_range(mem.ptr, mem.length);
80 }
81
82 void enableAddrReportingInRange(const(void)[] mem) nothrow @nogc
83 {
84 _d_valgrind_enable_addr_reporting_in_range(mem.ptr, mem.length);
85 }