Nice, long knife to stab yourself in the eye
stackaroo is a highly unsafe library, letting you swap out the OS-provided thread stack with your own custom stack (e.g. heap-backed).
This library was created as part of research into Linux kernel internals. It provides platform-specific assembly implementations (x86_64 and AArch64) to perform direct stack pointer manipulation, allowing you to:
- Execute functions on arbitrarily large custom stacks (4GB? Why not!)
- Perform deep recursion that would normally cause stack overflow
- Test stack-intensive algorithms without OS stack limitations
- Experience the pure terror of manual memory management
use stackaroo::swap_to_heap;
struct Args {
n: u64,
result: u64,
}
fn fibonacci(args: &mut Args) {
fn fib(n: u64) -> u64 {
let huge_array = [0u8; 1024 * 1024]; // 1MB per frame
std::hint::black_box(&huge_array); // Don't let it be compiled-out
if n <= 1 { return n; }
fib(n - 1) + fib(n - 2)
}
args.result = fib(args.n);
}
fn main() {
unsafe {
const STACK_SIZE: usize = 1 << 30; // 1GB
let mut args = Args { n: 32, result: 0 };
swap_to_heap(fibonacci, Some(&mut args), STACK_SIZE).unwrap();
println!("Fibonacci({}) = {}", args.n, args.result);
}
}- Supports x86_64 and AArch64
no_stdcompatible- One swap per thread (
std) or one swap globally (no-std) - Does not support recursive stack swaps
This library is extremely unsafe and should only be used by people who understand the implications of manual stack management. It's primarily intended for research, kernel development, and testing scenarios where you need to bypass OS stack limitations.
This project is licensed under the Apache License 2.0.