-
Notifications
You must be signed in to change notification settings - Fork 2
/
system.patch
57 lines (52 loc) · 2.05 KB
/
system.patch
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
diff --git a/sgx_alloc/src/system.rs b/sgx_alloc/src/system.rs
index 3d33f041..7f3e4f98 100644
--- a/sgx_alloc/src/system.rs
+++ b/sgx_alloc/src/system.rs
@@ -19,7 +19,7 @@
use core::alloc::{AllocError, Allocator, GlobalAlloc, Layout};
use core::intrinsics;
-use core::ptr::{self, NonNull};
+use core::ptr::{self, NonNull, write_bytes};
// The minimum alignment guaranteed by the architecture. This value is used to
// add fast paths for low alignment values. In practice, the alignment is a
@@ -115,6 +115,8 @@ unsafe impl Allocator for System {
#[inline]
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
if layout.size() != 0 {
+ // Clear previous allocated memory space.
+ write_bytes(ptr.as_ptr(), 0, layout.size());
// SAFETY: `layout` is non-zero in size,
// other conditions must be upheld by the caller
GlobalAlloc::dealloc(self, ptr.as_ptr(), layout)
@@ -218,6 +220,7 @@ mod platform {
use core::alloc::{GlobalAlloc, Layout};
use core::ffi::c_void;
use core::ptr;
+ use core::ptr::write_bytes;
unsafe impl GlobalAlloc for System {
#[inline]
@@ -229,6 +232,14 @@ mod platform {
}
}
+ #[inline]
+ unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
+ // Modified global allocator: ensure all the heap memory is fully cleared.
+ write_bytes(ptr, 0, _layout.size());
+
+ libc::free(ptr as *mut c_void)
+ }
+
#[inline]
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() {
@@ -242,11 +253,6 @@ mod platform {
}
}
- #[inline]
- unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
- libc::free(ptr as *mut c_void)
- }
-
#[inline]
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
if layout.align() <= MIN_ALIGN && layout.align() <= new_size {