{"record":{"id":"734d8498ae853e31","repo":"wasmerio/wasmer","slug":"stack-size-must-be-1024-bit-aligned","errorCode":null,"errorMessage":"Stack size must be 1024-bit aligned","messagePattern":"Stack size must be 1024-bit aligned","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/wasix/src/state/linker/mod.rs","lineNumber":375,"sourceCode":"\n        let memory_type = main_module_memory_type(main_module)?;\n\n        let memory = match memory {\n            Some(m) => m,\n            None => Memory::new(store, memory_type)?,\n        };\n\n        let stack_low = {\n            let data_end = memory_base + dylink_section.mem_info.memory_size as u64;\n            if !data_end.is_multiple_of(1024) {\n                data_end + 1024 - (data_end % 1024)\n            } else {\n                data_end\n            }\n        };\n\n        if !stack_size.is_multiple_of(1024) {\n            panic!(\"Stack size must be 1024-bit aligned\");\n        }\n\n        let stack_high = stack_low + stack_size;\n\n        // Allocate memory for the stack. This does not need to go through the memory allocator\n        // because it's always placed directly after the main module's data\n        memory.grow_at_least(store, stack_high)?;\n\n        trace!(\n            memory_pages = ?memory.grow(store, 0).unwrap(),\n            memory_base,\n            stack_low,\n            stack_high,\n            \"Memory layout\"\n        );\n\n        let stack_pointer = create_main_stack_pointer_global(store, main_module, stack_high)?;\n","sourceCodeStart":357,"sourceCodeEnd":393,"githubUrl":"https://github.com/wasmerio/wasmer/blob/8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5/lib/wasix/src/state/linker/mod.rs#L357-L393","documentation":"The linker's StackSize configuration must be a multiple of 1024 (the message says 1024-bit aligned, i.e. 128-byte / 1024-bit granularity). Stack regions in dynamically linked modules are laid out with this alignment so all side modules' stacks interleave correctly; an unaligned size would misalign subsequent stack allocations. The check panics at Linker::new time.","triggerScenarios":"Calling Linker::new (or the config that feeds it) with stack_size not divisible by 1024, e.g. StackSize(4097) or a value parsed from an env var like RUST_LOG-style tuning knobs without validation.","commonSituations":"Setting StackSize via an environment variable or CLI flag with an arbitrary value; copying a stack size from a different runtime that uses different alignment; a typo such as 1023 or 1000.","solutions":["Round the stack size up to the next multiple of 1024 before constructing the Linker","Validate/normalize any externally supplied stack size (env var, config file) before passing it in","Use the default stack size if unsure","Update your config templates that carry a non-1024-multiple stack size"],"exampleFix":"// before\nlet stack_size = std::env::var(\"STACK_SIZE\").unwrap().parse().unwrap(); // e.g. 4097\nlet linker = Linker::new(&engine, StackSize(stack_size));\n// after\nlet stack_size: u64 = std::env::var(\"STACK_SIZE\").unwrap().parse().unwrap();\nlet stack_size = (stack_size + 1023) / 1024 * 1024; // round up to 1024\nlet linker = Linker::new(&engine, StackSize(stack_size));","handlingStrategy":"validation","validationCode":"fn valid_stack_size(n: u64) -> bool { n > 0 && n % 1024 == 0 }\nlet n: u64 = env.parse().map_err(|_| \"invalid STACK_SIZE\")?;\nlet n = (n + 1023) / 1024 * 1024; // normalize before Linker::new\nassert!(valid_stack_size(n));","typeGuard":"fn is_1024_aligned(n: u64) -> bool { n % 1024 == 0 }","tryCatchPattern":null,"preventionTips":["Always round externally supplied stack sizes up to a 1024 multiple","Validate env/config-derived numbers before constructing the Linker","Keep stack size settings consistent across services using this runtime","Document the 1024-alignment requirement next to the config knob"],"tags":["linker","configuration","stack-size","alignment","panic"],"backgroundTag":"invalid-config-value","analyzedSha":"8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5","analyzedAt":"2026-09-01T23:06:31.009Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}