#10509: Stack is not aligned -----------------------------+---------------------------- Reporter: pulkomandy | Owner: axeld Type: enhancement | Status: new Priority: normal | Milestone: Unscheduled Component: System/Kernel | Version: R1/Development Resolution: | Keywords: Blocked By: | Blocking: Has a Patch: 0 | Platform: x86 -----------------------------+---------------------------- Changes (by bonefish): * owner: nobody => axeld * component: System => System/Kernel Comment: The initial stack for a new thread is set up in the architecture specific kernel function `arch_thread_enter_userspace()` ([http://cgit.haiku- os.org/haiku/tree/src/system/kernel/arch/x86/32/thread.cpp#n217 x86], [http://cgit.haiku- os.org/haiku/tree/src/system/kernel/arch/x86/64/thread.cpp#n214 x86-64]). All that has to be done is align the value of `stackTop` to 16 and offset it as necessary (note, the stack grows downward, so the address must only be decreased). I considered doing that already, but it hadn't been clear to me what that offset should be. According to the crash report the `movaps` instruction tries to access 0xffffff48(%ebp), which, I suppose, means that for x86 ebp (the stack frame pointer) should be offset by 8, which means that for the initial stack pointer (esp) `esp % 16 == 12` should hold (due to `ebp = esp - 4`). The `main()` prologue gcc generates seems to agree: {{{ 1ad5: 8d 4c 24 04 lea 0x4(%esp),%ecx 1ad9: 83 e4 f0 and $0xfffffff0,%esp 1adc: ff 71 fc pushl -0x4(%ecx) 1adf: 55 push %ebp 1ae0: 89 e5 mov %esp,%ebp }}} I think the best way to implement that is by having `arch_randomize_stack_pointer()` enforce that property and change all callers (namely `arch_thread_enter_userspace()` and `get_signal_stack()`) to supply an address that has already been adjusted to make the needed room on the stack. -- Ticket URL: <https://dev.haiku-os.org/ticket/10509#comment:3> Haiku <https://dev.haiku-os.org> Haiku - the operating system.