detached 50210c6

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 UnverifiedB5690EEEBB952194 The key is unknown
3 files · +8 -11
M .github/workflows/test.yml +2 -2
@@ -7,7 +7,7 @@ jobs:
77 strategy:
88 matrix:
99 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']
1111 name: Test with Go ${{ matrix.go }} on ${{ matrix.os }}
1212 runs-on: ${{ matrix.os }}
1313 defaults:
@@ -110,7 +110,7 @@ jobs:
110110 freebsd:
111111 strategy:
112112 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']
114114 name: Test with Go ${{ matrix.go }} on FreeBSD
115115 runs-on: ubuntu-22.04
116116 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 FreeBSD114 name: Test with Go ${{ matrix.go }} on FreeBSD
115 runs-on: ubuntu-22.04115 runs-on: ubuntu-22.04
116 defaults:116 defaults:
M internal/fakecgo/asm_amd64.s +1 -1
@@ -10,7 +10,7 @@
1010 // Saves C callee-saved registers and calls cgocallback with three arguments.
1111 // fn is the PC of a func(a unsafe.Pointer) function.
1212 // 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
1414 PUSH_REGS_HOST_TO_ABI0()
1515
1616 // 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-013+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
9696 RET
9797
9898 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.
104102
105103 // make space for first six int and 8 float arguments below the frame
106104 ADJSP $14*8, SP
@@ -120,7 +118,7 @@ TEXT callbackasm1(SB), NOSPLIT|NOFRAME, $0
120118 MOVQ R9, (14*8)(SP)
121119 LEAQ 8(SP), R8 // R8 = address of args vector
122120
123- MOVQ R10, 0(SP) // push the stack pointer below registers
121+ PUSHQ R10 // push the stack pointer below registers
124122
125123 // determine index into runtime·cbs table
126124 MOVQ $callbackasm(SB), DX
@@ -156,8 +154,7 @@ TEXT callbackasm1(SB), NOSPLIT|NOFRAME, $0
156154
157155 POP_REGS_HOST_TO_ABI0()
158156
159- MOVQ 0(SP), R10 // get the SP back
160-
157+ POPQ R10 // get the SP back
161158 ADJSP $-14*8, SP // remove arguments
162159
163160 MOVQ R10, 0(SP)
@@ -96,11 +96,9 @@ TEXT syscall15X(SB), NOSPLIT|NOFRAME, $0
96 RET96 RET
97 97
98 TEXT callbackasm1(SB), NOSPLIT|NOFRAME, $098 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), AX100+ MOVQ 8(SP), R10 // get the return SP so that we can align register args with stack args
101- ADDQ $8, SP101+ 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 frame103 // make space for first six int and 8 float arguments below the frame
106 ADJSP $14*8, SP104 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 vector119 LEAQ 8(SP), R8 // R8 = address of args vector
122 120
123- MOVQ R10, 0(SP) // push the stack pointer below registers121+ PUSHQ R10 // push the stack pointer below registers
124 122
125 // determine index into runtime·cbs table123 // determine index into runtime·cbs table
126 MOVQ $callbackasm(SB), DX124 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 back157+ POPQ R10 // get the SP back
160-
161 ADJSP $-14*8, SP // remove arguments158 ADJSP $-14*8, SP // remove arguments
162 159
163 MOVQ R10, 0(SP)160 MOVQ R10, 0(SP)

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 102

↑↓ moveenter openesc close