Skip to content

Commit f89d837

Browse files
wip: Add quick_exit test
This reproduces the bug in rust-osdev#917
1 parent a07e961 commit f89d837

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![no_std]
2+
#![no_main]
3+
4+
use uefi::prelude::*;
5+
6+
#[entry]
7+
fn main(image_handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
8+
uefi_services::init(&mut system_table).unwrap();
9+
Status::SUCCESS
10+
}

uefi-test-runner/src/bin/shell_launcher.rs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ use uefi::proto::device_path::build::{self, DevicePathBuilder};
1818
use uefi::proto::device_path::{DevicePath, DeviceSubType, DeviceType, LoadedImageDevicePath};
1919
use uefi::proto::loaded_image::LoadedImage;
2020
use uefi::table::boot::LoadImageSource;
21-
use uefi::Status;
21+
use uefi::{CStr16, Status};
2222

23-
/// Get the device path of the shell app. This is the same as the
23+
/// Get the device path of another app. This is the same as the
2424
/// currently-loaded image's device path, but with the file path part changed.
25-
fn get_shell_app_device_path<'a>(
25+
fn get_app_device_path<'a>(
2626
boot_services: &BootServices,
2727
storage: &'a mut Vec<u8>,
28+
file_path: &CStr16,
2829
) -> &'a DevicePath {
2930
let loaded_image_device_path = boot_services
3031
.open_protocol_exclusive::<LoadedImageDevicePath>(boot_services.image_handle())
@@ -39,19 +40,46 @@ fn get_shell_app_device_path<'a>(
3940
}
4041
builder = builder
4142
.push(&build::media::FilePath {
42-
path_name: cstr16!(r"efi\boot\shell.efi"),
43+
path_name: file_path,
4344
})
4445
.unwrap();
4546
builder.finalize().unwrap()
4647
}
4748

49+
fn run_quick_exit(boot_services: &BootServices) {
50+
let mut storage = Vec::new();
51+
let child_image_path = get_app_device_path(
52+
boot_services,
53+
&mut storage,
54+
cstr16!(r"efi\boot\quick_exit.efi"),
55+
);
56+
57+
let child_image_handle = boot_services
58+
.load_image(
59+
boot_services.image_handle(),
60+
LoadImageSource::FromDevicePath {
61+
device_path: child_image_path,
62+
from_boot_manager: false,
63+
},
64+
)
65+
.expect("failed to load quick-exit app");
66+
67+
info!("launching the quick-exit app");
68+
boot_services
69+
.start_image(child_image_handle)
70+
.expect("failed to launch the quick-exit app");
71+
}
72+
4873
#[entry]
4974
fn efi_main(image: Handle, mut st: SystemTable<Boot>) -> Status {
5075
uefi_services::init(&mut st).unwrap();
5176
let boot_services = st.boot_services();
5277

5378
let mut storage = Vec::new();
54-
let shell_image_path = get_shell_app_device_path(boot_services, &mut storage);
79+
let shell_image_path =
80+
get_app_device_path(boot_services, &mut storage, cstr16!(r"efi\boot\shell.efi"));
81+
82+
run_quick_exit(boot_services);
5583

5684
// Load the shell app.
5785
let shell_image_handle = boot_services

xtask/src/qemu.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,11 @@ fn build_esp_dir(opt: &QemuOpt, ovmf_paths: &OvmfPaths) -> Result<PathBuf> {
421421

422422
fs_err::copy(&ovmf_paths.shell, boot_dir.join("shell.efi"))?;
423423

424+
fs_err::copy(
425+
build_dir.join("quick_exit.efi"),
426+
boot_dir.join("quick_exit.efi"),
427+
)?;
428+
424429
let test_runner = build_dir.join("uefi-test-runner.efi");
425430
fs_err::copy(test_runner, boot_dir.join("test_runner.efi"))?;
426431
};

0 commit comments

Comments
 (0)