Skip to content

Commit 753536a

Browse files
committed
std: uefi: Use common function for UEFI shell
- Since in almost all cases, there will only be 1 UEFI shell, share the shell handle between all functions that require it. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
1 parent 588bfb4 commit 753536a

1 file changed

Lines changed: 2 additions & 36 deletions

File tree

  • library/std/src/sys/pal/uefi

‎library/std/src/sys/pal/uefi/os.rs‎

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ pub fn error_string(errno: RawOsError) -> String {
125125
}
126126

127127
pubfngetcwd() -> io::Result<PathBuf>{
128-
matchuefi_shell::open_shell(){
128+
matchhelpers::open_shell(){
129129
Some(shell) => {
130130
// SAFETY: path_ptr is managed by UEFI shell and should not be deallocated
131131
let path_ptr = unsafe{((*shell.as_ptr()).get_cur_dir)(crate::ptr::null_mut())};
@@ -144,7 +144,7 @@ pub fn getcwd() -> io::Result<PathBuf> {
144144
}
145145

146146
pubfnchdir(p:&path::Path) -> io::Result<()>{
147-
let shell = uefi_shell::open_shell().ok_or(unsupported_err())?;
147+
let shell = helpers::open_shell().ok_or(unsupported_err())?;
148148

149149
letmut p = helpers::os_string_to_raw(p.as_os_str())
150150
.ok_or(io::const_io_error!(io::ErrorKind::InvalidData,"Invalid path"))?;
@@ -275,40 +275,6 @@ pub fn getpid() -> u32 {
275275
panic!("no pids on this platform")
276276
}
277277

278-
mod uefi_shell {
279-
use r_efi::protocols::shell;
280-
281-
usesuper::super::helpers;
282-
usecrate::ptr::NonNull;
283-
usecrate::sync::atomic::{AtomicPtr,Ordering};
284-
285-
pubfnopen_shell() -> Option<NonNull<shell::Protocol>>{
286-
staticLAST_VALID_HANDLE:AtomicPtr<crate::ffi::c_void> =
287-
AtomicPtr::new(crate::ptr::null_mut());
288-
289-
ifletSome(handle) = NonNull::new(LAST_VALID_HANDLE.load(Ordering::Acquire)){
290-
ifletOk(protocol) = helpers::open_protocol::<shell::Protocol>(
291-
handle,
292-
r_efi::protocols::shell::PROTOCOL_GUID,
293-
){
294-
returnSome(protocol);
295-
}
296-
}
297-
298-
let handles = helpers::locate_handles(shell::PROTOCOL_GUID).ok()?;
299-
for handle in handles {
300-
ifletOk(protocol) =
301-
helpers::open_protocol::<shell::Protocol>(handle, shell::PROTOCOL_GUID)
302-
{
303-
LAST_VALID_HANDLE.store(handle.as_ptr(),Ordering::Release);
304-
returnSome(protocol);
305-
}
306-
}
307-
308-
None
309-
}
310-
}
311-
312278
mod uefi_env {
313279
usecrate::ffi::{OsStr,OsString};
314280
usecrate::io;

0 commit comments

Comments
 (0)