summaryrefslogtreecommitdiff
path: root/rust/kernel/alloc/allocator_test.rs
diff options
context:
space:
mode:
authorAlexei Starovoitov <ast@kernel.org>2025-09-11 09:34:37 -0700
committerAlexei Starovoitov <ast@kernel.org>2025-09-11 09:34:37 -0700
commit5d87e96a4971760c83e554c1d3ca99986d4f9b47 (patch)
tree6623b8ed550fd713e09fd2466bfcafa2f3a6a393 /rust/kernel/alloc/allocator_test.rs
parentf85981327a90c51e76f60e073cb6648b2f167226 (diff)
parente59a039119c3ec241228adf12dca0dd4398104d0 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf after rc5
Cross-merge BPF and other fixes after downstream PR. No conflicts. Signed-off-by: Alexei Starovoitov <ast@kernel.org>
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 a3074480bd8d..90dd987d40e4 100644
--- a/rust/kernel/alloc/allocator_test.rs
+++ b/rust/kernel/alloc/allocator_test.rs
@@ -22,6 +22,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()
+ }
+}
+
extern "C" {
#[link_name = "aligned_alloc"]
fn libc_aligned_alloc(align: usize, size: usize) -> *mut crate::ffi::c_void;