Skip to content

Commit 62f9772

Browse files
josephlrrbradford
authored andcommitted
efi/alloc: Don't use lazy_static for ALLOCATOR
This was done by removing depenance on `Default` and just manually implementing a `const fn` `Allocator::new()`. This now allows us to remove lazy_static as dependancy entirely. Signed-off-by: Joe Richey <[email protected]>
1 parent a5a68fe commit 62f9772

File tree

4 files changed

+19
-25
lines changed

4 files changed

+19
-25
lines changed

Cargo.lock

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,3 @@ cpuio = "*"
2828
spin = "0.5"
2929
r-efi = "2.1.0"
3030

31-
[dependencies.lazy_static]
32-
version = "1.0"
33-
features = ["spin_no_std"]
34-

src/efi/alloc.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use r_efi::efi::{AllocateType, MemoryType, PhysicalAddress, Status, VirtualAddre
1818

1919
// Copied from r_efi so we can do Default on it
2020
#[repr(C)]
21-
#[derive(Debug, Default, Clone)]
21+
#[derive(Debug, Copy, Clone)]
2222
pub struct MemoryDescriptor {
2323
pub r#type: u32,
2424
pub physical_start: PhysicalAddress,
@@ -27,7 +27,7 @@ pub struct MemoryDescriptor {
2727
pub attribute: u64,
2828
}
2929

30-
#[derive(Default)]
30+
#[derive(Copy, Clone)]
3131
struct Allocation {
3232
in_use: bool,
3333
next_allocation: Option<usize>,
@@ -36,7 +36,7 @@ struct Allocation {
3636

3737
const MAX_ALLOCATIONS: usize = 32;
3838

39-
#[derive(Default)]
39+
#[derive(Copy, Clone)]
4040
pub struct Allocator {
4141
allocations: [Allocation; MAX_ALLOCATIONS],
4242
key: usize,
@@ -341,7 +341,7 @@ impl Allocator {
341341
let mut cur = self.first_allocation;
342342

343343
while cur != None {
344-
out[count] = self.allocations[cur.unwrap()].descriptor.clone();
344+
out[count] = self.allocations[cur.unwrap()].descriptor;
345345
cur = self.allocations[cur.unwrap()].next_allocation;
346346
count += 1;
347347
}
@@ -377,11 +377,22 @@ impl Allocator {
377377
self.key
378378
}
379379

380-
pub fn new() -> Allocator {
380+
pub const fn new() -> Allocator {
381+
let allocation = Allocation {
382+
in_use: false,
383+
next_allocation: None,
384+
descriptor: MemoryDescriptor {
385+
r#type: 0,
386+
physical_start: 0,
387+
virtual_start: 0,
388+
number_of_pages: 0,
389+
attribute: 0,
390+
},
391+
};
381392
Allocator {
382-
first_allocation: None,
393+
allocations: [allocation; MAX_ALLOCATIONS],
383394
key: 0,
384-
..Allocator::default()
395+
first_allocation: None,
385396
}
386397
}
387398
}

src/efi/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ mod block;
1717
mod console;
1818
mod file;
1919

20-
use lazy_static::lazy_static;
2120
use spin::Mutex;
2221

2322
use r_efi::efi;
@@ -48,9 +47,7 @@ struct HandleWrapper {
4847
handle_type: HandleType,
4948
}
5049

51-
lazy_static! {
52-
pub static ref ALLOCATOR: Mutex<Allocator> = Mutex::new(Allocator::new());
53-
}
50+
pub static ALLOCATOR: Mutex<Allocator> = Mutex::new(Allocator::new());
5451

5552
static mut BLOCK_WRAPPERS: block::BlockWrappers = block::BlockWrappers {
5653
wrappers: [core::ptr::null_mut(); 16],

0 commit comments

Comments
 (0)