- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 182
 
Closed
Description
Right now, accessing any of the fundamental UEFI tables is very annoying and sometimes leads to annoying lifetime issues.
Apps either have to resort to passing a st/bs/rt reference around everywhere or have to resort to the un-ergonomic (because it's unsafe and doesn't even return a proper reference) system_table() from uefi-services. The former isn't even viable if implementing an API/protocol with fixed function signatures.
There are two things to note:
BootServices/RuntimeServicesare really just a list of global functions. The only reason they are provided throughSystemTableis because UEFI isn't a hosted environment with dynamic linking.- No functions in them take a 
thispointer. 
I propose the API to be changed such that:
- The application's entry-point is changed to a simple 
fn main() -> Resultsignature. The#[entry](which I would prefer renamed toefi_main) provides the real entry-point internally, stores theSystemTableand image handle somewhere, and calls into the marked main function. On return, it does the right thing(tm) with theResult(print out a message and return status code). - All functions in 
BootServices/RuntimeServicesare changed to associated functions that access the global table pointer internally. As they don't take athispointer, they are just global functions as is basically done in EDK2 (well, they provide a global pointer to the table struct, same difference). It's more ergonomic and will eliminate some annoying lifetime issues. It also obviates the need for some structs likeScopedProtocolto keep a ref to the table. - To protect against use after exiting boot services, the 
BootServicestable pointer can be replaced by the exit handler with aNoneor replaced with a custom implementation that panics if actually used. - Access to stdin/stdout/stderr should be provided via associated functions from the 
Input/Outputtypes (and panic after boot services exit). - An associated function would be provided to get direct access to the tables if needed.
 - This would also remove the need for a 
ViewonSystemTable: any members that go away should beOptions and set toNoneonce boot services are exited by the exit handler. (In fact, the UEFI spec recommends doing so.) 
Metadata
Metadata
Assignees
Labels
No labels