diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-10-07 17:22:08 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-10-07 17:22:08 +0000 |
commit | df07d17b578c936987013d4f082c2db300b24dd7 (patch) | |
tree | dfed1026d5397402b85feef171a5e9c2c1ff4dae /libgo | |
parent | 3dabf8ddc9b4f0da3277991d20525d062e5b5138 (diff) | |
download | gcc-df07d17b578c936987013d4f082c2db300b24dd7.tar.gz |
PR go/67874
net, runtime: Call C library fcntl function rather than syscall.Syscall.
Not all systems define a fcntl syscall; some only have fcntl64.
Fixes GCC PR go/67874.
Reviewed-on: https://go-review.googlesource.com/15497
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@228576 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo')
-rw-r--r-- | libgo/go/net/fd_unix.go | 10 | ||||
-rw-r--r-- | libgo/runtime/go-varargs.c | 24 |
2 files changed, 33 insertions, 1 deletions
diff --git a/libgo/go/net/fd_unix.go b/libgo/go/net/fd_unix.go index 7a97faeba34..45a4eb8f123 100644 --- a/libgo/go/net/fd_unix.go +++ b/libgo/go/net/fd_unix.go @@ -442,13 +442,21 @@ func (fd *netFD) accept() (netfd *netFD, err error) { return netfd, nil } +// Use a helper function to call fcntl. This is defined in C in +// libgo/runtime. +//extern __go_fcntl_uintptr +func fcntl(uintptr, uintptr, uintptr) (uintptr, uintptr) + // tryDupCloexec indicates whether F_DUPFD_CLOEXEC should be used. // If the kernel doesn't support it, this is set to 0. var tryDupCloexec = int32(1) func dupCloseOnExec(fd int) (newfd int, err error) { if atomic.LoadInt32(&tryDupCloexec) == 1 && syscall.F_DUPFD_CLOEXEC != 0 { - r0, _, e1 := syscall.Syscall(syscall.SYS_FCNTL, uintptr(fd), syscall.F_DUPFD_CLOEXEC, 0) + syscall.Entersyscall() + r0, errno := fcntl(uintptr(fd), syscall.F_DUPFD_CLOEXEC, 0) + syscall.Exitsyscall() + e1 := syscall.Errno(errno) if runtime.GOOS == "darwin" && e1 == syscall.EBADF { // On OS X 10.6 and below (but we only support // >= 10.6), F_DUPFD_CLOEXEC is unsupported diff --git a/libgo/runtime/go-varargs.c b/libgo/runtime/go-varargs.c index 705f55ee20b..7a2006fbab2 100644 --- a/libgo/runtime/go-varargs.c +++ b/libgo/runtime/go-varargs.c @@ -6,6 +6,8 @@ #include "config.h" +#include <errno.h> +#include <stdint.h> #include <sys/types.h> #include <fcntl.h> @@ -32,6 +34,28 @@ __go_fcntl_flock (int fd, int cmd, struct flock *arg) return fcntl (fd, cmd, arg); } +// This is for the net package. We use uintptr_t to make sure that +// the types match, since the Go and C "int" types are not the same. +struct go_fcntl_ret { + uintptr_t r; + uintptr_t err; +}; + +struct go_fcntl_ret +__go_fcntl_uintptr (uintptr_t fd, uintptr_t cmd, uintptr_t arg) +{ + int r; + struct go_fcntl_ret ret; + + r = fcntl ((int) fd, (int) cmd, (int) arg); + ret.r = (uintptr_t) r; + if (r < 0) + ret.err = (uintptr_t) errno; + else + ret.err = 0; + return ret; +} + #ifdef HAVE_OPEN64 int |