-
Notifications
You must be signed in to change notification settings - Fork 17.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
runtime,os,syscall,internal/poll: replace getdirentries on iOS
The getdirentries syscall is considered private API on iOS and is rejected by the App Store submission checks. Replace it with the fdopendir/readdir_r/closedir syscalls. Fixes #28984 Change-Id: I73341b124310e9cb34834a95f946769f337ec5b7 Reviewed-on: https://go-review.googlesource.com/c/153338 Reviewed-by: Keith Randall <khr@golang.org>
- Loading branch information
Showing
24 changed files
with
400 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// 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 darwin | ||
// +build arm arm64 | ||
|
||
package poll | ||
|
||
import ( | ||
"syscall" | ||
_ "unsafe" // for go:linkname | ||
) | ||
|
||
// OpenDir returns a pointer to a DIR structure suitable for | ||
// ReadDir. In case of an error, the name of the failed | ||
// syscall is returned along with a syscall.Errno. | ||
func (fd *FD) OpenDir() (uintptr, string, error) { | ||
// fdopendir(3) takes control of the file descriptor, | ||
// so use a dup. | ||
fd2, call, err := fd.Dup() | ||
if err != nil { | ||
return 0, call, err | ||
} | ||
dir, err := fdopendir(fd2) | ||
if err != nil { | ||
syscall.Close(fd2) | ||
return 0, "fdopendir", err | ||
} | ||
return dir, "", nil | ||
} | ||
|
||
// Implemented in syscall/syscall_darwin.go. | ||
//go:linkname fdopendir syscall.fdopendir | ||
func fdopendir(fd int) (dir uintptr, err error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright 2009 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 darwin | ||
// +build arm arm64 | ||
|
||
package os | ||
|
||
import ( | ||
"io" | ||
"runtime" | ||
"syscall" | ||
"unsafe" | ||
) | ||
|
||
// Auxiliary information if the File describes a directory | ||
type dirInfo struct { | ||
dir uintptr // Pointer to DIR structure from dirent.h | ||
} | ||
|
||
func (d *dirInfo) close() { | ||
if d.dir == 0 { | ||
return | ||
} | ||
closedir(d.dir) | ||
d.dir = 0 | ||
} | ||
|
||
func (f *File) readdirnames(n int) (names []string, err error) { | ||
if f.dirinfo == nil { | ||
dir, call, errno := f.pfd.OpenDir() | ||
if errno != nil { | ||
return nil, wrapSyscallError(call, errno) | ||
} | ||
f.dirinfo = &dirInfo{ | ||
dir: dir, | ||
} | ||
} | ||
d := f.dirinfo | ||
|
||
size := n | ||
if size <= 0 { | ||
size = 100 | ||
n = -1 | ||
} | ||
|
||
names = make([]string, 0, size) | ||
var dirent syscall.Dirent | ||
var entptr uintptr | ||
for len(names) < size { | ||
if res := readdir_r(d.dir, uintptr(unsafe.Pointer(&dirent)), uintptr(unsafe.Pointer(&entptr))); res != 0 { | ||
return names, wrapSyscallError("readdir", syscall.Errno(res)) | ||
} | ||
if entptr == 0 { // EOF | ||
break | ||
} | ||
if dirent.Ino == 0 { | ||
continue | ||
} | ||
name := (*[len(syscall.Dirent{}.Name)]byte)(unsafe.Pointer(&dirent.Name))[:] | ||
for i, c := range name { | ||
if c == 0 { | ||
name = name[:i] | ||
break | ||
} | ||
} | ||
// Check for useless names before allocating a string. | ||
if string(name) == "." || string(name) == ".." { | ||
continue | ||
} | ||
names = append(names, string(name)) | ||
runtime.KeepAlive(f) | ||
} | ||
if n >= 0 && len(names) == 0 { | ||
return names, io.EOF | ||
} | ||
return names, nil | ||
} | ||
|
||
// Implemented in syscall/syscall_darwin.go. | ||
|
||
//go:linkname closedir syscall.closedir | ||
func closedir(dir uintptr) (err error) | ||
|
||
//go:linkname readdir_r syscall.readdir_r | ||
func readdir_r(dir, entry, result uintptr) (res int) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.