Skip to content

Commit 4ab8056

Browse files
committed
syscall: restore linux raw vfork override
1 parent b1f08c0 commit 4ab8056

File tree

5 files changed

+74
-27
lines changed

5 files changed

+74
-27
lines changed

internal/plan9asm/filter_linux_test.go

Lines changed: 0 additions & 22 deletions
This file was deleted.

internal/plan9asm/translate.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ func TranslateSourceModuleForPkgWithOptions(pkg *packages.Package, sfile string,
123123
}
124124

125125
func shouldKeepResolvedFunc(pkgPath, goos, goarch, resolved string) bool {
126+
if pkgPath == "syscall" && goos == "linux" && (goarch == "arm64" || goarch == "amd64") && strings.HasSuffix(resolved, "rawVforkSyscall") {
127+
return false
128+
}
126129
return true
127130
}
128131

internal/plan9asm/translate_helpers_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,12 @@ func TestTranslateHelperFunctions(t *testing.T) {
135135
t.Fatalf("resolveSymFuncForTarget darwin RawSyscall6 = %q", got)
136136
}
137137

138+
if shouldKeepResolvedFunc("syscall", "linux", "amd64", "syscall.rawVforkSyscall") {
139+
t.Fatal("linux rawVforkSyscall should be filtered")
140+
}
138141
if !shouldKeepResolvedFunc("syscall", "linux", "amd64", "syscall.Syscall") {
139142
t.Fatal("normal syscall symbol should be kept")
140143
}
141-
if !shouldKeepResolvedFunc("syscall", "linux", "amd64", "syscall.rawVforkSyscall") {
142-
t.Fatal("linux rawVforkSyscall should be kept")
143-
}
144144
if !shouldKeepResolvedFunc("syscall", "darwin", "arm64", "syscall.RawSyscall") {
145145
t.Fatal("darwin RawSyscall should be kept")
146146
}
@@ -153,8 +153,8 @@ func TestTranslateHelperFunctions(t *testing.T) {
153153
}
154154
funcs := []extplan9asm.Func{{Sym: "·rawVforkSyscall"}, {Sym: "·Keep"}}
155155
filtered := FilterFuncs("syscall", "linux", "amd64", funcs, ResolveSymFunc("syscall"))
156-
if len(filtered) != len(funcs) {
157-
t.Fatalf("FilterFuncs linux = %#v, want all kept", filtered)
156+
if len(filtered) != 1 || filtered[0].Sym != "·Keep" {
157+
t.Fatalf("FilterFuncs linux = %#v, want only Keep", filtered)
158158
}
159159
darwinFuncs := []extplan9asm.Func{{Sym: "·RawSyscall"}, {Sym: "·RawSyscall6"}, {Sym: "·Syscall"}}
160160
darwinFiltered := FilterFuncs("syscall", "darwin", "arm64", darwinFuncs, resolveDarwinSyscall)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//go:build linux && (amd64 || arm64) && !go1.22
2+
// +build linux
3+
// +build amd64 arm64
4+
// +build !go1.22
5+
6+
package runtime
7+
8+
import (
9+
_ "unsafe"
10+
11+
c "github.com/goplus/llgo/runtime/internal/clite"
12+
cliteos "github.com/goplus/llgo/runtime/internal/clite/os"
13+
clitesyscall "github.com/goplus/llgo/runtime/internal/clite/syscall"
14+
)
15+
16+
//go:linkname c_syscall C.syscall
17+
func c_syscall(sysno c.Long, __llgo_va_list ...any) c.Long
18+
19+
//go:linkname syscall_rawVforkSyscall syscall.rawVforkSyscall
20+
func syscall_rawVforkSyscall(trap, a1, a2 uintptr) (r1 uintptr, err uintptr) {
21+
if trap == uintptr(clitesyscall.SYS_CLONE) {
22+
pid := cliteos.Fork()
23+
if pid < 0 {
24+
return uintptr(int64(pid)), uintptr(cliteos.Errno())
25+
}
26+
return uintptr(int64(pid)), 0
27+
}
28+
r := c_syscall(c.Long(trap), c.Long(a1), c.Long(a2))
29+
if r == -1 {
30+
return uintptr(r), uintptr(cliteos.Errno())
31+
}
32+
return uintptr(r), 0
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//go:build linux && (amd64 || arm64) && go1.22
2+
// +build linux
3+
// +build amd64 arm64
4+
// +build go1.22
5+
6+
package runtime
7+
8+
import (
9+
_ "unsafe"
10+
11+
c "github.com/goplus/llgo/runtime/internal/clite"
12+
cliteos "github.com/goplus/llgo/runtime/internal/clite/os"
13+
clitesyscall "github.com/goplus/llgo/runtime/internal/clite/syscall"
14+
)
15+
16+
//go:linkname c_syscall C.syscall
17+
func c_syscall(sysno c.Long, __llgo_va_list ...any) c.Long
18+
19+
//go:linkname syscall_rawVforkSyscall syscall.rawVforkSyscall
20+
func syscall_rawVforkSyscall(trap, a1, a2, a3 uintptr) (r1 uintptr, err uintptr) {
21+
if trap == uintptr(clitesyscall.SYS_CLONE) {
22+
pid := cliteos.Fork()
23+
if pid < 0 {
24+
return uintptr(int64(pid)), uintptr(cliteos.Errno())
25+
}
26+
return uintptr(int64(pid)), 0
27+
}
28+
r := c_syscall(c.Long(trap), c.Long(a1), c.Long(a2), c.Long(a3))
29+
if r == -1 {
30+
return uintptr(r), uintptr(cliteos.Errno())
31+
}
32+
return uintptr(r), 0
33+
}

0 commit comments

Comments
 (0)