I'm trying to point a boot loader at the top of my stack which is declared like so:
const MAX_STACK_SIZE: usize = 1024 * 256; #[repr(C, align(4))] // Comply with system-V ABI struct Stack([u8; MAX_STACK_SIZE]); static STACK: Stack = Stack([0; MAX_STACK_SIZE]);
Specifically, the pointer needs to be one index past the end of the array to be at the top of the stack. However, doing this:
#[link_section = ".stivale2hdr"] #[used] static BOOT_LOADER_HEADER: StivaleHeader = StivaleHeader::new() .stack(&STACK.0[MAX_STACK_SIZE] as *const u8) .flags(0x1E) .tags(&FB_TAG as *const StivaleFramebufferHeaderTag as *const ());
Doesn't evaluate properly (compiler error), obviously, so how do I force Rust to do this anyway? Normally, I'd avoid unsafe code like this, but if I set it to
MAX_STACK_SIZE - 1, my stack won't be aligned properly, and the System-V ABI mandates that the stack be 16-byte aligned.