Skip to content

Commit fcb3d0d

Browse files
author
Jethro Beekman
committed
Expose alloc/dealloc properly for SGX libunwind
1 parent 33b0b71 commit fcb3d0d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/libstd/sys/sgx/rwlock.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use alloc::{self, Layout};
12
use num::NonZeroUsize;
23
use slice;
34
use str;
@@ -147,6 +148,7 @@ impl RWLock {
147148
self.__write_unlock(rguard, wguard);
148149
}
149150

151+
// only used by __rust_rwlock_unlock below
150152
#[inline]
151153
unsafe fn unlock(&self) {
152154
let rguard = self.readers.lock();
@@ -164,6 +166,7 @@ impl RWLock {
164166

165167
const EINVAL: i32 = 22;
166168

169+
// used by libunwind port
167170
#[no_mangle]
168171
pub unsafe extern "C" fn __rust_rwlock_rdlock(p: *mut RWLock) -> i32 {
169172
if p.is_null() {
@@ -190,6 +193,8 @@ pub unsafe extern "C" fn __rust_rwlock_unlock(p: *mut RWLock) -> i32 {
190193
return 0;
191194
}
192195

196+
// the following functions are also used by the libunwind port. They're
197+
// included here to make sure parallel codegen and LTO don't mess things up.
193198
#[no_mangle]
194199
pub unsafe extern "C" fn __rust_print_err(m: *mut u8, s: i32) {
195200
if s < 0 {
@@ -206,6 +211,16 @@ pub unsafe extern "C" fn __rust_abort() {
206211
::sys::abort_internal();
207212
}
208213

214+
#[no_mangle]
215+
pub unsafe extern "C" fn __rust_c_alloc(size: usize, align: usize) -> *mut u8 {
216+
alloc::alloc(Layout::from_size_align_unchecked(size, align))
217+
}
218+
219+
#[no_mangle]
220+
pub unsafe extern "C" fn __rust_c_dealloc(ptr: *mut u8, size: usize, align: usize) {
221+
alloc::dealloc(ptr, Layout::from_size_align_unchecked(size, align))
222+
}
223+
209224
#[cfg(test)]
210225
mod tests {
211226

0 commit comments

Comments
 (0)