Skip to content
Closed
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
35 changes: 35 additions & 0 deletions pixie-uefi/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pixie-uefi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ postcard = { version = "1.1.3", default-features = false, features = ["alloc"] }
rand = { version = "0.8.5", default-features = false }
rand_xoshiro = { version = "0.6.0", default-features = false }
smoltcp = { version = "0.12.0", default-features = false, features = ["alloc", "proto-ipv4", "medium-ethernet", "socket-udp", "socket-tcp", "socket-dhcpv4", "async", "socket-tcp-cubic"] }
uefi = { version = "0.33.0", features = ["alloc", "global_allocator", "panic_handler"] }
spin = "0.10.0"
talc = { version = "4.4.3", default-features = false, features = ["lock_api"] }
uefi = { version = "0.33.0", features = ["panic_handler", "alloc"] }

[dependencies.pixie-shared]
path = "../pixie-shared"
Expand Down
37 changes: 37 additions & 0 deletions pixie-uefi/src/os/allocator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use talc::*;
use uefi::boot::MemoryType;

const MAX_BLOCK_SIZE: usize = 1 << 30;

struct AllocOnOom {
next_block_size: usize,
}

impl OomHandler for AllocOnOom {
fn handle_oom(talc: &mut Talc<Self>, layout: core::alloc::Layout) -> Result<(), ()> {
let bs = talc.oom_handler.next_block_size;
talc.oom_handler.next_block_size =
(talc.oom_handler.next_block_size * 2).min(MAX_BLOCK_SIZE);
match uefi::boot::allocate_pool(MemoryType::LOADER_DATA, bs) {
Err(e) => {
uefi::println!(
"Cannot allocate new block ({e}). Triggered by allocation {layout:?}"
);
Err(())
}
Ok(ptr) => {
let span = talc::Span::from_base_size(ptr.as_ptr(), bs);
// SAFETY: the memory was just allocated, so we have exclusive access to it
// and we can transfer ownership.
unsafe { talc.claim(span) }?;
Ok(())
}
}
}
}

#[global_allocator]
static ALLOCATOR: Talck<spin::Mutex<()>, AllocOnOom> = Talc::new(AllocOnOom {
next_block_size: 1 << 20,
})
.lock();
1 change: 1 addition & 0 deletions pixie-uefi/src/os/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use uefi::{
CStr16, Event, Handle, Status,
};

mod allocator;
mod boot_options;
pub mod disk;
pub mod error;
Expand Down