Skip to content

Commit 7cc74f1

Browse files
committed
Merge branch '💥-const-allocator' into 🦆
2 parents 4345dce + a6cfdea commit 7cc74f1

File tree

26 files changed

+3793
-201
lines changed

26 files changed

+3793
-201
lines changed

‎src/r3/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ While much of the application-level API has retained its general shape, there ar
2121

2222
TODO
2323

24+
### Fixed
25+
26+
- The hard-coded kernel object count limitation has been removed. This was made possible by the use of growable arrays in the compile-time kernel configurator.
27+
2428
## [0.1.3] - 2021-10-29
2529

2630
This release only includes changes to the documentation.

‎src/r3_core/src/kernel/cfg.rs

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Kernel configuration
22
use crate::{
33
kernel::{hook, interrupt, raw, raw_cfg},
4-
utils::{ComptimeVec, Init, PhantomInvariant},
4+
utils::{ComptimeVec, ConstAllocator, Frozen, Init, PhantomInvariant},
55
};
66

77
macro overview_ref() {
@@ -29,37 +29,49 @@ enum CfgSt {
2929

3030
impl<'c, C: raw_cfg::CfgBase> Cfg<'c, C> {
3131
/// Construct `Cfg`.
32-
const fn new(raw: &'c mut C, st: CfgSt) -> Self {
32+
const fn new(raw: &'c mut C, allocator: &'c ConstAllocator, st: CfgSt) -> Self {
3333
Self {
3434
raw,
3535
st,
36-
startup_hooks: ComptimeVec::new(),
36+
startup_hooks: ComptimeVec::new_in(allocator.clone()),
3737
hunk_pool_len: 0,
3838
hunk_pool_align: 1,
39-
interrupt_lines: ComptimeVec::new(),
40-
interrupt_handlers: ComptimeVec::new(),
39+
interrupt_lines: ComptimeVec::new_in(allocator.clone()),
40+
interrupt_handlers: ComptimeVec::new_in(allocator.clone()),
4141
}
4242
}
4343

4444
#[doc(hidden)]
45-
pub const fn __internal_new_phase1(raw: &'c mut C, _dummy: &'c mut ()) -> Self {
46-
Self::new(raw, CfgSt::Phase1)
45+
pub const fn __internal_new_phase1(
46+
raw: &'c mut C,
47+
allocator: &'c ConstAllocator,
48+
_dummy: &'c mut (),
49+
) -> Self {
50+
Self::new(raw, allocator, CfgSt::Phase1)
4751
}
4852

4953
#[doc(hidden)]
50-
pub const fn __internal_new_phase2(raw: &'c mut C, _dummy: &'c mut ()) -> Self
54+
pub const fn __internal_new_phase2(
55+
raw: &'c mut C,
56+
allocator: &'c ConstAllocator,
57+
_dummy: &'c mut (),
58+
) -> Self
5159
where
5260
C::System: CfgPhase1,
5361
{
54-
Self::new(raw, CfgSt::Phase2)
62+
Self::new(raw, allocator, CfgSt::Phase2)
5563
}
5664

5765
#[doc(hidden)]
58-
pub const fn __internal_new_phase3(raw: &'c mut C, _dummy: &'c mut ()) -> Self
66+
pub const fn __internal_new_phase3(
67+
raw: &'c mut C,
68+
allocator: &'c ConstAllocator,
69+
_dummy: &'c mut (),
70+
) -> Self
5971
where
6072
C::System: CfgPhase2,
6173
{
62-
Self::new(raw, CfgSt::Phase3 { interrupts: false })
74+
Self::new(raw, allocator, CfgSt::Phase3 { interrupts: false })
6375
}
6476

6577
/// Mutably borrow the underlying `C`.
@@ -104,10 +116,12 @@ impl<'c, C: raw_cfg::CfgBase> Cfg<'c, C> {
104116

105117
CfgPhase1Data {
106118
_phantom: Init::INIT,
107-
startup_hooks: self.startup_hooks.map(hook::CfgStartupHook::to_attr),
119+
startup_hooks: Frozen::leak_slice(
120+
&self.startup_hooks.map(hook::CfgStartupHook::to_attr),
121+
),
108122
hunk_pool_len: self.hunk_pool_len,
109123
hunk_pool_align: self.hunk_pool_align,
110-
interrupt_handlers: self.interrupt_handlers,
124+
interrupt_handlers: Frozen::leak_slice(&self.interrupt_handlers),
111125
}
112126
}
113127

@@ -186,8 +200,8 @@ impl<'c, C: raw_cfg::CfgBase> Cfg<'c, C> {
186200

187201
// Clear these fields to indicate that this method has been called
188202
// as required
189-
self.interrupt_lines = ComptimeVec::new();
190-
self.interrupt_handlers = ComptimeVec::new();
203+
self.interrupt_lines.clear();
204+
self.interrupt_handlers.clear();
191205
}
192206

193207
/// Finalize `self` for the phase 3 configuration.
@@ -238,10 +252,10 @@ impl<'c, C: raw_cfg::CfgBase> Cfg<'c, C> {
238252
#[doc = overview_ref!()]
239253
pub struct CfgPhase1Data<System> {
240254
_phantom: PhantomInvariant<System>,
241-
pub startup_hooks: ComptimeVec<hook::StartupHookAttr>,
255+
pub startup_hooks: &'static [Frozen<hook::StartupHookAttr>],
242256
pub hunk_pool_len: usize,
243257
pub hunk_pool_align: usize,
244-
pub interrupt_handlers: ComptimeVec<interrupt::CfgInterruptHandler>,
258+
pub interrupt_handlers: &'static [Frozen<interrupt::CfgInterruptHandler>],
245259
}
246260

247261
/// The inputs to [`attach_phase2!`].
@@ -504,28 +518,45 @@ where
504518

505519
/// Construct [`Cfg`]`<$RawCfg>` for the phase 3 configuration.
506520
///
521+
/// - `$raw_cfg: &mut impl `[`CfgBase`][]
522+
/// - `$allocator: &`[`ConstAllocator`][]
523+
///
507524
/// `<$RawCfg as `[`CfgBase`][]`>::System` must implement [`CfgPhase2`][].
508525
///
509526
/// [`CfgBase`]: raw_cfg::CfgBase
510-
pub macro cfg_phase3(let mut $cfg:ident = Cfg::<$RawCfg:ty>::new($raw_cfg:expr)) {
527+
pub macro cfg_phase3(
528+
let mut $cfg:ident = Cfg::<$RawCfg:ty>::new($raw_cfg:expr, $allocator:expr)
529+
) {
511530
let mut dummy = ();
512-
let mut $cfg = Cfg::<$RawCfg>::__internal_new_phase3(&mut *$raw_cfg, &mut dummy);
531+
let mut $cfg = Cfg::<$RawCfg>::__internal_new_phase3(&mut *$raw_cfg, $allocator, &mut dummy);
513532
}
514533

515534
/// Construct [`Cfg`]`<$RawCfg>` for the phase 2 configuration.
516535
///
536+
/// - `$raw_cfg: &mut impl `[`CfgBase`][]
537+
/// - `$allocator: &`[`ConstAllocator`][]
538+
///
517539
/// `<$RawCfg as `[`CfgBase`][]`>::System` must implement [`CfgPhase1`][].
518540
///
519541
/// [`CfgBase`]: raw_cfg::CfgBase
520-
pub macro cfg_phase2(let mut $cfg:ident = Cfg::<$RawCfg:ty>::new($raw_cfg:expr)) {
542+
pub macro cfg_phase2(
543+
let mut $cfg:ident = Cfg::<$RawCfg:ty>::new($raw_cfg:expr, $allocator:expr)
544+
) {
521545
let mut dummy = ();
522-
let mut $cfg = Cfg::<$RawCfg>::__internal_new_phase2(&mut *$raw_cfg, &mut dummy);
546+
let mut $cfg = Cfg::<$RawCfg>::__internal_new_phase2(&mut *$raw_cfg, $allocator, &mut dummy);
523547
}
524548

525549
/// Construct [`Cfg`]`<$RawCfg>` for the phase 1 configuration.
526-
pub macro cfg_phase1(let mut $cfg:ident = Cfg::<$RawCfg:ty>::new($raw_cfg:expr)) {
550+
///
551+
/// - `$raw_cfg: &mut impl `[`CfgBase`][]
552+
/// - `$allocator: &`[`ConstAllocator`][]
553+
///
554+
/// [`CfgBase`]: raw_cfg::CfgBase
555+
pub macro cfg_phase1(
556+
let mut $cfg:ident = Cfg::<$RawCfg:ty>::new($raw_cfg:expr, $allocator:expr)
557+
) {
527558
let mut dummy = ();
528-
let mut $cfg = Cfg::<$RawCfg>::__internal_new_phase1(&mut *$raw_cfg, &mut dummy);
559+
let mut $cfg = Cfg::<$RawCfg>::__internal_new_phase1(&mut *$raw_cfg, $allocator, &mut dummy);
529560
}
530561

531562
/// Implement [`KernelStatic`] on `$Ty` using the given `$params:
@@ -590,13 +621,15 @@ pub macro attach_phase1($params:expr, impl CfgPhase1<$System:ty> for $Ty:ty $(,)
590621
array_item_from_fn! {
591622
const STARTUP_HOOKS: [hook::StartupHookAttr; _] =
592623
(0..STATIC_PARAMS.startup_hooks.len())
593-
.map(|i| STATIC_PARAMS.startup_hooks[i]);
624+
.map(|i| STATIC_PARAMS.startup_hooks[i].get());
594625
}
595626

596627
// Consturct a table of combined second-level interrupt handlers
597-
const INTERRUPT_HANDLERS: [interrupt::CfgInterruptHandler; {
598-
STATIC_PARAMS.interrupt_handlers.len()
599-
}] = STATIC_PARAMS.interrupt_handlers.to_array();
628+
array_item_from_fn! {
629+
const INTERRUPT_HANDLERS: [interrupt::CfgInterruptHandler; _] =
630+
(0..STATIC_PARAMS.interrupt_handlers.len())
631+
.map(|i| STATIC_PARAMS.interrupt_handlers[i].get());
632+
}
600633
const NUM_INTERRUPT_HANDLERS: usize = INTERRUPT_HANDLERS.len();
601634
const NUM_INTERRUPT_LINES: usize =
602635
interrupt::num_required_interrupt_line_slots(&INTERRUPT_HANDLERS);

‎src/r3_core/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,29 @@
22
#![feature(const_fn_trait_bound)]
33
#![feature(const_fn_fn_ptr_basics)]
44
#![feature(const_fn_floating_point_arithmetic)]
5+
#![feature(const_maybe_uninit_as_mut_ptr)]
6+
#![feature(const_ptr_read)]
57
#![feature(generic_const_exprs)]
68
#![feature(const_ptr_offset)]
79
#![feature(const_swap)]
810
#![feature(const_slice_first_last)]
11+
#![feature(const_replace)]
12+
#![feature(const_intrinsic_copy)]
13+
#![feature(const_raw_ptr_comparison)]
14+
#![feature(const_ptr_offset_from)]
915
#![feature(maybe_uninit_slice)]
16+
#![feature(const_eval_select)]
1017
#![feature(const_mut_refs)]
1118
#![feature(const_slice_from_raw_parts)]
1219
#![feature(const_option)]
20+
#![feature(const_option_ext)]
1321
#![feature(const_trait_impl)]
1422
#![feature(const_refs_to_cell)]
23+
#![feature(const_ptr_as_ref)]
24+
#![feature(const_ptr_write)]
25+
#![feature(core_intrinsics)]
26+
#![feature(const_heap)]
27+
#![feature(let_else)]
1528
#![feature(exhaustive_patterns)] // `let Ok(()) = Ok::<(), !>(())`
1629
#![feature(decl_macro)]
1730
#![feature(set_ptr_value)] // `<*const T>::set_ptr_value`

0 commit comments

Comments
 (0)