mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
Add runtime detection for shared handle misuse wrap the FFI engine handle with parking_lot::RwLock when the new contention_checks feature is enabled, surfacing a clear “handle is already in use” error instead of allowing undefined behavior keep the feature optional so no_std builds or environments that supply their own synchronization can opt out caution users that this guards the handle itself but does not make the engine’s operations globally thread-safe on its own Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
32 lines
851 B
Rust
32 lines
851 B
Rust
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT License.
|
|
|
|
#[cfg(feature = "custom_allocator")]
|
|
extern "C" {
|
|
fn regorus_aligned_alloc(alignment: usize, size: usize) -> *mut u8;
|
|
fn regorus_free(ptr: *mut u8);
|
|
}
|
|
|
|
#[cfg(feature = "custom_allocator")]
|
|
mod allocator {
|
|
use core::alloc::{GlobalAlloc, Layout};
|
|
|
|
struct RegorusAllocator {}
|
|
|
|
unsafe impl GlobalAlloc for RegorusAllocator {
|
|
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
|
let size = layout.size();
|
|
let align = layout.align();
|
|
|
|
crate::allocator::regorus_aligned_alloc(align, size)
|
|
}
|
|
|
|
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
|
|
crate::allocator::regorus_free(ptr)
|
|
}
|
|
}
|
|
|
|
#[global_allocator]
|
|
static ALLOCATOR: RegorusAllocator = RegorusAllocator {};
|
|
}
|