1use crate::ffi::asan::*;
6
7use std::ffi::CStr;
8use std::os::raw::c_void;
9
10pub fn poison_memory_region(addr: *const c_void, size: usize) {
12 unsafe {
13 __asan_poison_memory_region(addr, size);
14 }
15}
16
17pub fn unpoison_memory_region(addr: *const c_void, size: usize) {
19 unsafe {
20 __asan_unpoison_memory_region(addr, size);
21 }
22}
23
24pub fn is_address_poisoned(addr: *const c_void) -> bool {
26 unsafe { __asan_address_is_poisoned(addr) != 0 }
27}
28
29pub fn region_is_poisoned(beg: *mut c_void, size: usize) -> Option<*mut c_void> {
31 let addr = unsafe { __asan_region_is_poisoned(beg, size) };
32 if addr.is_null() {
33 None
34 } else {
35 Some(addr)
36 }
37}
38
39pub fn describe_address(addr: *mut c_void) {
41 unsafe {
42 __asan_describe_address(addr);
43 }
44}
45
46pub fn report_present() -> bool {
48 unsafe { __asan_report_present() != 0 }
49}
50
51pub fn get_report_pc() -> *mut c_void {
53 unsafe { __asan_get_report_pc() }
54}
55
56pub fn get_report_bp() -> *mut c_void {
58 unsafe { __asan_get_report_bp() }
59}
60
61pub fn get_report_sp() -> *mut c_void {
63 unsafe { __asan_get_report_sp() }
64}
65
66pub fn get_report_address() -> *mut c_void {
68 unsafe { __asan_get_report_address() }
69}
70
71pub fn get_report_access_type() -> i32 {
73 unsafe { __asan_get_report_access_type() }
74}
75
76pub fn get_report_access_size() -> usize {
78 unsafe { __asan_get_report_access_size() }
79}
80
81pub fn get_report_description() -> String {
83 unsafe {
84 let desc_ptr = __asan_get_report_description();
85 if desc_ptr.is_null() {
86 String::new()
87 } else {
88 CStr::from_ptr(desc_ptr).to_string_lossy().into_owned()
89 }
90 }
91}
92
93pub fn set_error_report_callback(callback: Option<unsafe extern "C" fn(arg1: *const i8)>) {
95 unsafe {
96 __asan_set_error_report_callback(callback);
97 }
98}
99
100pub fn print_accumulated_stats() {
102 unsafe {
103 __asan_print_accumulated_stats();
104 }
105}
106
107pub fn default_options() -> String {
109 unsafe {
110 let options_ptr = __asan_default_options();
111 if options_ptr.is_null() {
112 String::new()
113 } else {
114 CStr::from_ptr(options_ptr).to_string_lossy().into_owned()
115 }
116 }
117}