Skip to content

Commit 7b5979e

Browse files
tklausergopherbot
authored andcommitted
unix: remove Go 1.12 compatibility on darwin
Go 1.12 was released more than 3 years ago. Dropping support for it will simplify generating the wrappers needed for Getdirentries implementation. Change-Id: If24bf6ff9076fb4e281948c67bac87744df98d7a Reviewed-on: https://go-review.googlesource.com/c/sys/+/430176 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
1 parent 63ea559 commit 7b5979e

13 files changed

+188
-305
lines changed

unix/mkall.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,6 @@ esac
214214
if [ "$GOOSARCH" == "aix_ppc64" ]; then
215215
# aix/ppc64 script generates files instead of writing to stdin.
216216
echo "$mksyscall -tags $GOOS,$GOARCH $syscall_goos $GOOSARCH_in && gofmt -w zsyscall_$GOOSARCH.go && gofmt -w zsyscall_"$GOOSARCH"_gccgo.go && gofmt -w zsyscall_"$GOOSARCH"_gc.go " ;
217-
elif [ "$GOOS" == "darwin" ]; then
218-
# 1.12 and later, syscalls via libSystem
219-
echo "$mksyscall -tags $GOOS,$GOARCH,go1.12 $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go";
220-
# 1.13 and later, syscalls via libSystem (including syscallPtr)
221-
echo "$mksyscall -tags $GOOS,$GOARCH,go1.13 syscall_darwin.1_13.go |gofmt >zsyscall_$GOOSARCH.1_13.go";
222217
elif [ "$GOOS" == "illumos" ]; then
223218
# illumos code generation requires a --illumos switch
224219
echo "$mksyscall -illumos -tags illumos,$GOARCH syscall_illumos.go |gofmt > zsyscall_illumos_$GOARCH.go";

unix/mkasm.go

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func archPtrSize(arch string) int {
3131
}
3232
}
3333

34-
func generateASMFile(arch string, inFileNames []string, outFileName, buildTags string) map[string]bool {
34+
func generateASMFile(arch string, inFileNames []string, outFileName string) map[string]bool {
3535
trampolines := map[string]bool{}
3636
var orderedTrampolines []string
3737
for _, inFileName := range inFileNames {
@@ -59,11 +59,6 @@ func generateASMFile(arch string, inFileNames []string, outFileName, buildTags s
5959
fmt.Fprintf(&out, "// go run mkasm.go %s\n", strings.Join(os.Args[1:], " "))
6060
fmt.Fprintf(&out, "// Code generated by the command above; DO NOT EDIT.\n")
6161
fmt.Fprintf(&out, "\n")
62-
if buildTags != "" {
63-
fmt.Fprintf(&out, "//go:build %s\n", buildTags)
64-
fmt.Fprintf(&out, "// +build %s\n", buildTags)
65-
fmt.Fprintf(&out, "\n")
66-
}
6762
fmt.Fprintf(&out, "#include \"textflag.h\"\n")
6863
for _, fn := range orderedTrampolines {
6964
fmt.Fprintf(&out, "\nTEXT %s_trampoline<>(SB),NOSPLIT,$0-0\n", fn)
@@ -121,7 +116,6 @@ func main() {
121116
}
122117
goos, arch := os.Args[1], os.Args[2]
123118

124-
buildTags := ""
125119
syscallFilename := fmt.Sprintf("syscall_%s.go", goos)
126120
syscallArchFilename := fmt.Sprintf("syscall_%s_%s.go", goos, arch)
127121
zsyscallArchFilename := fmt.Sprintf("zsyscall_%s_%s.go", goos, arch)
@@ -133,25 +127,9 @@ func main() {
133127
zsyscallArchFilename,
134128
}
135129

136-
if goos == "darwin" {
137-
buildTags = "go1.12"
138-
}
139-
trampolines := generateASMFile(arch, inFileNames, zsyscallASMFileName, buildTags)
140-
141-
if goos != "darwin" {
142-
return
143-
}
130+
trampolines := generateASMFile(arch, inFileNames, zsyscallASMFileName)
144131

145-
inFileNames = []string{
146-
"syscall_darwin.1_13.go",
147-
fmt.Sprintf("zsyscall_darwin_%s.1_13.go", arch),
148-
}
149-
trampolines2 := generateASMFile(arch, inFileNames, fmt.Sprintf("zsyscall_darwin_%s.1_13.s", arch), "go1.13")
150-
151-
// merge trampolines
152-
for trampoline := range trampolines2 {
153-
trampolines[trampoline] = true
132+
if goos == "darwin" {
133+
writeDarwinTest(trampolines, fmt.Sprintf("darwin_%s_test.go", arch), arch)
154134
}
155-
156-
writeDarwinTest(trampolines, fmt.Sprintf("darwin_%s_test.go", arch), arch)
157135
}

unix/syscall_darwin.1_12.go

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

unix/syscall_darwin.1_13.go

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

unix/syscall_darwin.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,96 @@ import (
1919
"unsafe"
2020
)
2121

22+
//sys closedir(dir uintptr) (err error)
23+
//sys readdir_r(dir uintptr, entry *Dirent, result **Dirent) (res Errno)
24+
25+
func fdopendir(fd int) (dir uintptr, err error) {
26+
r0, _, e1 := syscall_syscallPtr(libc_fdopendir_trampoline_addr, uintptr(fd), 0, 0)
27+
dir = uintptr(r0)
28+
if e1 != 0 {
29+
err = errnoErr(e1)
30+
}
31+
return
32+
}
33+
34+
var libc_fdopendir_trampoline_addr uintptr
35+
36+
//go:cgo_import_dynamic libc_fdopendir fdopendir "/usr/lib/libSystem.B.dylib"
37+
38+
func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
39+
// Simulate Getdirentries using fdopendir/readdir_r/closedir.
40+
// We store the number of entries to skip in the seek
41+
// offset of fd. See issue #31368.
42+
// It's not the full required semantics, but should handle the case
43+
// of calling Getdirentries or ReadDirent repeatedly.
44+
// It won't handle assigning the results of lseek to *basep, or handle
45+
// the directory being edited underfoot.
46+
skip, err := Seek(fd, 0, 1 /* SEEK_CUR */)
47+
if err != nil {
48+
return 0, err
49+
}
50+
51+
// We need to duplicate the incoming file descriptor
52+
// because the caller expects to retain control of it, but
53+
// fdopendir expects to take control of its argument.
54+
// Just Dup'ing the file descriptor is not enough, as the
55+
// result shares underlying state. Use Openat to make a really
56+
// new file descriptor referring to the same directory.
57+
fd2, err := Openat(fd, ".", O_RDONLY, 0)
58+
if err != nil {
59+
return 0, err
60+
}
61+
d, err := fdopendir(fd2)
62+
if err != nil {
63+
Close(fd2)
64+
return 0, err
65+
}
66+
defer closedir(d)
67+
68+
var cnt int64
69+
for {
70+
var entry Dirent
71+
var entryp *Dirent
72+
e := readdir_r(d, &entry, &entryp)
73+
if e != 0 {
74+
return n, errnoErr(e)
75+
}
76+
if entryp == nil {
77+
break
78+
}
79+
if skip > 0 {
80+
skip--
81+
cnt++
82+
continue
83+
}
84+
85+
reclen := int(entry.Reclen)
86+
if reclen > len(buf) {
87+
// Not enough room. Return for now.
88+
// The counter will let us know where we should start up again.
89+
// Note: this strategy for suspending in the middle and
90+
// restarting is O(n^2) in the length of the directory. Oh well.
91+
break
92+
}
93+
94+
// Copy entry into return buffer.
95+
s := unsafe.Slice((*byte)(unsafe.Pointer(&entry)), reclen)
96+
copy(buf, s)
97+
98+
buf = buf[reclen:]
99+
n += reclen
100+
cnt++
101+
}
102+
// Set the seek offset of the input fd to record
103+
// how many files we've already returned.
104+
_, err = Seek(fd, cnt, 0 /* SEEK_SET */)
105+
if err != nil {
106+
return n, err
107+
}
108+
109+
return n, nil
110+
}
111+
22112
// SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets.
23113
type SockaddrDatalink struct {
24114
Len uint8

unix/zsyscall_darwin_amd64.1_13.go

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

unix/zsyscall_darwin_amd64.1_13.s

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

0 commit comments

Comments
 (0)