Align stack to 16 bytes to avoid SIGBUS (#207)
Since callbackasm1 returns to the caller of its caller it wasn't aligning the stack to 16 bytes which is required by the AMD64 calling convention. Closes #193
- commit
- 50210c67e1f7247e6d01390a147d5a691d09d1d1
- author
- TotallyGamerJet · · 2024-01-27 15:25 UTC
- committer
- GitHub · · 2024-01-27 15:25 UTC
- parent
- e5188d3
- signature
- GPG Unverified
B5690EEEBB952194The key is unknown
3 files · +8 -11
M .github/workflows/test.yml +2 -2
| @@ -7,7 +7,7 @@ jobs: | |||
| 7 | 7 | strategy: | |
| 8 | 8 | matrix: | |
| 9 | 9 | os: [ubuntu-latest, macos-latest, windows-latest] | |
| 10 | - | go: ['1.18.x', '1.19.x', '1.20.x', '1.21.x'] | |
| 10 | + | go: ['1.18.x', '1.19.x', '1.20.x', '1.21.x', '1.22.0-rc.2'] | |
| 11 | 11 | name: Test with Go ${{ matrix.go }} on ${{ matrix.os }} | |
| 12 | 12 | runs-on: ${{ matrix.os }} | |
| 13 | 13 | defaults: | |
| @@ -110,7 +110,7 @@ jobs: | |||
| 110 | 110 | freebsd: | |
| 111 | 111 | strategy: | |
| 112 | 112 | matrix: | |
| 113 | - | go: ['1.18.10', '1.19.12', '1.20.7', '1.21.0'] | |
| 113 | + | go: ['1.18.10', '1.19.12', '1.20.7', '1.21.0', '1.22rc2'] | |
| 114 | 114 | name: Test with Go ${{ matrix.go }} on FreeBSD | |
| 115 | 115 | runs-on: ubuntu-22.04 | |
| 116 | 116 | defaults: | |
| @@ -7,7 +7,7 @@ jobs: | |||||
| 7 | strategy: | 7 | strategy: | ||
| 8 | matrix: | 8 | matrix: | ||
| 9 | os: [ubuntu-latest, macos-latest, windows-latest] | 9 | os: [ubuntu-latest, macos-latest, windows-latest] | ||
| 10 | - | go: ['1.18.x', '1.19.x', '1.20.x', '1.21.x'] | 10 | + | go: ['1.18.x', '1.19.x', '1.20.x', '1.21.x', '1.22.0-rc.2'] |
| 11 | name: Test with Go ${{ matrix.go }} on ${{ matrix.os }} | 11 | name: Test with Go ${{ matrix.go }} on ${{ matrix.os }} | ||
| 12 | runs-on: ${{ matrix.os }} | 12 | runs-on: ${{ matrix.os }} | ||
| 13 | defaults: | 13 | defaults: | ||
| @@ -110,7 +110,7 @@ jobs: | |||||
| 110 | freebsd: | 110 | freebsd: | ||
| 111 | strategy: | 111 | strategy: | ||
| 112 | matrix: | 112 | matrix: | ||
| 113 | - | go: ['1.18.10', '1.19.12', '1.20.7', '1.21.0'] | 113 | + | go: ['1.18.10', '1.19.12', '1.20.7', '1.21.0', '1.22rc2'] |
| 114 | name: Test with Go ${{ matrix.go }} on FreeBSD | 114 | name: Test with Go ${{ matrix.go }} on FreeBSD | ||
| 115 | runs-on: ubuntu-22.04 | 115 | runs-on: ubuntu-22.04 | ||
| 116 | defaults: | 116 | defaults: | ||
M internal/fakecgo/asm_amd64.s +1 -1
| @@ -10,7 +10,7 @@ | |||
| 10 | 10 | // Saves C callee-saved registers and calls cgocallback with three arguments. | |
| 11 | 11 | // fn is the PC of a func(a unsafe.Pointer) function. | |
| 12 | 12 | // This signature is known to SWIG, so we can't change it. | |
| 13 | - | TEXT crosscall2(SB), NOSPLIT|NOFRAME, $0-0 | |
| 13 | + | TEXT crosscall2(SB), NOSPLIT, $0-0 | |
| 14 | 14 | PUSH_REGS_HOST_TO_ABI0() | |
| 15 | 15 | ||
| 16 | 16 | // Make room for arguments to cgocallback. | |
| @@ -10,7 +10,7 @@ | |||||
| 10 | // Saves C callee-saved registers and calls cgocallback with three arguments. | 10 | // Saves C callee-saved registers and calls cgocallback with three arguments. | ||
| 11 | // fn is the PC of a func(a unsafe.Pointer) function. | 11 | // fn is the PC of a func(a unsafe.Pointer) function. | ||
| 12 | // This signature is known to SWIG, so we can't change it. | 12 | // This signature is known to SWIG, so we can't change it. | ||
| 13 | - | TEXT crosscall2(SB), NOSPLIT|NOFRAME, $0-0 | 13 | + | TEXT crosscall2(SB), NOSPLIT, $0-0 |
| 14 | PUSH_REGS_HOST_TO_ABI0() | 14 | PUSH_REGS_HOST_TO_ABI0() | ||
| 15 | 15 | ||||
| 16 | // Make room for arguments to cgocallback. | 16 | // Make room for arguments to cgocallback. | ||
M sys_amd64.s +5 -8
| @@ -96,11 +96,9 @@ TEXT syscall15X(SB), NOSPLIT|NOFRAME, $0 | |||
| 96 | 96 | RET | |
| 97 | 97 | ||
| 98 | 98 | TEXT callbackasm1(SB), NOSPLIT|NOFRAME, $0 | |
| 99 | - | // remove return address from stack, we are not returning to callbackasm, but to its caller. | |
| 100 | - | MOVQ 0(SP), AX | |
| 101 | - | ADDQ $8, SP | |
| 102 | - | ||
| 103 | - | MOVQ 0(SP), R10 // get the return SP so that we can align register args with stack args | |
| 99 | + | MOVQ 0(SP), AX // save the return address to calculate the cb index | |
| 100 | + | MOVQ 8(SP), R10 // get the return SP so that we can align register args with stack args | |
| 101 | + | ADDQ $8, SP // remove return address from stack, we are not returning to callbackasm, but to its caller. | |
| 104 | 102 | ||
| 105 | 103 | // make space for first six int and 8 float arguments below the frame | |
| 106 | 104 | ADJSP $14*8, SP | |
| @@ -120,7 +118,7 @@ TEXT callbackasm1(SB), NOSPLIT|NOFRAME, $0 | |||
| 120 | 118 | MOVQ R9, (14*8)(SP) | |
| 121 | 119 | LEAQ 8(SP), R8 // R8 = address of args vector | |
| 122 | 120 | ||
| 123 | - | MOVQ R10, 0(SP) // push the stack pointer below registers | |
| 121 | + | PUSHQ R10 // push the stack pointer below registers | |
| 124 | 122 | ||
| 125 | 123 | // determine index into runtime·cbs table | |
| 126 | 124 | MOVQ $callbackasm(SB), DX | |
| @@ -156,8 +154,7 @@ TEXT callbackasm1(SB), NOSPLIT|NOFRAME, $0 | |||
| 156 | 154 | ||
| 157 | 155 | POP_REGS_HOST_TO_ABI0() | |
| 158 | 156 | ||
| 159 | - | MOVQ 0(SP), R10 // get the SP back | |
| 160 | - | ||
| 157 | + | POPQ R10 // get the SP back | |
| 161 | 158 | ADJSP $-14*8, SP // remove arguments | |
| 162 | 159 | ||
| 163 | 160 | MOVQ R10, 0(SP) | |
| @@ -96,11 +96,9 @@ TEXT syscall15X(SB), NOSPLIT|NOFRAME, $0 | |||||
| 96 | RET | 96 | RET | ||
| 97 | 97 | ||||
| 98 | TEXT callbackasm1(SB), NOSPLIT|NOFRAME, $0 | 98 | TEXT callbackasm1(SB), NOSPLIT|NOFRAME, $0 | ||
| 99 | - | // remove return address from stack, we are not returning to callbackasm, but to its caller. | 99 | + | MOVQ 0(SP), AX // save the return address to calculate the cb index |
| 100 | - | MOVQ 0(SP), AX | 100 | + | MOVQ 8(SP), R10 // get the return SP so that we can align register args with stack args |
| 101 | - | ADDQ $8, SP | 101 | + | ADDQ $8, SP // remove return address from stack, we are not returning to callbackasm, but to its caller. |
| 102 | - | ||||
| 103 | - | MOVQ 0(SP), R10 // get the return SP so that we can align register args with stack args | |||
| 104 | 102 | ||||
| 105 | // make space for first six int and 8 float arguments below the frame | 103 | // make space for first six int and 8 float arguments below the frame | ||
| 106 | ADJSP $14*8, SP | 104 | ADJSP $14*8, SP | ||
| @@ -120,7 +118,7 @@ TEXT callbackasm1(SB), NOSPLIT|NOFRAME, $0 | |||||
| 120 | MOVQ R9, (14*8)(SP) | 118 | MOVQ R9, (14*8)(SP) | ||
| 121 | LEAQ 8(SP), R8 // R8 = address of args vector | 119 | LEAQ 8(SP), R8 // R8 = address of args vector | ||
| 122 | 120 | ||||
| 123 | - | MOVQ R10, 0(SP) // push the stack pointer below registers | 121 | + | PUSHQ R10 // push the stack pointer below registers |
| 124 | 122 | ||||
| 125 | // determine index into runtime·cbs table | 123 | // determine index into runtime·cbs table | ||
| 126 | MOVQ $callbackasm(SB), DX | 124 | MOVQ $callbackasm(SB), DX | ||
| @@ -156,8 +154,7 @@ TEXT callbackasm1(SB), NOSPLIT|NOFRAME, $0 | |||||
| 156 | 154 | ||||
| 157 | POP_REGS_HOST_TO_ABI0() | 155 | POP_REGS_HOST_TO_ABI0() | ||
| 158 | 156 | ||||
| 159 | - | MOVQ 0(SP), R10 // get the SP back | 157 | + | POPQ R10 // get the SP back |
| 160 | - | ||||
| 161 | ADJSP $-14*8, SP // remove arguments | 158 | ADJSP $-14*8, SP // remove arguments | ||
| 162 | 159 | ||||
| 163 | MOVQ R10, 0(SP) | 160 | MOVQ R10, 0(SP) | ||