Repository navigation
Tracking Issue for uefi-std #100499
Copy link
Copy link
Open
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCO-UEFIUEFIUEFIT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Description
Feature gate: #![feature(uefi_std)]
This is a tracking issue for Std support for UEFI environment. I have been working on implementing this as a part of my Google Summer of Code 2022 project. Information about the current state of this implementation can be found at src/doc/rustc/src/platform-support/unknown-uefi.md. A PR has already been opened here
For those who are wondering how a target like UEFI can benefit from std support, here are a few examples:
- Writing UEFI shell applications. This includes stuff like benchmarks, self-test utilities, etc. Many drivers should also be able to use std.
- Finding UEFI target bugs. During this work, I have found 3 numeric tests that cause CPU exceptions for UEFI (they are fixed now. Also, I have found 2 additional bugs (which seem like bugs in llvm soft-float) which went unnoticed because there was no easy way to do any broad testing.
- Provide a stable interface for library developers. The current std contains some functions under std::os::uefi::env to provide access to the underlying SystemTable and SystemHandle, which are essential for writing anything for UEFI.
Public API
APIs I propose to add under std::os::uefi::env:
pub fn get_system_table() -> NonNull<c_void>pub fn get_system_handle() -> NonNull<c_void>pub fn boot_services() -> Option<NonNull<c_void>>
APIs I propose to add under std::os::uefi::ffi (Just re-export std::os::windows::ffi)
- trait
OsStrExt - trait
OsStringExt
Implementation History
- Add Minimal Std implementation for UEFI #105861
- Stdio support for UEFI #116207
- Implement sys::args for UEFI #116341
- Improve UEFI stdio #117174
- Use ImageDataType for allocation type #117177
- Implement SystemTime for UEFI #120351
- Expand sys/os for UEFI #120419
- Mark UEFI std support as WIP #120640
- Implement Instant for UEFI #120889
- Implement sys/thread for UEFI #120938
- Add Process support for UEFI #123196
- std: uefi: Add basic Env variables #127462
- uefi: Implement getcwd and chdir #129794
- uefi: process: Add args support #129838
- Initial fs module for uefi #135324
- uefi: fs: Implement exists #135368
- uefi: helpers: Introduce OwnedDevicePath #135393
- uefi: Implement path #135475
- uefi: process: Add support for command environment variables #136418
- sys: net: Add UEFI stubs #136615
- uefi: helpers: Add DevicePathNode abstractions #137424
- uefi: Add Service Binding Protocol abstraction #137477
- uefi: fs: Implement FileType, FilePermissions and FileAttr #138269
- uefi: Add OwnedEvent abstraction #138236
- Implement some basics in UEFI fs #138662
- std: uefi: fs: Implement mkdir #138667
- uefi: fs: Add file times plumbing #138918
- std: sys: net: uefi: Implement TCP4 connect #139254
- std: sys: process: uefi: Use NULL stdin by default #139517
- std: sys: pal: uefi: Overhaul Time #139806
- std: sys: net: uefi: tcp4: Implement write #141532
- std: sys: random: uefi: Provide rdrand based fallback #141324
- std: sys: net: uefi: tcp4: Implement read #143470
- std: sys: net: uefi: tcp4: Add timeout support #143568
- std: net: uefi: Add support to query connection data #143838
- std: sys: io: io_slice: Add UEFI types #144350
- std: sys: net: uefi: tcp: Initial TcpListener support #145339
- library: std: sys: net: uefi: tcp: Implement write_vectored #146301
- std: sys: fs: uefi: Implement stat #148970
- std: sys: fs: uefi: Implement rmdir and unlink #149064
- std: sys: net: uefi: Implement read_vectored #149134
- std: sys: fs: uefi: Implement set_times and set_perm #149459
- std: sys: fs: uefi: Make time in FileAttr optional #149538
- std: sys: fs: uefi: Implement readdir #149540
- std: sys: fs: uefi: Implement initial File #150475
- std: sys: fs: uefi: Ignore "." and ".." when reading directory #150516
- std: sys: fs: uefi: Implement remove_dir_all #150533
- std: sys: fs: uefi: Implement rename #150547
- std: sys: fs: uefi: Implement File::write #150852
- std: sys: fs: uefi: Implement File::read #150853
- std: sys: fs: uefi: Implement File::tell #150855
- std: sys: fs: uefi: Implement File::flush #150862
- std: sys: fs: uefi: Implement File::seek #150918
- std: sys: fs: uefi: Implement copy #150953
- std: sys: uefi: os: Implement join_paths #150993
- std: sys: process: uefi: Add program searching #151014
- std: sys: pal: uefi: os: Implement split_paths #151991
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCO-UEFIUEFIUEFIT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Activity
6 remaining items
Ayush1325 commentedon Oct 22, 2023
@medhefgo, The main target for uefi-std, is uefi applications. That being said, I am not opposed to expanding it's scope as long as it is not detrimental to the main target.
Do you mean using
EFI_LOADED_IMAGE_PROTOCOL->ImageDataTypeto decide the memory type? I am not too familiar with it's usage so maybe @dvdhrm and @nicholasbishop can provide insight if it can be used?One thing to note is that some allocations take place between
sys::initand usermain. That is the main reason for not providing an endpoint underos::*for setting the allocation type.medhefgo commentedon Oct 22, 2023
It would be nice if boot drivers could be supported as they are not too different from apps. Runtime drivers are probably too niche and probably have too many pitfalls in it.
The main question is what the rust entry point machinery expects: For EFI drivers to be any useful they have to return from main with success code without tearing down anything. The code will continue to be called as needed by the firmware. The real exit tear-down would be handled by the exit handler that would be registered on
EFI_LOADED_IMAGE_PROTOCOL.If the rust machinery cannot handle that setup, it should definitely be documented that only EFI apps are possible as std target.
Yes.
nicholasbishop commentedon Oct 24, 2023
Using
ImageDataTypefor the memory type sounds good to me, and agree it would be good to document in the target docs exactly which executable types are intended to be supported by uefi-std.Rollup merge of rust-lang#117177 - Ayush1325:uefi-alloc-type, r=worki…
Unrolled build for rust-lang#117177
nicholasbishop commentedon Nov 4, 2023
@Ayush1325 I have a question about the feature gate described here,
#.It doesn't look to me like that feature actually exists. It's used in a couple places under
library/std/src/os/uefi/, but it's not defined incompiler/rustc_feature/src/(see https://rustc-dev-guide.rust-lang.org/implementing_new_features.html#stability-in-code for details how how a feature should be defined).It seems that right now, even without that feature, I can build a UEFI
stdprogram on nightly:I'm not sure if that's intended right now, since std on UEFI hasn't been stabilized as far as I know? The UEFI targets are tier 2 though, so maybe it's fine? I'm not actually sure what the intended policy here is :)
Ayush1325 commentedon Nov 4, 2023
@nicholasbishop As far as I understand it,
uefi_stdfeature only needs to be enabled if you usestd::os::uefi::*stuff, not general std. If you try using it without enabling the feature, you get the following error:On further inspection, I think that link is only for language features. Here is the link for library features: https://rustc-dev-guide.rust-lang.org/stability.html. I think everything required is already present.
Zekirax commentedon Feb 2, 2025
println don't write a new line. For new line it needs \r. Do we just add \r at the end, or is it worth it of modifying this macro ? I think println add a \n here.
Ayush1325 commentedon Feb 2, 2025
I think I had this discussion in the past, and the reason for not adding
\rwas that since UEFI shell also has pipes, piping to a file will become inconsistent (since we are adding an extra character).Additionally, do note that some UEFI shell tools do seem to work fine with just
\n(pipe output to a file and then use cat on it), so it seems like just LF is fine for files.t3kkm0tt commentedon May 15, 2026
Is it possible to let the user type things and get that into a String using
std::io::stdin().read_line(&mut input)?Ayush1325 commentedon May 15, 2026
Reading exact characters does work. But not sure if read_line works. If I remember correctly, read_line expects
\nand UEFI gives\ron enter (on OVMF at least. other UEFI implementations might give something else). But I have not tested it recently since well, I am not using rust UEFI in my current work. Maybe just try it?t3kkm0tt commentedon May 15, 2026
Yeah, I got it to work with read_char from the uefi crate.