-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add Rust std support for x86_64-unknown-uefi #100316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f872477
2be029d
ff55531
b988418
2800931
868e3e1
6769cb5
a14d62e
289c445
645647d
3e891b3
5689d37
372f6e1
65849ae
ebc5ca2
d5e78bf
368ab5a
ce43ad6
72641b8
95e8f68
aa980a6
3d9a83b
767650c
4f32221
0bb8203
e85df7a
1f52c23
d84c8e3
3bf5104
176361a
88c615c
8cd315c
4bc53e3
c257c00
7262c22
36c628f
73852ec
d610cde
3702334
c4320c1
944bf59
c83cbd2
a95933b
3df71e6
545899b
945049c
1baa38f
a9c1bb8
939e11e
67329ff
2345867
d343822
dae6b19
195633a
4f7ff72
77283ae
f89fceb
000228b
d48d07d
824f067
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,57 @@ | ||||||||||
//! UEFI-specific extensions to the primitives in `std::env` module | ||||||||||
|
||||||||||
use crate::ffi::c_void; | ||||||||||
use crate::ptr::NonNull; | ||||||||||
use crate::sync::atomic::{AtomicPtr, Ordering}; | ||||||||||
use crate::sync::Once; | ||||||||||
|
||||||||||
static GLOBAL_SYSTEM_TABLE: AtomicPtr<c_void> = AtomicPtr::new(crate::ptr::null_mut()); | ||||||||||
static GLOBAL_IMAGE_HANDLE: AtomicPtr<c_void> = AtomicPtr::new(crate::ptr::null_mut()); | ||||||||||
pub(crate) static GLOBALS: Once = Once::new(); | ||||||||||
Comment on lines
+8
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, I'm not sure if using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I catch your meaning here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was referring to the |
||||||||||
|
||||||||||
/// Initializes the global System Table and Image Handle pointers. | ||||||||||
/// | ||||||||||
/// The standard library requires access to the UEFI System Table and the Application Image Handle | ||||||||||
/// to operate. Those are provided to UEFI Applications via their application entry point. By | ||||||||||
/// calling `init_globals()`, those pointers are retained by the standard library for future use. | ||||||||||
/// The pointers are never exposed to any entity outside of this application and it is guaranteed | ||||||||||
/// that, once the application exited, these pointers are never dereferenced again. | ||||||||||
/// | ||||||||||
/// Callers are required to ensure the pointers are valid for the entire lifetime of this | ||||||||||
/// application. In particular, UEFI Boot Services must not be exited while an application with the | ||||||||||
/// standard library is loaded. | ||||||||||
/// | ||||||||||
/// This function must not be called more than once. | ||||||||||
#[unstable(feature = "uefi_std", issue = "100499")] | ||||||||||
pub unsafe fn init_globals(handle: NonNull<c_void>, system_table: NonNull<c_void>) { | ||||||||||
GLOBALS.call_once(|| { | ||||||||||
GLOBAL_SYSTEM_TABLE.store(system_table.as_ptr(), Ordering::Release); | ||||||||||
GLOBAL_IMAGE_HANDLE.store(handle.as_ptr(), Ordering::Release); | ||||||||||
}) | ||||||||||
} | ||||||||||
|
||||||||||
/// Get the SystemTable Pointer. | ||||||||||
/// Note: This function panics if the System Table and Image Handle is Not initialized | ||||||||||
#[unstable(feature = "uefi_std", issue = "100499")] | ||||||||||
pub fn system_table() -> NonNull<c_void> { | ||||||||||
try_system_table().unwrap() | ||||||||||
} | ||||||||||
|
||||||||||
/// Get the SystemHandle Pointer. | ||||||||||
/// Note: This function panics if the System Table and Image Handle is Not initialized | ||||||||||
#[unstable(feature = "uefi_std", issue = "100499")] | ||||||||||
pub fn image_handle() -> NonNull<c_void> { | ||||||||||
try_image_handle().unwrap() | ||||||||||
} | ||||||||||
|
||||||||||
/// Get the SystemTable Pointer. | ||||||||||
/// This function is mostly intended for places where panic is not an option | ||||||||||
pub(crate) fn try_system_table() -> Option<NonNull<crate::ffi::c_void>> { | ||||||||||
NonNull::new(GLOBAL_SYSTEM_TABLE.load(Ordering::Acquire)) | ||||||||||
} | ||||||||||
|
||||||||||
/// Get the SystemHandle Pointer. | ||||||||||
/// This function is mostly intended for places where panic is not an option | ||||||||||
pub(crate) fn try_image_handle() -> Option<NonNull<crate::ffi::c_void>> { | ||||||||||
NonNull::new(GLOBAL_IMAGE_HANDLE.load(Ordering::Acquire)) | ||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//! Platform-specific extensions to `std` for UEFI. | ||
|
||
#![unstable(feature = "uefi_std", issue = "100499")] | ||
|
||
pub mod env; | ||
#[path = "../windows/ffi.rs"] | ||
pub mod ffi; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//! Global Allocator for UEFI. | ||
//! Uses [r-efi-alloc](https://crates.io/crates/r-efi-alloc) | ||
|
||
use crate::alloc::{handle_alloc_error, GlobalAlloc, Layout, System}; | ||
|
||
pub(crate) const POOL_ALIGNMENT: usize = 8; | ||
|
||
const MEMORY_TYPE: u32 = r_efi::efi::LOADER_DATA; | ||
|
||
#[stable(feature = "alloc_system_type", since = "1.28.0")] | ||
unsafe impl GlobalAlloc for System { | ||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 { | ||
let system_table = match crate::os::uefi::env::try_system_table() { | ||
None => return crate::ptr::null_mut(), | ||
Some(x) => x.as_ptr() as *mut _, | ||
}; | ||
|
||
if layout.size() > 0 { | ||
unsafe { r_efi_alloc::raw::alloc(system_table, layout, MEMORY_TYPE) } | ||
} else { | ||
layout.dangling().as_ptr() | ||
} | ||
} | ||
|
||
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { | ||
let system_table = match crate::os::uefi::env::try_system_table() { | ||
None => handle_alloc_error(layout), | ||
Some(x) => x.as_ptr() as *mut _, | ||
}; | ||
if layout.size() > 0 { | ||
unsafe { r_efi_alloc::raw::dealloc(system_table, ptr, layout) } | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.