Skip to content

Commit 7262c22

Browse files
committed
Overhaul Dealing with UEFI ZSTs
A complete rewrite of VariableSizeType wrapper to match the semantics of Box. This commit is a part of a series of commits to clean up the `std::os::uefi` namespace. Signed-off-by: Ayush <ayushsingh1325@gmail.com>
1 parent c257c00 commit 7262c22

File tree

11 files changed

+389
-298
lines changed

11 files changed

+389
-298
lines changed

library/std/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,10 @@
243243
#![feature(c_unwind)]
244244
#![feature(cfg_target_thread_local)]
245245
#![feature(concat_idents)]
246+
#![feature(const_deref)]
246247
#![feature(const_mut_refs)]
247248
#![feature(const_trait_impl)]
249+
#![feature(const_try)]
248250
#![feature(decl_macro)]
249251
#![feature(deprecated_suggestion)]
250252
#![feature(doc_cfg)]
@@ -309,6 +311,7 @@
309311
#![feature(prelude_2024)]
310312
#![feature(provide_any)]
311313
#![feature(ptr_as_uninit)]
314+
#![feature(ptr_internals)]
312315
#![feature(raw_os_nonzero)]
313316
#![feature(slice_internals)]
314317
#![feature(slice_ptr_get)]
@@ -323,6 +326,7 @@
323326
#![feature(alloc_layout_extra)]
324327
#![feature(allocator_api)]
325328
#![feature(get_mut_unchecked)]
329+
#![feature(const_alloc_error)]
326330
#![feature(map_try_insert)]
327331
#![feature(new_uninit)]
328332
#![feature(thin_box)]

library/std/src/os/uefi/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ pub mod env;
66
pub mod ffi;
77
pub mod io;
88
pub mod net;
9-
pub mod path;
109
pub mod raw;

library/std/src/os/uefi/path.rs

Lines changed: 0 additions & 118 deletions
This file was deleted.

library/std/src/os/uefi/raw.rs

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,3 @@
11
//! This module just re-exports stuff from r-efi crate
22
33
pub use r_efi::efi::{BootServices, Guid, RuntimeServices, SystemTable};
4-
5-
use crate::alloc::{Allocator, Global, Layout};
6-
use crate::io;
7-
use crate::ptr::NonNull;
8-
use crate::sys_common::AsInner;
9-
10-
// A type to make working with Variable Sized Types easier
11-
pub(crate) struct VariableSizeType<T> {
12-
inner: NonNull<T>,
13-
layout: Layout,
14-
}
15-
16-
impl<T> VariableSizeType<T> {
17-
const ALIGNMENT: usize = 8;
18-
19-
pub(crate) fn new(inner: NonNull<T>, layout: Layout) -> Self {
20-
Self { inner, layout }
21-
}
22-
23-
pub(crate) fn from_size(size: usize) -> io::Result<Self> {
24-
let layout = Layout::from_size_align(size, Self::ALIGNMENT).map_err(|_| {
25-
io::error::const_io_error!(io::ErrorKind::Uncategorized, "Invalid buffer size")
26-
})?;
27-
let inner: NonNull<T> = Global
28-
.allocate(layout)
29-
.map_err(|_| {
30-
io::error::const_io_error!(
31-
io::ErrorKind::Uncategorized,
32-
"Failed to allocate Buffer"
33-
)
34-
})?
35-
.cast();
36-
Ok(Self::new(inner, layout))
37-
}
38-
39-
pub(crate) fn as_ptr(&self) -> *mut T {
40-
self.inner.as_ptr()
41-
}
42-
43-
// Callers responsibility to ensure that it has been inintialized beforehand
44-
pub(crate) fn as_ref(&self) -> &T {
45-
unsafe { self.inner.as_ref() }
46-
}
47-
48-
pub(crate) fn size(&self) -> usize {
49-
self.layout.size()
50-
}
51-
}
52-
53-
impl<T> AsInner<NonNull<T>> for VariableSizeType<T> {
54-
fn as_inner(&self) -> &NonNull<T> {
55-
&self.inner
56-
}
57-
}
58-
59-
impl<T> Drop for VariableSizeType<T> {
60-
fn drop(&mut self) {
61-
unsafe { Global.deallocate(self.inner.cast(), self.layout) }
62-
}
63-
}

library/std/src/sys/uefi/alloc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use crate::alloc::{GlobalAlloc, Layout, System};
66
use crate::os::uefi;
77

8-
const POOL_ALIGNMENT: usize = 8;
8+
pub(crate) const POOL_ALIGNMENT: usize = 8;
99
// FIXME: Maybe allow chaing the MEMORY_TYPE. However, since allocation is done even before main,
1010
// there will be a few allocations with the default MEMORY_TYPE.
1111
const MEMORY_TYPE: u32 = r_efi::efi::LOADER_DATA;

0 commit comments

Comments
 (0)