Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
28bd22c
rustdoc: Gate unstable `doc(cfg())` predicates
clubby789 Mar 9, 2025
85b1116
rustdoc: Add FIXME test for `doc_cfg` interaction with `check_cfg`
clubby789 Mar 10, 2025
aa2c24b
uefi: Add OwnedEvent abstraction
Ayush1325 Mar 8, 2025
bcac931
Update test for SGX now implementing read_buf
thaliaarchi Mar 18, 2025
526a689
std: fs: uefi: Implement canonicalize
Ayush1325 Mar 18, 2025
456eedc
std: fs: uefi: Make lstat call stat
Ayush1325 Mar 18, 2025
80229a2
std: fs: uefi: Implement OpenOptions
Ayush1325 Mar 18, 2025
ec487bf
Test that `supported-crate-types` is `-Zunstable-options`-gated
jieyouxu Mar 18, 2025
83d3197
Add smoke test for `supported-crate-types` print request
jieyouxu Mar 18, 2025
e8cf087
Implement `supported-crate-types` print request
jieyouxu Mar 18, 2025
aafcdda
Document `supported-crate-types` print request in unstable book
jieyouxu Mar 18, 2025
675bfeb
Rebless tests with changed help due to new print request option
jieyouxu Mar 18, 2025
405d1c4
Adjust `rustc-print-info-issue-138612.rs`
jieyouxu Mar 21, 2025
b523301
Add test to ensure no index out of bounds panic (#135474)
reddevilmidzy Mar 14, 2025
c25e4bf
resolve: Avoid some unstable iteration 3
petrochenkov Mar 22, 2025
fa0c951
doc: rename reference #create-a-configtoml to #create-a-bootstraptoml
chiichen Mar 23, 2025
5950c86
Slim `rustc_parse_format` dependencies down
Veykril Mar 17, 2025
0b0773d
Rollup merge of #138236 - Ayush1325:uefi-event, r=petrochenkov
jieyouxu Mar 23, 2025
0631764
Rollup merge of #138293 - clubby789:doc-cfg-gate, r=GuillaumeGomez
jieyouxu Mar 23, 2025
21d89ff
Rollup merge of #138509 - reddevilmidzy:add-test, r=compiler-errors
jieyouxu Mar 23, 2025
16447db
Rollup merge of #138602 - Veykril:push-purxoytpktpu, r=SparrowLii
jieyouxu Mar 23, 2025
34892c1
Rollup merge of #138631 - thaliaarchi:sgx-read-buf-test, r=workingjub…
jieyouxu Mar 23, 2025
51e1840
Rollup merge of #138641 - jieyouxu:print-supported-crate-types, r=Urgau
jieyouxu Mar 23, 2025
22f8caa
Rollup merge of #138662 - Ayush1325:uefi-fs-1, r=nicholasbishop,petro…
jieyouxu Mar 23, 2025
7b54a2f
Rollup merge of #138837 - petrochenkov:resinstab2, r=jieyouxu
jieyouxu Mar 23, 2025
5c17679
Rollup merge of #138849 - chiichen:dev/master/doc-correct-configtoml,…
jieyouxu Mar 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 53 additions & 33 deletions library/std/src/sys/pal/uefi/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,39 +120,6 @@ pub(crate) fn open_protocol<T>(
}
}

pub(crate) fn create_event(
signal: u32,
tpl: efi::Tpl,
handler: Option<efi::EventNotify>,
context: *mut crate::ffi::c_void,
) -> io::Result<NonNull<crate::ffi::c_void>> {
let boot_services: NonNull<efi::BootServices> =
boot_services().ok_or(BOOT_SERVICES_UNAVAILABLE)?.cast();
let mut event: r_efi::efi::Event = crate::ptr::null_mut();
let r = unsafe {
let create_event = (*boot_services.as_ptr()).create_event;
(create_event)(signal, tpl, handler, context, &mut event)
};
if r.is_error() {
Err(crate::io::Error::from_raw_os_error(r.as_usize()))
} else {
NonNull::new(event).ok_or(const_error!(io::ErrorKind::Other, "null protocol"))
}
}

/// # SAFETY
/// - The supplied event must be valid
pub(crate) unsafe fn close_event(evt: NonNull<crate::ffi::c_void>) -> io::Result<()> {
let boot_services: NonNull<efi::BootServices> =
boot_services().ok_or(BOOT_SERVICES_UNAVAILABLE)?.cast();
let r = unsafe {
let close_event = (*boot_services.as_ptr()).close_event;
(close_event)(evt.as_ptr())
};

if r.is_error() { Err(crate::io::Error::from_raw_os_error(r.as_usize())) } else { Ok(()) }
}

/// Gets the Protocol for current system handle.
///
/// Note: Some protocols need to be manually freed. It is the caller's responsibility to do so.
Expand Down Expand Up @@ -735,3 +702,56 @@ impl Drop for ServiceProtocol {
}
}
}

#[repr(transparent)]
pub(crate) struct OwnedEvent(NonNull<crate::ffi::c_void>);

impl OwnedEvent {
pub(crate) fn new(
signal: u32,
tpl: efi::Tpl,
handler: Option<efi::EventNotify>,
context: Option<NonNull<crate::ffi::c_void>>,
) -> io::Result<Self> {
let boot_services: NonNull<efi::BootServices> =
boot_services().ok_or(BOOT_SERVICES_UNAVAILABLE)?.cast();
let mut event: r_efi::efi::Event = crate::ptr::null_mut();
let context = context.map(NonNull::as_ptr).unwrap_or(crate::ptr::null_mut());

let r = unsafe {
let create_event = (*boot_services.as_ptr()).create_event;
(create_event)(signal, tpl, handler, context, &mut event)
};

if r.is_error() {
Err(crate::io::Error::from_raw_os_error(r.as_usize()))
} else {
NonNull::new(event)
.ok_or(const_error!(io::ErrorKind::Other, "failed to create event"))
.map(Self)
}
}

pub(crate) fn into_raw(self) -> *mut crate::ffi::c_void {
let r = self.0.as_ptr();
crate::mem::forget(self);
r
}

/// SAFETY: Assumes that ptr is a non-null valid UEFI event
pub(crate) unsafe fn from_raw(ptr: *mut crate::ffi::c_void) -> Self {
Self(unsafe { NonNull::new_unchecked(ptr) })
}
}

impl Drop for OwnedEvent {
fn drop(&mut self) {
if let Some(boot_services) = boot_services() {
let bt: NonNull<r_efi::efi::BootServices> = boot_services.cast();
unsafe {
let close_event = (*bt.as_ptr()).close_event;
(close_event)(self.0.as_ptr())
};
}
}
}
10 changes: 5 additions & 5 deletions library/std/src/sys/pal/uefi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ pub(crate) unsafe fn init(argc: isize, argv: *const *const u8, _sigpipe: u8) {
unsafe { uefi::env::init_globals(image_handle, system_table) };

// Register exit boot services handler
match helpers::create_event(
match helpers::OwnedEvent::new(
r_efi::efi::EVT_SIGNAL_EXIT_BOOT_SERVICES,
r_efi::efi::TPL_NOTIFY,
Some(exit_boot_service_handler),
crate::ptr::null_mut(),
None,
) {
Ok(x) => {
if EXIT_BOOT_SERVICE_EVENT
.compare_exchange(
crate::ptr::null_mut(),
x.as_ptr(),
x.into_raw(),
Ordering::Release,
Ordering::Acquire,
)
Expand All @@ -77,7 +77,7 @@ pub unsafe fn cleanup() {
if let Some(exit_boot_service_event) =
NonNull::new(EXIT_BOOT_SERVICE_EVENT.swap(crate::ptr::null_mut(), Ordering::Acquire))
{
let _ = unsafe { helpers::close_event(exit_boot_service_event) };
let _ = unsafe { helpers::OwnedEvent::from_raw(exit_boot_service_event.as_ptr()) };
}
}

Expand Down Expand Up @@ -143,7 +143,7 @@ pub fn abort_internal() -> ! {
if let Some(exit_boot_service_event) =
NonNull::new(EXIT_BOOT_SERVICE_EVENT.load(Ordering::Acquire))
{
let _ = unsafe { helpers::close_event(exit_boot_service_event) };
let _ = unsafe { helpers::OwnedEvent::from_raw(exit_boot_service_event.as_ptr()) };
}

if let (Some(boot_services), Some(handle)) =
Expand Down