Commit 30ee5919 authored by Hyang-Ah Hana Kim's avatar Hyang-Ah Hana Kim

runtime: add syscalls needed for android/amd64 logging.

access, connect, socket.

In Android-L, logging is done by writing the log messages to the logd
process through a unix domain socket.

Also, changed the arg types of those syscall stubs to match linux
programming APIs.

For golang/go#10743

Change-Id: I66368a03316e253561e9e76aadd180c2cd2e48f3
Reviewed-on: https://go-review.googlesource.com/15993Reviewed-by: 's avatarDavid Crawshaw <crawshaw@golang.org>
parent 7d2c6eb3
...@@ -87,6 +87,10 @@ const ( ...@@ -87,6 +87,10 @@ const (
_EPOLL_CTL_ADD = 0x1 _EPOLL_CTL_ADD = 0x1
_EPOLL_CTL_DEL = 0x2 _EPOLL_CTL_DEL = 0x2
_EPOLL_CTL_MOD = 0x3 _EPOLL_CTL_MOD = 0x3
_AF_UNIX = 0x1
_F_SETFL = 0x4
_SOCK_DGRAM = 0x2
) )
type timespec struct { type timespec struct {
...@@ -253,3 +257,8 @@ type sigcontext struct { ...@@ -253,3 +257,8 @@ type sigcontext struct {
fpstate *fpstate1 fpstate *fpstate1
__reserved1 [8]uint64 __reserved1 [8]uint64
} }
type sockaddr_un struct {
family uint16
path [108]byte
}
...@@ -116,7 +116,7 @@ func initLogd() { ...@@ -116,7 +116,7 @@ func initLogd() {
exit(2) exit(2)
} }
errno := connect(uintptr(fd), unsafe.Pointer(&logdAddr), int32(unsafe.Sizeof(logdAddr))) errno := connect(fd, unsafe.Pointer(&logdAddr), int32(unsafe.Sizeof(logdAddr)))
if errno < 0 { if errno < 0 {
msg := []byte("runtime: cannot connect to /dev/socket/logdw\x00") msg := []byte("runtime: cannot connect to /dev/socket/logdw\x00")
write(2, unsafe.Pointer(&msg[0]), int32(len(msg))) write(2, unsafe.Pointer(&msg[0]), int32(len(msg)))
......
...@@ -2,9 +2,15 @@ package runtime ...@@ -2,9 +2,15 @@ package runtime
import "unsafe" import "unsafe"
// Return values of access/connect/socket are the return values of the syscall
// (may encode error numbers).
// int access(const char *, int)
//go:noescape //go:noescape
func access(name *byte, mode int32) int32 func access(name *byte, mode int32) int32
func connect(fd uintptr, addr unsafe.Pointer, len int32) int32 // int connect(int, const struct sockaddr*, socklen_t)
func connect(fd int32, addr unsafe.Pointer, len int32) int32
// int socket(int, int, int)
func socket(domain int32, typ int32, prot int32) int32 func socket(domain int32, typ int32, prot int32) int32
...@@ -442,3 +442,33 @@ TEXT runtime·closeonexec(SB),NOSPLIT,$0 ...@@ -442,3 +442,33 @@ TEXT runtime·closeonexec(SB),NOSPLIT,$0
MOVL $72, AX // fcntl MOVL $72, AX // fcntl
SYSCALL SYSCALL
RET RET
// int access(const char *name, int mode)
TEXT runtime·access(SB),NOSPLIT,$0
MOVQ name+0(FP), DI
MOVL mode+8(FP), SI
MOVL $21, AX // syscall entry
SYSCALL
MOVL AX, ret+16(FP)
RET
// int connect(int fd, const struct sockaddr *addr, socklen_t addrlen)
TEXT runtime·connect(SB),NOSPLIT,$0-28
MOVL fd+0(FP), DI
MOVQ addr+8(FP), SI
MOVL addrlen+16(FP), DX
MOVL $42, AX // syscall entry
SYSCALL
MOVL AX, ret+24(FP)
RET
// int socket(int domain, int type, int protocol)
TEXT runtime·socket(SB),NOSPLIT,$0-20
MOVL domain+0(FP), DI
MOVL type+4(FP), SI
MOVL protocol+8(FP), DX
MOVL $41, AX // syscall entry
SYSCALL
MOVL AX, ret+16(FP)
RET
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