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 {...@@ -614,23 +614,24 @@ fn clone() callconv(.Naked) void {
614 \\ # Shuffle the arguments614 \\ # Shuffle the arguments
615 \\ mov 217, %%g1615 \\ mov 217, %%g1
616 \\ mov %%i2, %%o0616 \\ mov %%i2, %%o0
617 \\ sub %%i1, 2047, %%o1617 \\ # Add some extra space for the initial frame
618 \\ sub %%i1, 176 + 2047, %%o1
618 \\ mov %%i4, %%o2619 \\ mov %%i4, %%o2
619 \\ mov %%i5, %%o3620 \\ mov %%i5, %%o3
620 \\ ldx [%%fp + 192 - 2*8 + 2047], %%o4621 \\ ldx [%%fp + 0x8af], %%o4
621 \\ t 0x6d622 \\ t 0x6d
622 \\ bcs,pn %%xcc, 2f623 \\ bcs,pn %%xcc, 2f
623 \\ nop624 \\ nop
624 \\ # sparc64 returns the child pid in o0 and a flag telling625 \\ # The child pid is returned in o0 while o1 tells if this
625 \\ # whether the process is the child in o1626 \\ # process is # the child (=1) or the parent (=0).
626 \\ brnz %%o1, 1f627 \\ brnz %%o1, 1f
627 \\ nop628 \\ nop
628 \\ # This is the parent process, return the child pid629 \\ # Parent process, return the child pid
629 \\ mov %%o0, %%i0630 \\ mov %%o0, %%i0
630 \\ ret631 \\ ret
631 \\ restore632 \\ restore
632 \\1:633 \\1:
633 \\ # This is the child process634 \\ # Child process, call func(arg)
634 \\ mov %%g0, %%fp635 \\ mov %%g0, %%fp
635 \\ call %%g2636 \\ call %%g2
636 \\ mov %%g3, %%o0637 \\ mov %%g3, %%o0