Skip to content

Commit ff23c0e

Browse files
committed
Finished merging errors
1 parent d2a72cd commit ff23c0e

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

src/tools/bsan/bsan-rt/src/global.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use hashbrown::{DefaultHashBuilder, HashMap};
1717
use rustc_hash::FxBuildHasher;
1818

1919
use crate::*;
20+
use crate::shadow::ShadowHeap;
2021

2122
/// Every action that requires a heap allocation must be performed through a globally
2223
/// accessible, singleton instance of `GlobalCtx`. Initializing or obtaining
@@ -43,17 +44,21 @@ impl GlobalCtx {
4344
/// This function will also initialize our shadow heap
4445
fn new(hooks: BsanHooks) -> Self {
4546
Self {
46-
hooks,
47+
hooks: hooks.clone(),
4748
next_alloc_id: AtomicUsize::new(AllocId::min().get()),
4849
next_thread_id: AtomicUsize::new(0),
49-
shadow_heap: ShadowHeap::new(hooks),
50+
shadow_heap: ShadowHeap::new(&hooks),
5051
}
5152
}
5253

5354
pub fn shadow_heap(&self) -> &ShadowHeap<Provenance> {
5455
&self.shadow_heap
5556
}
5657

58+
pub fn hooks(&self) -> &BsanHooks {
59+
&self.hooks
60+
}
61+
5762
pub fn new_block<T>(&self, num_elements: NonZeroUsize) -> Block<T> {
5863
let layout = Layout::array::<T>(num_elements.into()).unwrap();
5964
let size = NonZeroUsize::new(layout.size()).unwrap();

src/tools/bsan/bsan-rt/src/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,19 @@ pub type Span = usize;
152152
/// and a borrow tag. We also include a pointer to the "lock" location for the allocation,
153153
/// which contains all other metadata used to detect undefined behavior.
154154
#[repr(C)]
155-
#[derive(Clone, Copy)]
155+
#[derive(Clone, Copy, Debug)]
156156
pub struct Provenance {
157157
pub alloc_id: AllocId,
158158
pub bor_tag: BorTag,
159159
pub alloc_info: *mut c_void,
160160
}
161161

162+
impl Default for Provenance {
163+
fn default() -> Self {
164+
Provenance::null()
165+
}
166+
}
167+
162168
impl Provenance {
163169
/// The default provenance value, which is assigned to dangling or invalid
164170
/// pointers.
@@ -258,14 +264,14 @@ extern "C" fn bsan_shadow_clear(addr: usize, access_size: usize) {}
258264
/// the result in the return pointer.
259265
#[no_mangle]
260266
unsafe extern "C" fn bsan_load_prov(prov: *mut Provenance, address: usize) {
261-
let result = global_ctx().shadow_heap().load_prov(address);
267+
let result = (*global_ctx()).shadow_heap().load_prov(address);
262268
*prov = result;
263269
}
264270

265271
/// Stores the given provenance value into shadow memory at the location for the given address.
266272
#[no_mangle]
267273
unsafe extern "C" fn bsan_store_prov(provenance: *const Provenance, address: usize) {
268-
let heap = &(*global_ctx()).shadow_heap();
274+
let heap = (*global_ctx()).shadow_heap();
269275
heap.store_prov(provenance, address);
270276
}
271277
/// Pushes a shadow stack frame

src/tools/bsan/bsan-rt/src/shadow.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ pub struct ShadowHeap<T> {
134134
l1: L1<T>,
135135
}
136136

137-
impl<T: Default + Copy> Default for ShadowHeap<T> {
137+
impl<T> Default for ShadowHeap<T> {
138138
fn default() -> Self {
139-
Self { l1: unsafe { L1::new(global_ctx().hooks()) } }
139+
Self { l1: unsafe { L1::new((*global_ctx()).hooks()) } }
140140
}
141141
}
142142

@@ -146,7 +146,8 @@ impl<T> ShadowHeap<T> {
146146
}
147147
}
148148

149-
impl<T: Default + Copy> ShadowHeap<T> {
149+
impl<T : Default + Copy> ShadowHeap<T> {
150+
150151
pub unsafe fn load_prov(&self, address: usize) -> T {
151152
let (l1_addr, l2_addr) = table_indices(address);
152153
let mut l2 = (*self.l1.entries)[l1_addr];
@@ -165,7 +166,7 @@ impl<T: Default + Copy> ShadowHeap<T> {
165166
let mut l2 = (*self.l1.entries)[l1_addr];
166167
if l2.is_null() {
167168
let l2_addr = unsafe { (*self.l1.entries).as_ptr().add(l1_addr) as *mut c_void };
168-
l2 = &mut L2::new(global_ctx().hooks(), l2_addr);
169+
l2 = &mut L2::new((*global_ctx()).hooks(), l2_addr);
169170
(*self.l1.entries)[l1_addr] = l2;
170171
}
171172

0 commit comments

Comments
 (0)