mirror of
https://github.com/golang/sys.git
synced 2026-02-08 03:36:03 +03:00
Getdirentries is implemented with the __getdirentries64 function
in libSystem.dylib on darwin/{386,amd64}. That function can't be used in
an app store application.
Implement Getdirentries using the underlying
fdopendir/readdir_r/closedir for Go 1.13. The simulation isn't faithful,
and could be slow, but it should handle common cases.
For Go 1.12, fall back to raw syscalls since syscall.syscallPtr needed
to use fdopendir from libSystem.dylib is not available.
Follow CL 168479 and CL 170892 which did the same for syscall in the
stdlib.
Tested on darwin/amd64 with Go 1.11, Go 1.12 and Go 1.13
Fixes golang/go#34400
Change-Id: I631382aaea9ee7e0c4ed09e06ad5427efc620769
Reviewed-on: https://go-review.googlesource.com/c/sys/+/196478
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
79 lines
2.2 KiB
Go
79 lines
2.2 KiB
Go
// Copyright 2018 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// +build ignore
|
|
|
|
// mkasm_darwin.go generates assembly trampolines to call libSystem routines from Go.
|
|
//This program must be run after mksyscall.go.
|
|
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"log"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
func writeASMFile(in string, fileName string, buildTags string) {
|
|
trampolines := map[string]bool{}
|
|
|
|
var out bytes.Buffer
|
|
|
|
fmt.Fprintf(&out, "// go run mkasm_darwin.go %s\n", strings.Join(os.Args[1:], " "))
|
|
fmt.Fprintf(&out, "// Code generated by the command above; DO NOT EDIT.\n")
|
|
fmt.Fprintf(&out, "\n")
|
|
fmt.Fprintf(&out, "// +build %s\n", buildTags)
|
|
fmt.Fprintf(&out, "\n")
|
|
fmt.Fprintf(&out, "#include \"textflag.h\"\n")
|
|
for _, line := range strings.Split(in, "\n") {
|
|
if !strings.HasPrefix(line, "func ") || !strings.HasSuffix(line, "_trampoline()") {
|
|
continue
|
|
}
|
|
fn := line[5 : len(line)-13]
|
|
if !trampolines[fn] {
|
|
trampolines[fn] = true
|
|
fmt.Fprintf(&out, "TEXT ·%s_trampoline(SB),NOSPLIT,$0-0\n", fn)
|
|
fmt.Fprintf(&out, "\tJMP\t%s(SB)\n", fn)
|
|
}
|
|
}
|
|
err := ioutil.WriteFile(fileName, out.Bytes(), 0644)
|
|
if err != nil {
|
|
log.Fatalf("can't write %s: %s", fileName, err)
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
in1, err := ioutil.ReadFile("syscall_darwin.go")
|
|
if err != nil {
|
|
log.Fatalf("can't open syscall_darwin.go: %s", err)
|
|
}
|
|
arch := os.Args[1]
|
|
in2, err := ioutil.ReadFile(fmt.Sprintf("syscall_darwin_%s.go", arch))
|
|
if err != nil {
|
|
log.Fatalf("can't open syscall_darwin_%s.go: %s", arch, err)
|
|
}
|
|
in3, err := ioutil.ReadFile(fmt.Sprintf("zsyscall_darwin_%s.go", arch))
|
|
if err != nil {
|
|
log.Fatalf("can't open zsyscall_darwin_%s.go: %s", arch, err)
|
|
}
|
|
in := string(in1) + string(in2) + string(in3)
|
|
|
|
writeASMFile(in, fmt.Sprintf("zsyscall_darwin_%s.s", arch), "go1.12")
|
|
|
|
in1, err = ioutil.ReadFile("syscall_darwin.1_13.go")
|
|
if err != nil {
|
|
log.Fatalf("can't open syscall_darwin.1_13.go: %s", err)
|
|
}
|
|
in2, err = ioutil.ReadFile(fmt.Sprintf("zsyscall_darwin_%s.1_13.go", arch))
|
|
if err != nil {
|
|
log.Fatalf("can't open zsyscall_darwin_%s.1_13.go: %s", arch, err)
|
|
}
|
|
|
|
in = string(in1) + string(in2)
|
|
|
|
writeASMFile(in, fmt.Sprintf("zsyscall_darwin_%s.1_13.s", arch), "go1.13")
|
|
}
|