Skip to content

Commit 0b81290

Browse files
committed
refactor: move crate::utils::{alloc:: → }{vec, freeze}, remove r3_kernel::utils::alloc
`cfg_phaseN!` will need `ConstAllocator`, and they can't produce `ConstAllocator` to be used by themselves because, if the constructed `ConstAllocator` is stored in a local variable of a user-controlled `async` closure, there exists no way to guarantee that its destructor is called before the control exits the scope (a concrete example of the exploitation of this caveat can be found in [1]). `vec` and `freeze` are kept out of `r3_core::utils::alloc` to minimize the stable API surface to maintain. [1]: https://github.com/yvt/cryo/blob/3cd529a8665063e98961e08b4df25d398d9bd4b5/src/lib.rs#L565-L662
1 parent 1a03e0d commit 0b81290

File tree

9 files changed

+26
-8
lines changed

9 files changed

+26
-8
lines changed

src/r3_core/src/utils/alloc/allocator.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ macro_rules! const_try_result {
2424
/// `ConstAllocator`. This is accomplished by, instead of making a call to
2525
/// `const_allocate` for each allocation request, slicing out each allocated
2626
/// region from larger blocks using a dynamic storage allocation algorithm.
27+
///
28+
/// # Stability
29+
///
30+
/// This type is subject to the kernel-side API stability guarantee.
2731
pub struct ConstAllocator {
2832
// We very much want to put these in `core::cell::*`, but they aren't very
2933
// useful in `const fn`, unfortunately.
@@ -192,6 +196,10 @@ impl const Drop for ConstAllocator {
192196
/// that may be due to resource exhaustion or to
193197
/// something wrong when combining the given input arguments with this
194198
/// allocator.
199+
///
200+
/// # Stability
201+
///
202+
/// This trait is subject to the kernel-side API stability guarantee.
195203
#[derive(Clone, Copy)]
196204
pub struct AllocError;
197205

@@ -200,6 +208,10 @@ pub struct AllocError;
200208
/// # Safety
201209
///
202210
/// See [`core::alloc::Allocator`]'s documentation.
211+
///
212+
/// # Stability
213+
///
214+
/// This trait is subject to the kernel-side API stability guarantee.
203215
pub unsafe trait Allocator {
204216
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>;
205217

src/r3_core/src/utils/alloc/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
//! Compile-time memory allocation
2-
#[macro_use]
3-
mod vec;
42
mod allocator;
5-
mod freeze;
63
mod rlsf;
7-
pub use {allocator::*, freeze::*, vec::*};
4+
pub use allocator::*;

src/r3_core/src/utils/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
//! Utility
2+
//!
3+
//! **This module is exempt from the API stability guarantee** unless specified
4+
//! otherwise. It's exposed mostly because it's needed by macros.
25
use core::marker::PhantomData;
36

47
/// Conditional type
@@ -45,6 +48,10 @@ mod binary_search;
4548
mod sort;
4649
pub(crate) use sort::*;
4750
#[macro_use]
51+
mod vec;
52+
pub use vec::*;
53+
mod freeze;
54+
pub use freeze::*;
4855
mod alloc;
4956
pub use alloc::*;
5057
#[macro_use]
File renamed without changes.

src/r3_kernel/src/utils/alloc

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/r3_kernel/src/utils/freeze.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../r3_core/src/utils/freeze.rs

src/r3_kernel/src/utils/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Utility
22
//!
33
//! **This module is exempt from the API stability guarantee** unless specified
4-
//! otherwise. It's exposed only because it's needed by macros.
4+
//! otherwise. It's exposed mostly because it's needed by macros.
55
use core::marker::PhantomData;
66

77
/// Conditional type
@@ -46,15 +46,16 @@ mod aligned_storage;
4646
pub mod binary_heap;
4747
pub(crate) mod convert;
4848
mod ctz;
49+
mod freeze;
4950
mod int;
5051
pub(crate) mod intrusive_list;
5152
pub mod mem;
5253
pub(crate) mod pin;
5354
mod prio_bitmap;
5455
mod rawcell;
5556
#[macro_use]
56-
mod alloc;
57-
pub use self::{aligned_storage::*, alloc::*, int::*, prio_bitmap::*, rawcell::*};
57+
mod vec;
58+
pub use self::{aligned_storage::*, freeze::*, int::*, prio_bitmap::*, rawcell::*, vec::*};
5859
pub use r3_core::utils::{Init, ZeroInit};
5960

6061
/// A "type function" producing a type.

src/r3_kernel/src/utils/vec.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../r3_core/src/utils/vec.rs

0 commit comments

Comments
 (0)