os: Use a uintptr for NewFile
This appears to have been how it is upstream for about 10 years. Using an interface breaks if a file descriptor number is passed directly to `NewFile`, e.g., `NewFile(3, "fuzz_in")` as used in Go 1.18 fuzzing code.
Этот коммит содержится в:
родитель
bf23839931
коммит
a680bfbb7a
5 изменённых файлов: 19 добавлений и 25 удалений
|
@ -21,9 +21,9 @@ func init() {
|
||||||
// Stdin, Stdout, and Stderr are open Files pointing to the standard input,
|
// Stdin, Stdout, and Stderr are open Files pointing to the standard input,
|
||||||
// standard output, and standard error file descriptors.
|
// standard output, and standard error file descriptors.
|
||||||
var (
|
var (
|
||||||
Stdin = NewFile(unixFileHandle(syscall.Stdin), "/dev/stdin")
|
Stdin = NewFile(uintptr(syscall.Stdin), "/dev/stdin")
|
||||||
Stdout = NewFile(unixFileHandle(syscall.Stdout), "/dev/stdout")
|
Stdout = NewFile(uintptr(syscall.Stdout), "/dev/stdout")
|
||||||
Stderr = NewFile(unixFileHandle(syscall.Stderr), "/dev/stderr")
|
Stderr = NewFile(uintptr(syscall.Stderr), "/dev/stderr")
|
||||||
)
|
)
|
||||||
|
|
||||||
const DevNull = "/dev/null"
|
const DevNull = "/dev/null"
|
||||||
|
@ -87,9 +87,9 @@ func (fs unixFilesystem) Remove(path string) error {
|
||||||
return &PathError{Op: "remove", Path: path, Err: e}
|
return &PathError{Op: "remove", Path: path, Err: e}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs unixFilesystem) OpenFile(path string, flag int, perm FileMode) (FileHandle, error) {
|
func (fs unixFilesystem) OpenFile(path string, flag int, perm FileMode) (uintptr, error) {
|
||||||
fp, err := syscall.Open(path, flag, uint32(perm))
|
fp, err := syscall.Open(path, flag, uint32(perm))
|
||||||
return unixFileHandle(fp), handleSyscallError(err)
|
return uintptr(fp), handleSyscallError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// unixFileHandle is a Unix file pointer with associated methods that implement
|
// unixFileHandle is a Unix file pointer with associated methods that implement
|
||||||
|
|
|
@ -10,9 +10,9 @@ import (
|
||||||
// Stdin, Stdout, and Stderr are open Files pointing to the standard input,
|
// Stdin, Stdout, and Stderr are open Files pointing to the standard input,
|
||||||
// standard output, and standard error file descriptors.
|
// standard output, and standard error file descriptors.
|
||||||
var (
|
var (
|
||||||
Stdin = NewFile(stdioFileHandle(0), "/dev/stdin")
|
Stdin = NewFile(0, "/dev/stdin")
|
||||||
Stdout = NewFile(stdioFileHandle(1), "/dev/stdout")
|
Stdout = NewFile(1, "/dev/stdout")
|
||||||
Stderr = NewFile(stdioFileHandle(2), "/dev/stderr")
|
Stderr = NewFile(2, "/dev/stderr")
|
||||||
)
|
)
|
||||||
|
|
||||||
// isOS indicates whether we're running on a real operating system with
|
// isOS indicates whether we're running on a real operating system with
|
||||||
|
@ -32,8 +32,8 @@ type file struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFile(fd FileHandle, name string) *File {
|
func NewFile(fd uintptr, name string) *File {
|
||||||
return &File{&file{fd, name}}
|
return &File{&file{stdioFileHandle(fd), name}}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read is unsupported on this system.
|
// Read is unsupported on this system.
|
||||||
|
|
|
@ -38,8 +38,8 @@ type file struct {
|
||||||
dirinfo *dirInfo // nil unless directory being read
|
dirinfo *dirInfo // nil unless directory being read
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFile(fd FileHandle, name string) *File {
|
func NewFile(fd uintptr, name string) *File {
|
||||||
return &File{&file{fd, name, nil}}
|
return &File{&file{unixFileHandle(fd), name, nil}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Pipe() (r *File, w *File, err error) {
|
func Pipe() (r *File, w *File, err error) {
|
||||||
|
@ -48,8 +48,8 @@ func Pipe() (r *File, w *File, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
r = NewFile(unixFileHandle(p[0]), "|0")
|
r = NewFile(uintptr(p[0]), "|0")
|
||||||
w = NewFile(unixFileHandle(p[1]), "|1")
|
w = NewFile(uintptr(p[1]), "|1")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,8 +38,8 @@ type file struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFile(fd FileHandle, name string) *File {
|
func NewFile(fd uintptr, name string) *File {
|
||||||
return &File{&file{fd, name}}
|
return &File{&file{unixFileHandle(fd), name}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Pipe() (r *File, w *File, err error) {
|
func Pipe() (r *File, w *File, err error) {
|
||||||
|
@ -48,14 +48,8 @@ func Pipe() (r *File, w *File, err error) {
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
r = NewFile(
|
r = NewFile(uintptr(p[0]), "|0")
|
||||||
unixFileHandle(p[0]),
|
w = NewFile(uintptr(p[1]), "|1")
|
||||||
"|0",
|
|
||||||
)
|
|
||||||
w = NewFile(
|
|
||||||
unixFileHandle(p[1]),
|
|
||||||
"|1",
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ type mountPoint struct {
|
||||||
// WARNING: this interface is not finalized and may change in a future version.
|
// WARNING: this interface is not finalized and may change in a future version.
|
||||||
type Filesystem interface {
|
type Filesystem interface {
|
||||||
// OpenFile opens the named file.
|
// OpenFile opens the named file.
|
||||||
OpenFile(name string, flag int, perm FileMode) (FileHandle, error)
|
OpenFile(name string, flag int, perm FileMode) (uintptr, error)
|
||||||
|
|
||||||
// Mkdir creates a new directoy with the specified permission (before
|
// Mkdir creates a new directoy with the specified permission (before
|
||||||
// umask). Some filesystems may not support directories or permissions.
|
// umask). Some filesystems may not support directories or permissions.
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче