During the research of my another question Go package syscall conn.Read() is non-blocking and cause high CPU usage, I read source code in syscall
package.
在研究我的另一个问题Go包syscall conn.Read()时,我阅读了syscall包中的源代码,它是非阻塞的,并导致高CPU使用率。
Since I found my last issue on OS X 10.8.3, here is the source code related:
由于我找到了上一期关于OS X 10.8.3的文章,下面是与之相关的源代码:
http://golang.org/src/pkg/syscall/zsyscall_darwin_amd64.go?h=Read#L898
http://golang.org/src/pkg/syscall/zsyscall_darwin_amd64.go?h=Read L898
I have no idea what Syscall(SYS_READ, uintptr(fd), uintptr(_p0), uintptr(len(p)))
means, actually I don't understand stuffs like unsafe.Pointer
& Syscall()
. How they works?
我不知道Syscall(SYS_READ, uintptr(fd), uintptr(_p0), uintptr(len(p)))是什么意思,实际上我不理解一些不安全的东西。指针和系统调用()。他们是如何运作的吗?
Besides, can anyone explain the comment // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
, how and why these things work with specific platform by different implementations? And how syscall
package generate these interfaces?
另外,谁能解释一下注释//这个文件是由顶部的命令生成的吗?不编辑,如何以及为什么这些东西与特定的平台有不同的实现?以及syscall包如何生成这些接口?
If someone can explain a specific function like Read()
related with syscall
could be help me understand it better, thanks.
如果有人能解释一个与syscall相关的特定函数Read(),可以帮助我更好地理解它,谢谢。
1 个解决方案
#1
3
The Go Darwin syscall
package func Read(fd int, p \[\]byte) (n int, err error)
function is making a read
(SYS_READ
) system call:
Go Darwin syscall package func Read(fd int, p \[\]byte) (n int, err error)函数正在创建一个Read(SYS_READ)系统调用:
read Mac OS X Developer Tools Manual Page
阅读Mac OS X开发者工具手册页
ssize_t read(int fildes, void *buf, size_t nbyte);
读取(int fildes, void *buf, size_t nbyte);
Read()
attempts to readnbyte
bytes of data from the object referenced by the descriptorfildes
into the buffer pointed to bybuf
.Read()尝试从描述符fildes引用的对象中读取nbyte字节的数据到由buf指向的缓冲区中。
The Go Darwin syscall
package Syscall
function is:
Go Darwin syscall包syscall函数是:
// func Syscall(trap int64, a1, a2, a3 int64) (r1, r2, err int64);
// Trap # in AX, args in DI SI DX, return in AX DX
TEXT ·Syscall(SB),7,$0
CALL runtime·entersyscall(SB)
MOVQ 16(SP), DI
MOVQ 24(SP), SI
MOVQ 32(SP), DX
MOVQ $0, R10
MOVQ $0, R8
MOVQ $0, R9
MOVQ 8(SP), AX // syscall entry
ADDQ $0x2000000, AX
SYSCALL
JCC ok
MOVQ $-1, 40(SP) // r1
MOVQ $0, 48(SP) // r2
MOVQ AX, 56(SP) // errno
CALL runtime·exitsyscall(SB)
RET
ok:
MOVQ AX, 40(SP) // r1
MOVQ DX, 48(SP) // r2
MOVQ $0, 56(SP) // errno
CALL runtime·exitsyscall(SB)
RET
#1
3
The Go Darwin syscall
package func Read(fd int, p \[\]byte) (n int, err error)
function is making a read
(SYS_READ
) system call:
Go Darwin syscall package func Read(fd int, p \[\]byte) (n int, err error)函数正在创建一个Read(SYS_READ)系统调用:
read Mac OS X Developer Tools Manual Page
阅读Mac OS X开发者工具手册页
ssize_t read(int fildes, void *buf, size_t nbyte);
读取(int fildes, void *buf, size_t nbyte);
Read()
attempts to readnbyte
bytes of data from the object referenced by the descriptorfildes
into the buffer pointed to bybuf
.Read()尝试从描述符fildes引用的对象中读取nbyte字节的数据到由buf指向的缓冲区中。
The Go Darwin syscall
package Syscall
function is:
Go Darwin syscall包syscall函数是:
// func Syscall(trap int64, a1, a2, a3 int64) (r1, r2, err int64);
// Trap # in AX, args in DI SI DX, return in AX DX
TEXT ·Syscall(SB),7,$0
CALL runtime·entersyscall(SB)
MOVQ 16(SP), DI
MOVQ 24(SP), SI
MOVQ 32(SP), DX
MOVQ $0, R10
MOVQ $0, R8
MOVQ $0, R9
MOVQ 8(SP), AX // syscall entry
ADDQ $0x2000000, AX
SYSCALL
JCC ok
MOVQ $-1, 40(SP) // r1
MOVQ $0, 48(SP) // r2
MOVQ AX, 56(SP) // errno
CALL runtime·exitsyscall(SB)
RET
ok:
MOVQ AX, 40(SP) // r1
MOVQ DX, 48(SP) // r2
MOVQ $0, 56(SP) // errno
CALL runtime·exitsyscall(SB)
RET