Commit cff0c39d by Ian Lance Taylor

Clean up syscalls, add some Solaris support.

From-SVN: r168738
parent 243ffa47
...@@ -596,10 +596,17 @@ go_mime_files = \ ...@@ -596,10 +596,17 @@ go_mime_files = \
if LIBGO_IS_RTEMS if LIBGO_IS_RTEMS
go_net_fd_os_file = go/net/fd_rtems.go go_net_fd_os_file = go/net/fd_rtems.go
go_net_newpollserver_file = go/net/newpollserver_rtems.go go_net_newpollserver_file = go/net/newpollserver_rtems.go
else else # !LIBGO_IS_RTEMS
if LIBGO_IS_LINUX
go_net_fd_os_file = go/net/fd_linux.go go_net_fd_os_file = go/net/fd_linux.go
go_net_newpollserver_file = go/net/newpollserver.go go_net_newpollserver_file = go/net/newpollserver.go
endif else # !LIBGO_IS_LINUX && !LIBGO_IS_RTEMS
# By default use select with pipes. Most systems should have
# something better.
go_net_fd_os_file = go/net/fd_rtems.go
go_net_newpollserver_file = go/net/newpollserver.go
endif # !LIBGO_IS_LINUX
endif # !LIBGO_IS_RTEMS
go_net_files = \ go_net_files = \
go/net/dial.go \ go/net/dial.go \
...@@ -1019,33 +1026,92 @@ go_testing_quick_files = \ ...@@ -1019,33 +1026,92 @@ go_testing_quick_files = \
go_testing_script_files = \ go_testing_script_files = \
go/testing/script/script.go go/testing/script/script.go
# Define Syscall and Syscall6.
if LIBGO_IS_RTEMS if LIBGO_IS_RTEMS
syscall_exec_os_file = syscalls/exec_stubs.go
syscall_socket_os_file = syscalls/socket_bsd.go
syscall_socket_epoll_file =
syscall_sysfile_os_file = syscalls/sysfile_rtems.go
syscall_syscall_file = syscalls/syscall_stubs.go syscall_syscall_file = syscalls/syscall_stubs.go
syscall_errstr_file = syscalls/errstr_rtems.go
syscall_errstr_decl_file = syscalls/errstr_decl_rtems.go
else else
syscall_exec_os_file = syscalls/exec.go
syscall_socket_os_file = syscalls/socket_linux.go
syscall_socket_epoll_file = syscalls/socket_epoll.go
syscall_sysfile_os_file = syscalls/sysfile_linux.go
syscall_syscall_file = syscalls/syscall.go syscall_syscall_file = syscalls/syscall.go
endif
# Declare libc functions that vary for largefile systems.
if LIBGO_IS_LINUX
# Always use lseek64 on GNU/Linux.
syscall_filesize_file = syscalls/sysfile_largefile.go
else # !LIBGO_IS_LINUX
if LIBGO_IS_SOLARIS
if LIBGO_IS_386
# Use lseek64 on 386 Solaris.
syscall_filesize_flie = syscalls/sysfile_largefile.go
else # !LIBGO_IS_LINUX && LIBGO_IS_SOLARIS && !LIBGO_IS_386
# Use lseek on amd64 Solaris.
syscall_filesize_flie = syscalls/sysfile_regfile.go
endif # !LIBGO_IS_386
else # !LIBGO_IS_LINUX && !LIBGO_IS_SOLARIS
# Use lseek by default.
syscall_filesize_file = syscalls/sysfile_regfile.go
endif # !LIBGO_IS_SOLARIS
endif # !LIBGO_IS_LINUX
# Define ForkExec, PtraceForkExec, Exec, and Wait4.
if LIBGO_IS_RTEMS
syscall_exec_os_file = syscalls/exec_stubs.go
else
syscall_exec_os_file = syscalls/exec.go
endif
# Define Sleep.
if LIBGO_IS_RTEMS
syscall_sleep_file = syscalls/sleep_rtems.go
else
syscall_sleep_file = syscalls/sleep_select.go
endif
# Define Errstr.
if LIBGO_IS_RTEMS
syscall_errstr_file = syscalls/errstr_rtems.go
else
syscall_errstr_file = syscalls/errstr.go syscall_errstr_file = syscalls/errstr.go
endif
# Declare libc_strerror_r which is the Go name for strerror_r.
if LIBGO_IS_RTEMS
# RTEMS uses newlib in which strerror_r returns char *.
syscall_errstr_decl_file = syscalls/errstr_decl_rtems.go
else
if LIBGO_IS_LINUX if LIBGO_IS_LINUX
# In Linux the POSIX strerror_r is called __xpg_strerror_r.
syscall_errstr_decl_file = syscalls/errstr_decl_linux.go syscall_errstr_decl_file = syscalls/errstr_decl_linux.go
else else
# On other systems we hope strerror_r is just strerror_r.
syscall_errstr_decl_file = syscalls/errstr_decl.go syscall_errstr_decl_file = syscalls/errstr_decl.go
endif endif
endif endif
# Define socket sizes and types.
if LIBGO_IS_LINUX
syscall_socket_os_file = syscalls/socket_linux.go
else
if LIBGO_IS_SOLARIS
syscall_socket_os_file = syscalls/socket_solaris.go
else
syscall_socket_os_file = syscalls_socket_bsd.go
endif
endif
# Support for epoll.
if LIBGO_IS_LINUX
syscall_socket_epoll_file = syscalls/socket_epoll.go
else
syscall_socket_epoll_file =
endif
syscall_arch.go: s-syscall_arch; @true syscall_arch.go: s-syscall_arch; @true
s-syscall_arch: Makefile s-syscall_arch: Makefile
rm -f syscall_arch.go.tmp rm -f syscall_arch.go.tmp
echo "package syscall" > syscall_arch.go.tmp echo "package syscall" > syscall_arch.go.tmp
echo 'const ARCH = "'$(GOARCH)'"' >> syscall_arch.go.tmp echo 'const ARCH = "'$(GOARCH)'"' >> syscall_arch.go.tmp
echo 'const OS = "'$(GOOS)'"' >> syscall_arch.go.tmp
$(SHELL) $(srcdir)/../move-if-change syscall_arch.go.tmp syscall_arch.go $(SHELL) $(srcdir)/../move-if-change syscall_arch.go.tmp syscall_arch.go
$(STAMP) $@ $(STAMP) $@
...@@ -1054,6 +1120,8 @@ go_syscall_files = \ ...@@ -1054,6 +1120,8 @@ go_syscall_files = \
$(syscall_errstr_decl_file) \ $(syscall_errstr_decl_file) \
syscalls/exec_helpers.go \ syscalls/exec_helpers.go \
$(syscall_exec_os_file) \ $(syscall_exec_os_file) \
$(syscall_filesize_file) \
$(syscall_sleep_file) \
syscalls/socket.go \ syscalls/socket.go \
$(syscall_socket_os_file) \ $(syscall_socket_os_file) \
$(syscall_socket_epoll_file) \ $(syscall_socket_epoll_file) \
...@@ -1063,7 +1131,6 @@ go_syscall_files = \ ...@@ -1063,7 +1131,6 @@ go_syscall_files = \
syscalls/syscall_$(GOOS).go \ syscalls/syscall_$(GOOS).go \
syscalls/syscall_$(GOOS)_$(GOARCH).go \ syscalls/syscall_$(GOOS)_$(GOARCH).go \
syscalls/sysfile_posix.go \ syscalls/sysfile_posix.go \
$(syscall_sysfile_os_file) \
sysinfo.go \ sysinfo.go \
syscall_arch.go syscall_arch.go
go_syscall_c_files = \ go_syscall_c_files = \
...@@ -2232,7 +2299,7 @@ testing/script/check: $(CHECK_DEPS) ...@@ -2232,7 +2299,7 @@ testing/script/check: $(CHECK_DEPS)
.PHONY: testing/script/check .PHONY: testing/script/check
sysinfo.go: $(srcdir)/mksysinfo.sh config.h sysinfo.go: $(srcdir)/mksysinfo.sh config.h
$(SHELL) $(srcdir)/mksysinfo.sh CC="$(CC)" $(SHELL) $(srcdir)/mksysinfo.sh
syscalls/libsyscall.a: $(go_syscall_files) $(go_syscall_c_files) sync.gox syscalls/libsyscall.a: $(go_syscall_files) $(go_syscall_c_files) sync.gox
rm -f syscall.gox syscalls/libsyscall.a rm -f syscall.gox syscalls/libsyscall.a
test -d syscalls || $(MKDIR_P) syscalls test -d syscalls || $(MKDIR_P) syscalls
......
...@@ -938,9 +938,13 @@ go_mime_files = \ ...@@ -938,9 +938,13 @@ go_mime_files = \
go/mime/mediatype.go \ go/mime/mediatype.go \
go/mime/type.go go/mime/type.go
@LIBGO_IS_RTEMS_FALSE@go_net_fd_os_file = go/net/fd_linux.go # By default use select with pipes. Most systems should have
# something better.
@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_RTEMS_FALSE@go_net_fd_os_file = go/net/fd_rtems.go
@LIBGO_IS_LINUX_TRUE@@LIBGO_IS_RTEMS_FALSE@go_net_fd_os_file = go/net/fd_linux.go
@LIBGO_IS_RTEMS_TRUE@go_net_fd_os_file = go/net/fd_rtems.go @LIBGO_IS_RTEMS_TRUE@go_net_fd_os_file = go/net/fd_rtems.go
@LIBGO_IS_RTEMS_FALSE@go_net_newpollserver_file = go/net/newpollserver.go @LIBGO_IS_LINUX_FALSE@@LIBGO_IS_RTEMS_FALSE@go_net_newpollserver_file = go/net/newpollserver.go
@LIBGO_IS_LINUX_TRUE@@LIBGO_IS_RTEMS_FALSE@go_net_newpollserver_file = go/net/newpollserver.go
@LIBGO_IS_RTEMS_TRUE@go_net_newpollserver_file = go/net/newpollserver_rtems.go @LIBGO_IS_RTEMS_TRUE@go_net_newpollserver_file = go/net/newpollserver_rtems.go
go_net_files = \ go_net_files = \
go/net/dial.go \ go/net/dial.go \
...@@ -1389,26 +1393,56 @@ go_testing_quick_files = \ ...@@ -1389,26 +1393,56 @@ go_testing_quick_files = \
go_testing_script_files = \ go_testing_script_files = \
go/testing/script/script.go go/testing/script/script.go
@LIBGO_IS_RTEMS_FALSE@syscall_exec_os_file = syscalls/exec.go
@LIBGO_IS_RTEMS_TRUE@syscall_exec_os_file = syscalls/exec_stubs.go
@LIBGO_IS_RTEMS_FALSE@syscall_socket_os_file = syscalls/socket_linux.go
@LIBGO_IS_RTEMS_TRUE@syscall_socket_os_file = syscalls/socket_bsd.go
@LIBGO_IS_RTEMS_FALSE@syscall_socket_epoll_file = syscalls/socket_epoll.go
@LIBGO_IS_RTEMS_TRUE@syscall_socket_epoll_file =
@LIBGO_IS_RTEMS_FALSE@syscall_sysfile_os_file = syscalls/sysfile_linux.go
@LIBGO_IS_RTEMS_TRUE@syscall_sysfile_os_file = syscalls/sysfile_rtems.go
@LIBGO_IS_RTEMS_FALSE@syscall_syscall_file = syscalls/syscall.go @LIBGO_IS_RTEMS_FALSE@syscall_syscall_file = syscalls/syscall.go
# Define Syscall and Syscall6.
@LIBGO_IS_RTEMS_TRUE@syscall_syscall_file = syscalls/syscall_stubs.go @LIBGO_IS_RTEMS_TRUE@syscall_syscall_file = syscalls/syscall_stubs.go
# Use lseek by default.
@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_FALSE@syscall_filesize_file = syscalls/sysfile_regfile.go
# Declare libc functions that vary for largefile systems.
# Always use lseek64 on GNU/Linux.
@LIBGO_IS_LINUX_TRUE@syscall_filesize_file = syscalls/sysfile_largefile.go
# Use lseek on amd64 Solaris.
@LIBGO_IS_386_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_TRUE@syscall_filesize_flie = syscalls/sysfile_regfile.go
# Use lseek64 on 386 Solaris.
@LIBGO_IS_386_TRUE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_TRUE@syscall_filesize_flie = syscalls/sysfile_largefile.go
@LIBGO_IS_RTEMS_FALSE@syscall_exec_os_file = syscalls/exec.go
# Define ForkExec, PtraceForkExec, Exec, and Wait4.
@LIBGO_IS_RTEMS_TRUE@syscall_exec_os_file = syscalls/exec_stubs.go
@LIBGO_IS_RTEMS_FALSE@syscall_sleep_file = syscalls/sleep_select.go
# Define Sleep.
@LIBGO_IS_RTEMS_TRUE@syscall_sleep_file = syscalls/sleep_rtems.go
@LIBGO_IS_RTEMS_FALSE@syscall_errstr_file = syscalls/errstr.go @LIBGO_IS_RTEMS_FALSE@syscall_errstr_file = syscalls/errstr.go
# Define Errstr.
@LIBGO_IS_RTEMS_TRUE@syscall_errstr_file = syscalls/errstr_rtems.go @LIBGO_IS_RTEMS_TRUE@syscall_errstr_file = syscalls/errstr_rtems.go
# On other systems we hope strerror_r is just strerror_r.
@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_RTEMS_FALSE@syscall_errstr_decl_file = syscalls/errstr_decl.go @LIBGO_IS_LINUX_FALSE@@LIBGO_IS_RTEMS_FALSE@syscall_errstr_decl_file = syscalls/errstr_decl.go
# In Linux the POSIX strerror_r is called __xpg_strerror_r.
@LIBGO_IS_LINUX_TRUE@@LIBGO_IS_RTEMS_FALSE@syscall_errstr_decl_file = syscalls/errstr_decl_linux.go @LIBGO_IS_LINUX_TRUE@@LIBGO_IS_RTEMS_FALSE@syscall_errstr_decl_file = syscalls/errstr_decl_linux.go
# Declare libc_strerror_r which is the Go name for strerror_r.
# RTEMS uses newlib in which strerror_r returns char *.
@LIBGO_IS_RTEMS_TRUE@syscall_errstr_decl_file = syscalls/errstr_decl_rtems.go @LIBGO_IS_RTEMS_TRUE@syscall_errstr_decl_file = syscalls/errstr_decl_rtems.go
@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_FALSE@syscall_socket_os_file = syscalls_socket_bsd.go
@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_TRUE@syscall_socket_os_file = syscalls/socket_solaris.go
# Define socket sizes and types.
@LIBGO_IS_LINUX_TRUE@syscall_socket_os_file = syscalls/socket_linux.go
@LIBGO_IS_LINUX_FALSE@syscall_socket_epoll_file =
# Support for epoll.
@LIBGO_IS_LINUX_TRUE@syscall_socket_epoll_file = syscalls/socket_epoll.go
go_syscall_files = \ go_syscall_files = \
$(syscall_errstr_file) \ $(syscall_errstr_file) \
$(syscall_errstr_decl_file) \ $(syscall_errstr_decl_file) \
syscalls/exec_helpers.go \ syscalls/exec_helpers.go \
$(syscall_exec_os_file) \ $(syscall_exec_os_file) \
$(syscall_filesize_file) \
$(syscall_sleep_file) \
syscalls/socket.go \ syscalls/socket.go \
$(syscall_socket_os_file) \ $(syscall_socket_os_file) \
$(syscall_socket_epoll_file) \ $(syscall_socket_epoll_file) \
...@@ -1418,7 +1452,6 @@ go_syscall_files = \ ...@@ -1418,7 +1452,6 @@ go_syscall_files = \
syscalls/syscall_$(GOOS).go \ syscalls/syscall_$(GOOS).go \
syscalls/syscall_$(GOOS)_$(GOARCH).go \ syscalls/syscall_$(GOOS)_$(GOARCH).go \
syscalls/sysfile_posix.go \ syscalls/sysfile_posix.go \
$(syscall_sysfile_os_file) \
sysinfo.go \ sysinfo.go \
syscall_arch.go syscall_arch.go
...@@ -3608,6 +3641,7 @@ s-syscall_arch: Makefile ...@@ -3608,6 +3641,7 @@ s-syscall_arch: Makefile
rm -f syscall_arch.go.tmp rm -f syscall_arch.go.tmp
echo "package syscall" > syscall_arch.go.tmp echo "package syscall" > syscall_arch.go.tmp
echo 'const ARCH = "'$(GOARCH)'"' >> syscall_arch.go.tmp echo 'const ARCH = "'$(GOARCH)'"' >> syscall_arch.go.tmp
echo 'const OS = "'$(GOOS)'"' >> syscall_arch.go.tmp
$(SHELL) $(srcdir)/../move-if-change syscall_arch.go.tmp syscall_arch.go $(SHELL) $(srcdir)/../move-if-change syscall_arch.go.tmp syscall_arch.go
$(STAMP) $@ $(STAMP) $@
...@@ -4578,7 +4612,7 @@ testing/script/check: $(CHECK_DEPS) ...@@ -4578,7 +4612,7 @@ testing/script/check: $(CHECK_DEPS)
.PHONY: testing/script/check .PHONY: testing/script/check
sysinfo.go: $(srcdir)/mksysinfo.sh config.h sysinfo.go: $(srcdir)/mksysinfo.sh config.h
$(SHELL) $(srcdir)/mksysinfo.sh CC="$(CC)" $(SHELL) $(srcdir)/mksysinfo.sh
syscalls/libsyscall.a: $(go_syscall_files) $(go_syscall_c_files) sync.gox syscalls/libsyscall.a: $(go_syscall_files) $(go_syscall_c_files) sync.gox
rm -f syscall.gox syscalls/libsyscall.a rm -f syscall.gox syscalls/libsyscall.a
test -d syscalls || $(MKDIR_P) syscalls test -d syscalls || $(MKDIR_P) syscalls
......
...@@ -6,11 +6,6 @@ ...@@ -6,11 +6,6 @@
package syscall package syscall
const ENONE = 0
func GetErrno() int
func SetErrno(int)
func Errstr(errno int) string { func Errstr(errno int) string {
for len := Size_t(128); ; len *= 2 { for len := Size_t(128); ; len *= 2 {
b := make([]byte, len) b := make([]byte, len)
......
...@@ -6,11 +6,6 @@ ...@@ -6,11 +6,6 @@
package syscall package syscall
const ENONE = 0
func GetErrno() int
func SetErrno(int)
func Errstr(errno int) string { func Errstr(errno int) string {
for len := Size_t(128); ; len *= 2 { for len := Size_t(128); ; len *= 2 {
b := make([]byte, len+1) b := make([]byte, len+1)
......
// sysfile_rtems.go -- RTEMS specific file handling. // sleep_rtems.go -- Sleep on RTEMS.
// Copyright 2010 The Go Authors. All rights reserved. // Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// Support for basic Unix file operations. This file simply
// translates from Go data types to Unix data types, and handles
// errno. FIXME: This could probably be done mechanically.
package syscall
const (
OS = "rtems"
// No support for async I/O in RTEMS.
O_ASYNC = 0
)
func libc_pread(fd int, buf *byte, count Size_t, offset Offset_t) Ssize_t __asm__ ("pread")
func libc_pwrite(fd int, buf *byte, count Size_t, offset Offset_t) Ssize_t __asm__ ("pwrite")
func libc_lseek64(int, Offset_t, int) Offset_t __asm__ ("lseek")
func libc_truncate64(path *byte, length Offset_t) int __asm__ ("truncate")
func libc_ftruncate64(fd int, length Offset_t) int __asm__ ("ftruncate")
func libc_nanosleep(req *Timespec, rem *Timespec) int __asm__ ("nanosleep") func libc_nanosleep(req *Timespec, rem *Timespec) int __asm__ ("nanosleep")
func Sleep(nsec int64) (errno int) { func Sleep(nsec int64) (errno int) {
......
// sleep_select.go -- Sleep using select.
// Copyright 2011 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.
package syscall
func Sleep(nsec int64) (errno int) {
tv := NsecToTimeval(nsec);
n, err := Select(0, nil, nil, nil, &tv);
return err;
}
...@@ -12,10 +12,6 @@ package syscall ...@@ -12,10 +12,6 @@ package syscall
import "unsafe" import "unsafe"
const SizeofSockaddrInet4 = 16
const SizeofSockaddrInet6 = 28
const SizeofSockaddrUnix = 110
type RawSockaddrAny struct { type RawSockaddrAny struct {
Addr RawSockaddr; Addr RawSockaddr;
Pad [12]int8; Pad [12]int8;
...@@ -53,6 +49,91 @@ type Linger struct { ...@@ -53,6 +49,91 @@ type Linger struct {
Linger int32; Linger int32;
} }
func (sa *SockaddrInet4) sockaddr() (*RawSockaddrAny, Socklen_t, int) {
if sa.Port < 0 || sa.Port > 0xFFFF {
return nil, 0, EINVAL;
}
sa.raw.Family = AF_INET;
n := sa.raw.setLen()
p := (*[2]byte)(unsafe.Pointer(&sa.raw.Port));
p[0] = byte(sa.Port>>8);
p[1] = byte(sa.Port);
for i := 0; i < len(sa.Addr); i++ {
sa.raw.Addr[i] = sa.Addr[i];
}
return (*RawSockaddrAny)(unsafe.Pointer(&sa.raw)), n, 0;
}
func (sa *SockaddrInet6) sockaddr() (*RawSockaddrAny, Socklen_t, int) {
if sa.Port < 0 || sa.Port > 0xFFFF {
return nil, 0, EINVAL;
}
sa.raw.Family = AF_INET6;
n := sa.raw.setLen()
p := (*[2]byte)(unsafe.Pointer(&sa.raw.Port));
p[0] = byte(sa.Port>>8);
p[1] = byte(sa.Port);
for i := 0; i < len(sa.Addr); i++ {
sa.raw.Addr[i] = sa.Addr[i];
}
return (*RawSockaddrAny)(unsafe.Pointer(&sa.raw)), n, 0;
}
func (sa *SockaddrUnix) sockaddr() (*RawSockaddrAny, Socklen_t, int) {
name := sa.Name;
n := len(name);
if n >= len(sa.raw.Path) || n == 0 {
return nil, 0, EINVAL;
}
sa.raw.Family = AF_UNIX;
sa.raw.setLen(n)
for i := 0; i < n; i++ {
sa.raw.Path[i] = int8(name[i]);
}
if sa.raw.Path[0] == '@' {
sa.raw.Path[0] = 0;
}
// length is family (uint16), name, NUL.
return (*RawSockaddrAny)(unsafe.Pointer(&sa.raw)), 2 + Socklen_t(n) + 1, 0;
}
func anyToSockaddr(rsa *RawSockaddrAny) (Sockaddr, int) {
switch rsa.Addr.Family {
case AF_UNIX:
pp := (*RawSockaddrUnix)(unsafe.Pointer(rsa))
sa := new(SockaddrUnix)
n, err := pp.getLen()
if err != 0 {
return nil, err
}
bytes := (*[len(pp.Path)]byte)(unsafe.Pointer(&pp.Path[0]));
sa.Name = string(bytes[0:n]);
return sa, 0;
case AF_INET:
pp := (*RawSockaddrInet4)(unsafe.Pointer(rsa));
sa := new(SockaddrInet4);
p := (*[2]byte)(unsafe.Pointer(&pp.Port));
sa.Port = int(p[0])<<8 + int(p[1]);
for i := 0; i < len(sa.Addr); i++ {
sa.Addr[i] = pp.Addr[i];
}
return sa, 0;
case AF_INET6:
pp := (*RawSockaddrInet6)(unsafe.Pointer(rsa));
sa := new(SockaddrInet6);
p := (*[2]byte)(unsafe.Pointer(&pp.Port));
sa.Port = int(p[0])<<8 + int(p[1]);
for i := 0; i < len(sa.Addr); i++ {
sa.Addr[i] = pp.Addr[i];
}
return sa, 0;
}
return nil, EAFNOSUPPORT;
}
func libc_accept(fd int, sa *RawSockaddrAny, len *Socklen_t) int __asm__ ("accept"); func libc_accept(fd int, sa *RawSockaddrAny, len *Socklen_t) int __asm__ ("accept");
func libc_bind(fd int, sa *RawSockaddrAny, len Socklen_t) int __asm__ ("bind"); func libc_bind(fd int, sa *RawSockaddrAny, len Socklen_t) int __asm__ ("bind");
func libc_connect(fd int, sa *RawSockaddrAny, len Socklen_t) int __asm__ ("connect"); func libc_connect(fd int, sa *RawSockaddrAny, len Socklen_t) int __asm__ ("connect");
......
...@@ -4,13 +4,11 @@ ...@@ -4,13 +4,11 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// Low-level socket interface.
// Only for implementing net package.
// DO NOT USE DIRECTLY.
package syscall package syscall
import "unsafe" const SizeofSockaddrInet4 = 16
const SizeofSockaddrInet6 = 28
const SizeofSockaddrUnix = 110
type RawSockaddrInet4 struct { type RawSockaddrInet4 struct {
Len uint8; Len uint8;
...@@ -20,6 +18,11 @@ type RawSockaddrInet4 struct { ...@@ -20,6 +18,11 @@ type RawSockaddrInet4 struct {
Zero [8]uint8; Zero [8]uint8;
} }
func (sa *RawSockaddrInet4) setLen() Socklen_t {
sa.Len = SizeofSockaddrInet4
return SizeofSockaddrInet4
}
type RawSockaddrInet6 struct { type RawSockaddrInet6 struct {
Len uint8; Len uint8;
Family uint8; Family uint8;
...@@ -29,108 +32,40 @@ type RawSockaddrInet6 struct { ...@@ -29,108 +32,40 @@ type RawSockaddrInet6 struct {
Scope_id uint32; Scope_id uint32;
} }
type RawSockaddrUnix struct { func (sa *RawSockaddrInet6) setLen() Socklen_t {
Len uint8; sa.raw.Len = SizeofSockaddrInet6
Family uint8; return SizeofSockaddrInet6
Path [108]int8;
} }
type RawSockaddr struct { type RawSockaddrUnix struct {
Len uint8; Len uint8;
Family uint8; Family uint8;
Data [14]int8; Path [108]int8;
} }
func (sa *SockaddrInet4) sockaddr() (*RawSockaddrAny, Socklen_t, int) { func (sa *RawsockaddrUnix) setLen(n int) {
if sa.Port < 0 || sa.Port > 0xFFFF { sa.Len = uint8(3 + n) // 2 for Family, Len; 1 for NUL.
return nil, 0, EINVAL;
}
sa.raw.Len = SizeofSockaddrInet4;
sa.raw.Family = AF_INET;
p := (*[2]byte)(unsafe.Pointer(&sa.raw.Port));
p[0] = byte(sa.Port>>8);
p[1] = byte(sa.Port);
for i := 0; i < len(sa.Addr); i++ {
sa.raw.Addr[i] = sa.Addr[i];
}
return (*RawSockaddrAny)(unsafe.Pointer(&sa.raw)), Socklen_t(sa.raw.Len), 0;
} }
func (sa *SockaddrInet6) sockaddr() (*RawSockaddrAny, Socklen_t, int) { func (sa *RawsockaddrUnix) getLen() (int, int) {
if sa.Port < 0 || sa.Port > 0xFFFF { if sa.Len < 3 || sa.Len > SizeofSockaddrUnix {
return nil, 0, EINVAL; return 0, EINVAL
}
sa.raw.Len = SizeofSockaddrInet6;
sa.raw.Family = AF_INET6;
p := (*[2]byte)(unsafe.Pointer(&sa.raw.Port));
p[0] = byte(sa.Port>>8);
p[1] = byte(sa.Port);
for i := 0; i < len(sa.Addr); i++ {
sa.raw.Addr[i] = sa.Addr[i];
} }
return (*RawSockaddrAny)(unsafe.Pointer(&sa.raw)), Socklen_t(sa.raw.Len), 0; n := int(sa.Len) - 3 // subtract leading Family, Len, terminating NUL.
}
func (sa *SockaddrUnix) sockaddr() (*RawSockaddrAny, Socklen_t, int) {
name := sa.Name;
n := len(name);
if n >= len(sa.raw.Path) || n == 0 {
return nil, 0, EINVAL;
}
sa.raw.Len = byte(3 + n); // 2 for Family, Len; 1 for NUL.
sa.raw.Family = AF_UNIX;
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
sa.raw.Path[i] = int8(name[i]); if sa.Path[i] == 0 {
} // found early NUL; assume Len is overestimating.
if sa.raw.Path[0] == '@' { n = i
sa.raw.Path[0] = 0; break
}
} }
return n, 0
// length is family, name, NUL.
return (*RawSockaddrAny)(unsafe.Pointer(&sa.raw)), Socklen_t(sa.raw.Len), 0;
} }
func anyToSockaddr(rsa *RawSockaddrAny) (Sockaddr, int) { type RawSockaddr struct {
switch rsa.Addr.Family { Len uint8;
case AF_UNIX: Family uint8;
pp := (*RawSockaddrUnix)(unsafe.Pointer(rsa)) Data [14]int8;
if pp.Len < 3 || pp.Len > SizeofSockaddrUnix {
return nil, EINVAL
}
sa := new(SockaddrUnix)
n := int(pp.Len) - 3 // subtract leading Family, Len, terminating NUL.
for i := 0; i < n; i++ {
if pp.Path[i] == 0 {
// found early NUL; assume Len is overestimating.
n = i
break
}
}
bytes := (*[len(pp.Path)]byte)(unsafe.Pointer(&pp.Path[0]))
sa.Name = string(bytes[0:n])
return sa, 0
case AF_INET:
pp := (*RawSockaddrInet4)(unsafe.Pointer(rsa));
sa := new(SockaddrInet4);
p := (*[2]byte)(unsafe.Pointer(&pp.Port));
sa.Port = int(p[0])<<8 + int(p[1]);
for i := 0; i < len(sa.Addr); i++ {
sa.Addr[i] = pp.Addr[i];
}
return sa, 0;
case AF_INET6:
pp := (*RawSockaddrInet6)(unsafe.Pointer(rsa));
sa := new(SockaddrInet6);
p := (*[2]byte)(unsafe.Pointer(&pp.Port));
sa.Port = int(p[0])<<8 + int(p[1]);
for i := 0; i < len(sa.Addr); i++ {
sa.Addr[i] = pp.Addr[i];
}
return sa, 0;
}
return nil, EAFNOSUPPORT;
} }
// BindToDevice binds the socket associated with fd to device. // BindToDevice binds the socket associated with fd to device.
......
...@@ -4,14 +4,11 @@ ...@@ -4,14 +4,11 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// Low-level socket interface.
// Only for implementing net package.
// DO NOT USE DIRECTLY.
package syscall package syscall
import "unsafe" const SizeofSockaddrInet4 = 16
const SizeofSockaddrInet6 = 28
const SizeofSockaddrUnix = 110
type RawSockaddrInet4 struct { type RawSockaddrInet4 struct {
Family uint16; Family uint16;
...@@ -20,6 +17,10 @@ type RawSockaddrInet4 struct { ...@@ -20,6 +17,10 @@ type RawSockaddrInet4 struct {
Zero [8]uint8; Zero [8]uint8;
} }
func (sa *RawSockaddrInet4) setLen() Socklen_t {
return SizeofSockaddrInet4
}
type RawSockaddrInet6 struct { type RawSockaddrInet6 struct {
Family uint16; Family uint16;
Port uint16; Port uint16;
...@@ -28,110 +29,44 @@ type RawSockaddrInet6 struct { ...@@ -28,110 +29,44 @@ type RawSockaddrInet6 struct {
Scope_id uint32; Scope_id uint32;
} }
type RawSockaddrUnix struct { func (sa *RawSockaddrInet6) setLen() Socklen_t {
Family uint16; return SizeofSockaddrInet6
Path [108]int8;
} }
type RawSockaddr struct { type RawSockaddrUnix struct {
Family uint16; Family uint16;
Data [14]int8; Path [108]int8;
} }
func (sa *SockaddrInet4) sockaddr() (*RawSockaddrAny, Socklen_t, int) { func (sa *RawSockaddrUnix) setLen(int) {
if sa.Port < 0 || sa.Port > 0xFFFF {
return nil, 0, EINVAL;
}
sa.raw.Family = AF_INET;
p := (*[2]byte)(unsafe.Pointer(&sa.raw.Port));
p[0] = byte(sa.Port>>8);
p[1] = byte(sa.Port);
for i := 0; i < len(sa.Addr); i++ {
sa.raw.Addr[i] = sa.Addr[i];
}
return (*RawSockaddrAny)(unsafe.Pointer(&sa.raw)), SizeofSockaddrInet4, 0;
} }
func (sa *SockaddrInet6) sockaddr() (*RawSockaddrAny, Socklen_t, int) { func (sa *RawSockaddrUnix) getLen() (int, int) {
if sa.Port < 0 || sa.Port > 0xFFFF { if sa.Path[0] == 0 {
return nil, 0, EINVAL; // "Abstract" Unix domain socket.
} // Rewrite leading NUL as @ for textual display.
sa.raw.Family = AF_INET6; // (This is the standard convention.)
p := (*[2]byte)(unsafe.Pointer(&sa.raw.Port)); // Not friendly to overwrite in place,
p[0] = byte(sa.Port>>8); // but the callers below don't care.
p[1] = byte(sa.Port); sa.Path[0] = '@';
for i := 0; i < len(sa.Addr); i++ {
sa.raw.Addr[i] = sa.Addr[i];
} }
return (*RawSockaddrAny)(unsafe.Pointer(&sa.raw)), SizeofSockaddrInet6, 0;
}
func (sa *SockaddrUnix) sockaddr() (*RawSockaddrAny, Socklen_t, int) { // Assume path ends at NUL.
name := sa.Name; // This is not technically the Linux semantics for
n := len(name); // abstract Unix domain sockets--they are supposed
if n >= len(sa.raw.Path) || n == 0 { // to be uninterpreted fixed-size binary blobs--but
return nil, 0, EINVAL; // everyone uses this convention.
} n := 0;
sa.raw.Family = AF_UNIX; for n < len(sa.Path) - 3 && sa.Path[n] != 0 {
for i := 0; i < n; i++ { n++;
sa.raw.Path[i] = int8(name[i]);
}
if sa.raw.Path[0] == '@' {
sa.raw.Path[0] = 0;
} }
// length is family, name, NUL. return n, 0
return (*RawSockaddrAny)(unsafe.Pointer(&sa.raw)), 1 + Socklen_t(n) + 1, 0;
} }
func anyToSockaddr(rsa *RawSockaddrAny) (Sockaddr, int) { type RawSockaddr struct {
switch rsa.Addr.Family { Family uint16;
case AF_UNIX: Data [14]int8;
pp := (*RawSockaddrUnix)(unsafe.Pointer(rsa));
sa := new(SockaddrUnix);
if pp.Path[0] == 0 {
// "Abstract" Unix domain socket.
// Rewrite leading NUL as @ for textual display.
// (This is the standard convention.)
// Not friendly to overwrite in place,
// but the callers below don't care.
pp.Path[0] = '@';
}
// Assume path ends at NUL.
// This is not technically the Linux semantics for
// abstract Unix domain sockets--they are supposed
// to be uninterpreted fixed-size binary blobs--but
// everyone uses this convention.
n := 0;
for n < len(pp.Path) - 3 && pp.Path[n] != 0 {
n++;
}
bytes := (*[len(pp.Path)]byte)(unsafe.Pointer(&pp.Path[0]));
sa.Name = string(bytes[0:n]);
return sa, 0;
case AF_INET:
pp := (*RawSockaddrInet4)(unsafe.Pointer(rsa));
sa := new(SockaddrInet4);
p := (*[2]byte)(unsafe.Pointer(&pp.Port));
sa.Port = int(p[0])<<8 + int(p[1]);
for i := 0; i < len(sa.Addr); i++ {
sa.Addr[i] = pp.Addr[i];
}
return sa, 0;
case AF_INET6:
pp := (*RawSockaddrInet6)(unsafe.Pointer(rsa));
sa := new(SockaddrInet6);
p := (*[2]byte)(unsafe.Pointer(&pp.Port));
sa.Port = int(p[0])<<8 + int(p[1]);
for i := 0; i < len(sa.Addr); i++ {
sa.Addr[i] = pp.Addr[i];
}
return sa, 0;
}
return nil, EAFNOSUPPORT;
} }
// BindToDevice binds the socket associated with fd to device. // BindToDevice binds the socket associated with fd to device.
......
// socket_solaris.go -- Socket handling specific to Solaris.
// Copyright 2010 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.
package syscall
const SizeofSockaddrInet4 = 16
const SizeofSockaddrInet6 = 32
const SizeofSockaddrUnix = 110
type RawSockaddrInet4 struct {
Family uint16
Port uint16
Addr [4]byte /* in_addr */
Zero [8]uint8
}
func (sa *RawSockaddrInet4) setLen() Socklen_t {
return SizeofSockaddrInet4
}
type RawSockaddrInet6 struct {
Family uint16
Port uint16
Flowinfo uint32
Addr [16]byte /* in6_addr */
Scope_id uint32
Src_id uint32
}
func (sa *RawSockaddrInet6) setLen() Socklen_t {
return SizeofSockaddrInet6
}
type RawSockaddrUnix struct {
Family uint16
Path [108]int8
}
func (sa *RawSockaddrUnix) setLen(int) {
}
func (sa *RawSockaddrUnix) getLen() (int, int) {
if sa.Path[0] == 0 {
// "Abstract" Unix domain socket.
// Rewrite leading NUL as @ for textual display.
// (This is the standard convention.)
// Not friendly to overwrite in place,
// but the callers below don't care.
sa.Path[0] = '@'
}
// Assume path ends at NUL.
// This is not technically the Linux semantics for
// abstract Unix domain sockets--they are supposed
// to be uninterpreted fixed-size binary blobs--but
// everyone uses this convention.
n := 0
for n < len(sa.Path) - 3 && sa.Path[n] != 0 {
n++
}
return n, 0
}
type RawSockaddr struct {
Family uint16
Data [14]int8
}
// BindToDevice binds the socket associated with fd to device.
func BindToDevice(fd int, device string) (errno int) {
return ENOSYS
}
...@@ -8,8 +8,6 @@ package syscall ...@@ -8,8 +8,6 @@ package syscall
import "unsafe" import "unsafe"
const ARCH = "386"
// FIXME: ptrace(3C) has this, but exec.go expects the next. // FIXME: ptrace(3C) has this, but exec.go expects the next.
//func libc_ptrace(request int, pid Pid_t, addr int, data int) int __asm__ ("ptrace") //func libc_ptrace(request int, pid Pid_t, addr int, data int) int __asm__ ("ptrace")
......
...@@ -8,8 +8,6 @@ package syscall ...@@ -8,8 +8,6 @@ package syscall
import "unsafe" import "unsafe"
const ARCH = "amd64"
// FIXME: ptrace(3C) has this, but exec.go expects the next. // FIXME: ptrace(3C) has this, but exec.go expects the next.
//func libc_ptrace(request int, pid Pid_t, addr int, data int) int __asm__ ("ptrace") //func libc_ptrace(request int, pid Pid_t, addr int, data int) int __asm__ ("ptrace")
......
...@@ -10,6 +10,11 @@ var ( ...@@ -10,6 +10,11 @@ var (
Stderr = 2 Stderr = 2
) )
const ENONE = 0
func GetErrno() int
func SetErrno(int)
func libc_uname(buf *Utsname) (errno int) __asm__("uname") func libc_uname(buf *Utsname) (errno int) __asm__("uname")
func Uname(buf *Utsname) (errno int) { func Uname(buf *Utsname) (errno int) {
......
// sysfile_largefile.go -- For systems which use the large file interface.
// Copyright 2011 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.
package syscall
func libc_pread(fd int, buf *byte, count Size_t, offset Offset_t) Ssize_t __asm__ ("pread64")
func libc_pwrite(fd int, buf *byte, count Size_t, offset Offset_t) Ssize_t __asm__ ("pwrite64")
func libc_lseek(int, Offset_t, int) Offset_t __asm__ ("lseek64")
func libc_truncate(path *byte, length Offset_t) int __asm__ ("truncate64")
func libc_ftruncate(fd int, length Offset_t) int __asm__ ("ftruncate64")
// sysfile_linux.go -- Linux specific file handling.
// Copyright 2010 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.
// Support for basic Unix file operations. This file simply
// translates from Go data types to Unix data types, and handles
// errno. FIXME: This could probably be done mechanically.
package syscall
const OS = "linux"
func libc_pread(fd int, buf *byte, count Size_t, offset Offset_t) Ssize_t __asm__ ("pread64")
func libc_pwrite(fd int, buf *byte, count Size_t, offset Offset_t) Ssize_t __asm__ ("pwrite64")
func libc_lseek64(int, Offset_t, int) Offset_t __asm__ ("lseek64")
func libc_truncate64(path *byte, length Offset_t) int __asm__ ("truncate64")
func libc_ftruncate64(fd int, length Offset_t) int __asm__ ("ftruncate64")
func libc_setgroups(size Size_t, list *Gid_t) int __asm__ ("setgroups")
func Sleep(nsec int64) (errno int) {
tv := NsecToTimeval(nsec);
n, err := Select(0, nil, nil, nil, &tv);
return err;
}
func Setgroups(gids []int) (errno int) {
if len(gids) == 0 {
return libc_setgroups(0, nil);
}
a := make([]Gid_t, len(gids));
for i, v := range gids {
a[i] = Gid_t(v);
}
return libc_setgroups(Size_t(len(a)), &a[0]);
}
...@@ -106,7 +106,7 @@ func Pwrite(fd int, p []byte, offset int64) (n int, errno int) { ...@@ -106,7 +106,7 @@ func Pwrite(fd int, p []byte, offset int64) (n int, errno int) {
} }
func Seek(fd int, offset int64, whence int) (off int64, errno int) { func Seek(fd int, offset int64, whence int) (off int64, errno int) {
r := libc_lseek64(fd, Offset_t(offset), whence); r := libc_lseek(fd, Offset_t(offset), whence);
if r == -1 { errno = GetErrno() } if r == -1 { errno = GetErrno() }
off = int64(r); off = int64(r);
return; return;
...@@ -300,13 +300,13 @@ func Fchown(fd int, uid int, gid int) (errno int) { ...@@ -300,13 +300,13 @@ func Fchown(fd int, uid int, gid int) (errno int) {
} }
func Truncate(path string, length int64) (errno int) { func Truncate(path string, length int64) (errno int) {
r := libc_truncate64(StringBytePtr(path), Offset_t(length)); r := libc_truncate(StringBytePtr(path), Offset_t(length));
if r < 0 { errno = GetErrno() } if r < 0 { errno = GetErrno() }
return; return;
} }
func Ftruncate(fd int, length int64) (errno int) { func Ftruncate(fd int, length int64) (errno int) {
r := libc_ftruncate64(fd, Offset_t(length)); r := libc_ftruncate(fd, Offset_t(length));
if r < 0 { errno = GetErrno() } if r < 0 { errno = GetErrno() }
return; return;
} }
......
// sysfile_regfile.go -- For systems which do not use the large file interface.
// Copyright 2011 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.
package syscall
func libc_pread(fd int, buf *byte, count Size_t, offset Offset_t) Ssize_t __asm__ ("pread")
func libc_pwrite(fd int, buf *byte, count Size_t, offset Offset_t) Ssize_t __asm__ ("pwrite")
func libc_lseek(int, Offset_t, int) Offset_t __asm__ ("lseek")
func libc_truncate(path *byte, length Offset_t) int __asm__ ("truncate")
func libc_ftruncate(fd int, length Offset_t) int __asm__ ("ftruncate")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment