summaryrefslogtreecommitdiff
path: root/rust/kernel/alloc/allocator_test.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/kernel/alloc/allocator_test.rs')
-rw-r--r--rust/kernel/alloc/allocator_test.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/rust/kernel/alloc/allocator_test.rs b/rust/kernel/alloc/allocator_test.rs
index f46b4b671389..7b10e276f621 100644
--- a/rust/kernel/alloc/allocator_test.rs
+++ b/rust/kernel/alloc/allocator_test.rs
@@ -24,6 +24,17 @@ pub type Kmalloc = Cmalloc;
pub type Vmalloc = Kmalloc;
pub type KVmalloc = Kmalloc;
+impl Cmalloc {
+ /// Returns a [`Layout`] that makes [`Kmalloc`] fulfill the requested size and alignment of
+ /// `layout`.
+ pub fn aligned_layout(layout: Layout) -> Layout {
+ // Note that `layout.size()` (after padding) is guaranteed to be a multiple of
+ // `layout.align()` which together with the slab guarantees means that `Kmalloc` will return
+ // a properly aligned object (see comments in `kmalloc()` for more information).
+ layout.pad_to_align()
+ }
+}
+
pub struct VmallocPageIter<'a> {
_p: PhantomData<page::BorrowedPage<'a>>,
}