darwin: fix syscall.Open on darwin/arm64
Unfortunately the calling convention for variadic functions is different from the calling convention of regular functions on darwin/arm64, and open happens to be such a variadic function. The syscall package treated it like a regular function, which resulted in buggy behavior. This fix introduces a wrapper function. This is the cleanest change I could come up with.
Этот коммит содержится в:
родитель
2072d1bb5c
коммит
7e9d84777e
6 изменённых файлов: 24 добавлений и 5 удалений
7
src/runtime/os_darwin.c
Обычный файл
7
src/runtime/os_darwin.c
Обычный файл
|
@ -0,0 +1,7 @@
|
||||||
|
// Wrapper function because 'open' is a variadic function and variadic functions
|
||||||
|
// use a different (incompatible) calling convention on darwin/arm64.
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
int syscall_libc_open(const char *pathname, int flags, mode_t mode) {
|
||||||
|
return open(pathname, flags, mode);
|
||||||
|
}
|
|
@ -5,6 +5,8 @@ package runtime
|
||||||
|
|
||||||
import "unsafe"
|
import "unsafe"
|
||||||
|
|
||||||
|
import "C" // dummy import so that os_darwin.c works
|
||||||
|
|
||||||
const GOOS = "darwin"
|
const GOOS = "darwin"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -351,11 +351,6 @@ func libc_pread(fd int32, buf *byte, count uint, offset int64) int
|
||||||
//export lseek
|
//export lseek
|
||||||
func libc_lseek(fd int32, offset int64, whence int) int64
|
func libc_lseek(fd int32, offset int64, whence int) int64
|
||||||
|
|
||||||
// int open(const char *pathname, int flags, mode_t mode);
|
|
||||||
//
|
|
||||||
//export open
|
|
||||||
func libc_open(pathname *byte, flags int32, mode uint32) int32
|
|
||||||
|
|
||||||
// int close(int fd)
|
// int close(int fd)
|
||||||
//
|
//
|
||||||
//export close
|
//export close
|
||||||
|
|
|
@ -281,3 +281,8 @@ func libc_pipe(fds *int32) int32
|
||||||
//
|
//
|
||||||
//export getpagesize
|
//export getpagesize
|
||||||
func libc_getpagesize() int32
|
func libc_getpagesize() int32
|
||||||
|
|
||||||
|
// int open(const char *pathname, int flags, mode_t mode);
|
||||||
|
//
|
||||||
|
//export syscall_libc_open
|
||||||
|
func libc_open(pathname *byte, flags int32, mode uint32) int32
|
||||||
|
|
|
@ -71,3 +71,8 @@ func Pipe2(p []int, flags int) (err error) {
|
||||||
func Getpagesize() int {
|
func Getpagesize() int {
|
||||||
return 4096 // TODO
|
return 4096 // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// int open(const char *pathname, int flags, mode_t mode);
|
||||||
|
//
|
||||||
|
//export open
|
||||||
|
func libc_open(pathname *byte, flags int32, mode uint32) int32
|
||||||
|
|
|
@ -323,3 +323,8 @@ func libc_fstat(fd int32, ptr unsafe.Pointer) int32
|
||||||
//
|
//
|
||||||
//export lstat
|
//export lstat
|
||||||
func libc_lstat(pathname *byte, ptr unsafe.Pointer) int32
|
func libc_lstat(pathname *byte, ptr unsafe.Pointer) int32
|
||||||
|
|
||||||
|
// int open(const char *pathname, int flags, mode_t mode);
|
||||||
|
//
|
||||||
|
//export open
|
||||||
|
func libc_open(pathname *byte, flags int32, mode uint32) int32
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче