Skip to content

Commit efb6e7e

Browse files
committed
feat(utils): add the vendored rlsf to crate::utils::alloc
1 parent 6b74a11 commit efb6e7e

File tree

5 files changed

+48
-14
lines changed

5 files changed

+48
-14
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
#[macro_use]
33
mod vec;
44
pub use vec::*;
5+
mod rlsf;

src/r3_core/src/utils/alloc/rlsf/flex/tests.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use quickcheck_macros::quickcheck;
22
use std::{fmt, prelude::v1::*};
33

4-
use super::*;
5-
use crate::{
4+
use super::super::{
65
tests::ShadowAllocator,
7-
utils::{nonnull_slice_end, nonnull_slice_len},
6+
utils::{self, nonnull_slice_end, nonnull_slice_len},
87
};
8+
use super::*;
99

1010
trait TestFlexSource: FlexSource {
1111
type Options: quickcheck::Arbitrary;
@@ -293,7 +293,7 @@ macro_rules! gen_test {
293293
sa!().allocate(layout, ptr);
294294

295295
// Fill it with dummy data
296-
fill_data(crate::utils::nonnull_slice_from_raw_parts(ptr, len));
296+
fill_data(utils::nonnull_slice_from_raw_parts(ptr, len));
297297
}
298298
}
299299
3..=5 => {
@@ -303,7 +303,7 @@ macro_rules! gen_test {
303303
log::trace!("dealloc {:?}", alloc);
304304

305305
// Make sure the stored dummy data is not corrupted
306-
verify_data(crate::utils::nonnull_slice_from_raw_parts(alloc.ptr, alloc.layout.size()));
306+
verify_data(utils::nonnull_slice_from_raw_parts(alloc.ptr, alloc.layout.size()));
307307

308308
unsafe { tlsf.deallocate(alloc.ptr, alloc.layout.align()) };
309309
sa!().deallocate(alloc.layout, alloc.ptr);
@@ -330,8 +330,8 @@ macro_rules! gen_test {
330330
log::trace!(" {:?} → {:?}", alloc.ptr, ptr);
331331

332332
// Check and refill the dummy data
333-
verify_data(crate::utils::nonnull_slice_from_raw_parts(ptr, len.min(alloc.layout.size())));
334-
fill_data(crate::utils::nonnull_slice_from_raw_parts(ptr, len));
333+
verify_data(utils::nonnull_slice_from_raw_parts(ptr, len.min(alloc.layout.size())));
334+
fill_data(utils::nonnull_slice_from_raw_parts(ptr, len));
335335

336336
sa!().deallocate(alloc.layout, alloc.ptr);
337337
alloc.ptr = ptr;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//! [`rlsf`][] modified for compile-time allocation.
2+
//!
3+
//! [`rlsf`]: https://crates.io/crates/rlsf
4+
// FIXME: `rlsf` targets a pre-`unsafe_op_in_unsafe_fn` stable compiler, so
5+
// it doesn't have `deny(unsafe_op_in_unsafe_fn)`. Eventually we need to remove
6+
// this because this lint "may become [...] hard error in a future edition" [1].
7+
//
8+
// [1]: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1520-2021-05-06
9+
#![allow(unsafe_op_in_unsafe_fn)]
10+
#![allow(dead_code)]
11+
12+
macro_rules! const_panic {
13+
($($tt:tt)*) => {
14+
panic!($($tt)*)
15+
};
16+
}
17+
18+
use crate::utils::Init;
19+
20+
mod flex;
21+
pub mod int;
22+
mod tlsf;
23+
mod utils;
24+
pub use self::{
25+
flex::*,
26+
tlsf::{Tlsf, GRANULARITY},
27+
};
28+
29+
#[cfg(test)]
30+
mod tests;

src/r3_core/src/utils/alloc/rlsf/tlsf.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ use core::{
99
ptr::{addr_of, NonNull},
1010
};
1111

12-
use crate::{
12+
use super::{
1313
int::BinInteger,
1414
utils::{nonnull_slice_from_raw_parts, nonnull_slice_len, nonnull_slice_start},
1515
};
1616

17-
#[cfg_attr(doc, svgbobdoc::transform)]
17+
#[doc = svgbobdoc::transform!(
1818
/// The TLSF header (top-level) data structure.
1919
///
2020
/// # Data Structure Overview
@@ -63,6 +63,7 @@ use crate::{
6363
///
6464
/// The maximum block size is `(GRANULARITY << FLLEN) - GRANULARITY`.
6565
///
66+
)]
6667
#[derive(Debug)]
6768
pub struct Tlsf<'pool, FLBitmap, SLBitmap, const FLLEN: usize, const SLLEN: usize> {
6869
fl_bitmap: FLBitmap,
@@ -433,7 +434,7 @@ impl<'pool, FLBitmap: BinInteger, SLBitmap: BinInteger, const FLLEN: usize, cons
433434
///
434435
/// # Examples
435436
///
436-
/// ```
437+
/// ```rust,ignore
437438
/// use rlsf::Tlsf;
438439
/// use std::{mem::MaybeUninit, ptr::NonNull};
439440
/// static mut POOL: MaybeUninit<[u8; 1024]> = MaybeUninit::uninit();
@@ -555,7 +556,7 @@ impl<'pool, FLBitmap: BinInteger, SLBitmap: BinInteger, const FLLEN: usize, cons
555556
///
556557
/// # Examples
557558
///
558-
/// ```
559+
/// ```rust,ignore
559560
/// use rlsf::Tlsf;
560561
/// use std::{mem::MaybeUninit, ptr::NonNull};
561562
///
@@ -699,7 +700,7 @@ impl<'pool, FLBitmap: BinInteger, SLBitmap: BinInteger, const FLLEN: usize, cons
699700
///
700701
/// # Examples
701702
///
702-
/// ```
703+
/// ```rust,ignore
703704
/// use rlsf::Tlsf;
704705
/// use std::mem::MaybeUninit;
705706
/// let mut pool = [MaybeUninit::uninit(); 1024];
@@ -709,7 +710,7 @@ impl<'pool, FLBitmap: BinInteger, SLBitmap: BinInteger, const FLLEN: usize, cons
709710
///
710711
/// The insertred memory block must outlive `self`:
711712
///
712-
/// ```rust,compile_fail
713+
/// ```rust,ignore
713714
/// use rlsf::Tlsf;
714715
/// use std::mem::MaybeUninit;
715716
/// let mut tlsf: Tlsf<u8, u8, 8, 8> = Tlsf::INIT;

src/r3_core/src/utils/alloc/rlsf/tlsf/tests.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use quickcheck_macros::quickcheck;
22
use std::{mem::MaybeUninit, prelude::v1::*};
33

4+
use super::super::{tests::ShadowAllocator, utils::nonnull_slice_from_raw_parts};
45
use super::*;
5-
use crate::{tests::ShadowAllocator, utils::nonnull_slice_from_raw_parts};
66

77
#[repr(align(64))]
88
struct Align<T>(T);
@@ -179,6 +179,8 @@ macro_rules! gen_test {
179179
let mut sa = ShadowAllocator::new();
180180
let mut tlsf: TheTlsf = Tlsf::INIT;
181181

182+
let pool_size = pool_size % 0x1000000;
183+
182184
let mut pool = Align([MaybeUninit::<u8>::uninit(); 65536]);
183185
let pool_ptr;
184186
// The end index of the memory pool inserted to `tlsf`

0 commit comments

Comments
 (0)