Link: https://lore.kernel.org/r/20260217200002.683975158@linuxfoundation.org Tested-by: Florian Fainelli <florian.fainelli@broadcom.com> Tested-by: Takeshi Ogasawara <takeshi.ogasawara@futuring-girl.com> Tested-by: Peter Schneider <pschneider1968@googlemail.com> Tested-by: Jon Hunter <jonathanh@nvidia.com> Tested-by: Salvatore Bonaccorso <carnil@debian.org> Tested-by: Brett A C Sheffield <bacs@librecast.net> Tested-by: Mark Brown <broonie@kernel.org> Tested-by: Luna Jernberg <droidbittin@gmail.com> Tested-by: Ronald Warsow <rwarsow@gmx.de> Tested-by: Justin M. Forbes <jforbes@fedoraproject.org> Tested-by: Ron Economos <re@w6rz.net> Tested-by: Miguel Ojeda <ojeda@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
44 lines
935 B
Rust
44 lines
935 B
Rust
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
|
|
use pin_init::*;
|
|
|
|
// Struct with size over 1GiB
|
|
#[derive(Debug)]
|
|
#[allow(dead_code)]
|
|
pub struct BigStruct {
|
|
buf: [u8; 1024 * 1024 * 1024],
|
|
a: u64,
|
|
b: u64,
|
|
c: u64,
|
|
d: u64,
|
|
managed_buf: ManagedBuf,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct ManagedBuf {
|
|
buf: [u8; 1024 * 1024],
|
|
}
|
|
|
|
impl ManagedBuf {
|
|
pub fn new() -> impl Init<Self> {
|
|
init!(ManagedBuf { buf <- init_zeroed() })
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
|
{
|
|
// we want to initialize the struct in-place, otherwise we would get a stackoverflow
|
|
let buf: Box<BigStruct> = Box::init(init!(BigStruct {
|
|
buf <- init_zeroed(),
|
|
a: 7,
|
|
b: 186,
|
|
c: 7789,
|
|
d: 34,
|
|
managed_buf <- ManagedBuf::new(),
|
|
}))
|
|
.unwrap();
|
|
println!("{}", core::mem::size_of_val(&*buf));
|
|
}
|
|
}
|