std: uefi: Use common function for UEFI shell · qinheping/verify-rust-std@c949985 (original) (raw)

`@@ -125,7 +125,7 @@ pub fn error_string(errno: RawOsError) -> String {

`

125

125

`}

`

126

126

``

127

127

`pub fn getcwd() -> io::Result {

`

128

``

`-

match uefi_shell::open_shell() {

`

``

128

`+

match helpers::open_shell() {

`

129

129

`Some(shell) => {

`

130

130

`// SAFETY: path_ptr is managed by UEFI shell and should not be deallocated

`

131

131

`let path_ptr = unsafe { ((*shell.as_ptr()).get_cur_dir)(crate::ptr::null_mut()) };

`

`@@ -144,7 +144,7 @@ pub fn getcwd() -> io::Result {

`

144

144

`}

`

145

145

``

146

146

`pub fn chdir(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())?;

`

148

148

``

149

149

`let mut p = helpers::os_string_to_raw(p.as_os_str())

`

150

150

`.ok_or(io::const_io_error!(io::ErrorKind::InvalidData, "Invalid path"))?;

`

`@@ -275,40 +275,6 @@ pub fn getpid() -> u32 {

`

275

275

`panic!("no pids on this platform")

`

276

276

`}

`

277

277

``

278

``

`-

mod uefi_shell {

`

279

``

`-

use r_efi::protocols::shell;

`

280

``

-

281

``

`-

use super::super::helpers;

`

282

``

`-

use crate::ptr::NonNull;

`

283

``

`-

use crate::sync::atomic::{AtomicPtr, Ordering};

`

284

``

-

285

``

`-

pub fn open_shell() -> Option<NonNullshell::Protocol> {

`

286

``

`-

static LAST_VALID_HANDLE: AtomicPtrcrate::ffi::c_void =

`

287

``

`-

AtomicPtr::new(crate::ptr::null_mut());

`

288

``

-

289

``

`-

if let Some(handle) = NonNull::new(LAST_VALID_HANDLE.load(Ordering::Acquire)) {

`

290

``

`-

if let Ok(protocol) = helpers::open_protocol::shell::Protocol(

`

291

``

`-

handle,

`

292

``

`-

r_efi::protocols:🐚:PROTOCOL_GUID,

`

293

``

`-

) {

`

294

``

`-

return Some(protocol);

`

295

``

`-

}

`

296

``

`-

}

`

297

``

-

298

``

`-

let handles = helpers::locate_handles(shell::PROTOCOL_GUID).ok()?;

`

299

``

`-

for handle in handles {

`

300

``

`-

if let Ok(protocol) =

`

301

``

`-

helpers::open_protocol::shell::Protocol(handle, shell::PROTOCOL_GUID)

`

302

``

`-

{

`

303

``

`-

LAST_VALID_HANDLE.store(handle.as_ptr(), Ordering::Release);

`

304

``

`-

return Some(protocol);

`

305

``

`-

}

`

306

``

`-

}

`

307

``

-

308

``

`-

None

`

309

``

`-

}

`

310

``

`-

}

`

311

``

-

312

278

`mod uefi_env {

`

313

279

`use crate::ffi::{OsStr, OsString};

`

314

280

`use crate::io;

`