- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
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(); | ||||||||||
|          | ||||||||||
| 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(); | |
| pub(crate) static GLOBALS: OnceLock<(NonNull<c_void>, NonNull<c_void>)> = OnceLock::new(); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I'm not sure if using NonNull instead of AtomicPtr is correct here. It is technically possible for some other driver to change the underlying System Table and thus atomic operations seem to make more sense to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I catch your meaning here? NonNull does not mandate that the underlying data stays constant, so it should be fine to use even if that situation arises.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was referring to the AtomicPtr::load() operation since there will be multiple pointers to SystemTable floating around even in Rust code simultaneously.
| 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.