authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-05-01 11:02:04+02:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-05-01 11:02:04+02:00
log51f80deaf6e7377f34c3fd4d68b8ad03b5de3bfb
tree500595424a985ccd3e69d67f0d6a7ff80bbc6c66
parent807bb7c03fc98e3792ece7e0573e226727c18129

std: Fix stack overflow in SPARC clone() impl

Leave the minimum amount of stack space required by the ABI (16 * 8 bytes for the window contents plus 6 * 8 bytes for the input arguments) on the new thread stack.

1 files changed, 7 insertions(+), 6 deletions(-)

lib/std/special/c.zig+7-6
......@@ -614,23 +614,24 @@ fn clone() callconv(.Naked) void {
614614 \\ # Shuffle the arguments
615615 \\ mov 217, %%g1
616616 \\ mov %%i2, %%o0
617 \\ sub %%i1, 2047, %%o1
617 \\ # Add some extra space for the initial frame
618 \\ sub %%i1, 176 + 2047, %%o1
618619 \\ mov %%i4, %%o2
619620 \\ mov %%i5, %%o3
620 \\ ldx [%%fp + 192 - 2*8 + 2047], %%o4
621 \\ ldx [%%fp + 0x8af], %%o4
621622 \\ t 0x6d
622623 \\ bcs,pn %%xcc, 2f
623624 \\ nop
624 \\ # sparc64 returns the child pid in o0 and a flag telling
625 \\ # whether the process is the child in o1
625 \\ # The child pid is returned in o0 while o1 tells if this
626 \\ # process is # the child (=1) or the parent (=0).
626627 \\ brnz %%o1, 1f
627628 \\ nop
628 \\ # This is the parent process, return the child pid
629 \\ # Parent process, return the child pid
629630 \\ mov %%o0, %%i0
630631 \\ ret
631632 \\ restore
632633 \\1:
633 \\ # This is the child process
634 \\ # Child process, call func(arg)
634635 \\ mov %%g0, %%fp
635636 \\ call %%g2
636637 \\ mov %%g3, %%o0