diff options
| author | Ayush Singh <ayushsingh1325@gmail.com> | 2023-05-21 14:26:59 +0530 |
|---|---|---|
| committer | Ayush Singh <ayushdevel1325@gmail.com> | 2023-09-22 17:23:33 +0530 |
| commit | c7e5f3ca085c3adfd285a6d41080ff65a6299bc9 (patch) | |
| tree | 116df502759aa3ddff2b95e388736ba981c3ac7e /library/std/src/sys/uefi/helpers.rs | |
| parent | 40c3dacc767a4fbf42ea5dfa686a54acf9ded5fb (diff) | |
| download | rust-c7e5f3ca085c3adfd285a6d41080ff65a6299bc9.tar.gz rust-c7e5f3ca085c3adfd285a6d41080ff65a6299bc9.zip | |
Rebase to master
- Update Example - Add thread_parking to sys::uefi - Fix unsafe in unsafe errors - Improve docs - Improve os/exit - Some asserts - Switch back to atomics Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
Diffstat (limited to 'library/std/src/sys/uefi/helpers.rs')
| -rw-r--r-- | library/std/src/sys/uefi/helpers.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/library/std/src/sys/uefi/helpers.rs b/library/std/src/sys/uefi/helpers.rs index 2e1bcb36944..126661bfc96 100644 --- a/library/std/src/sys/uefi/helpers.rs +++ b/library/std/src/sys/uefi/helpers.rs @@ -60,13 +60,14 @@ pub(crate) fn locate_handles(mut guid: Guid) -> io::Result<Vec<NonNull<crate::ff } // The returned buf_len is in bytes - let mut buf: Vec<r_efi::efi::Handle> = - Vec::with_capacity(buf_len / size_of::<r_efi::efi::Handle>()); + assert_eq!(buf_len % size_of::<r_efi::efi::Handle>(), 0); + let num_of_handles = buf_len / size_of::<r_efi::efi::Handle>(); + let mut buf: Vec<r_efi::efi::Handle> = Vec::with_capacity(num_of_handles); match inner(&mut guid, boot_services, &mut buf_len, buf.as_mut_ptr()) { Ok(()) => { // This is safe because the call will succeed only if buf_len >= required length. // Also, on success, the `buf_len` is updated with the size of bufferv (in bytes) written - unsafe { buf.set_len(buf_len / size_of::<r_efi::efi::Handle>()) }; + unsafe { buf.set_len(num_of_handles) }; Ok(buf.into_iter().filter_map(|x| NonNull::new(x)).collect()) } Err(e) => Err(e), @@ -114,16 +115,15 @@ pub(crate) fn create_event( ) -> io::Result<NonNull<crate::ffi::c_void>> { let boot_services: NonNull<efi::BootServices> = boot_services().ok_or(BOOT_SERVICES_UNAVAILABLE)?.cast(); - let mut exit_boot_service_event: r_efi::efi::Event = crate::ptr::null_mut(); + 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 exit_boot_service_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(exit_boot_service_event) - .ok_or(const_io_error!(io::ErrorKind::Other, "null protocol")) + NonNull::new(event).ok_or(const_io_error!(io::ErrorKind::Other, "null protocol")) } } |
