Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove heap allocation #21

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 7 additions & 27 deletions src/gop_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![allow(unused)]

use std::prelude::*;
use std::uefi::boot::InterfaceType;
use std::uefi::memory::PhysicalAddress;

static VBT: &[u8] = include_bytes!(env!("FIRMWARE_OPEN_VBT"));
Expand Down Expand Up @@ -72,29 +71,10 @@ extern "efiapi" fn GetPlatformDockStatus(_CurrentDockStatus: DockStatus) -> Stat
Status::UNSUPPORTED
}

impl GopPolicy {
pub fn new() -> Box<Self> {
Box::new(Self {
Revision: Self::REVISION_03,
GetPlatformLidStatus,
GetVbtData,
GetPlatformDockStatus,
GopOverrideGuid: Guid::NULL,
})
}

pub fn install(self: Box<Self>) -> Result<()> {
let uefi = unsafe { std::system_table_mut() };

let self_ptr = Box::into_raw(self);
let mut handle = Handle(0);
Result::from((uefi.BootServices.InstallProtocolInterface)(
&mut handle,
&Self::GUID,
InterfaceType::Native,
self_ptr as usize,
))?;

Ok(())
}
}
pub static GOP_POLICY: GopPolicy = GopPolicy {
Revision: GopPolicy::REVISION_03,
GetPlatformLidStatus,
GetVbtData,
GetPlatformDockStatus,
GopOverrideGuid: Guid::NULL,
};
23 changes: 13 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
#![no_std]
#![no_main]

#[macro_use]
extern crate uefi_std as std;

use std::prelude::*;

mod gop_policy;

use gop_policy::{GopPolicy, GOP_POLICY};
use std::prelude::*;
use std::uefi::boot::InterfaceType;

#[no_mangle]
pub extern "C" fn main() -> Status {
let gop_policy = gop_policy::GopPolicy::new();
if let Err(err) = gop_policy.install() {
println!("GopPolicy error: {:?}", err);
err
} else {
Status::SUCCESS
}
let uefi = unsafe { std::system_table_mut() };
let mut handle = Handle(0);

(uefi.BootServices.InstallProtocolInterface)(
&mut handle,
&GopPolicy::GUID,
InterfaceType::Native,
core::ptr::addr_of!(GOP_POLICY) as usize,
)
}