1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 //go:build 386 && linux
14 func setTimespec(sec
, nsec
int64) Timespec
{
15 return Timespec
{Sec
: int32(sec
), Nsec
: int32(nsec
)}
18 func setTimeval(sec
, usec
int64) Timeval
{
19 return Timeval
{Sec
: int32(sec
), Usec
: int32(usec
)}
22 // 64-bit file system and 32-bit uid calls
23 // (386 default is 32-bit file system and 16-bit uid).
24 //sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error)
25 //sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_FADVISE64_64
26 //sys Fchown(fd int, uid int, gid int) (err error) = SYS_FCHOWN32
27 //sys Fstat(fd int, stat *Stat_t) (err error) = SYS_FSTAT64
28 //sys Fstatat(dirfd int, path string, stat *Stat_t, flags int) (err error) = SYS_FSTATAT64
29 //sys Ftruncate(fd int, length int64) (err error) = SYS_FTRUNCATE64
30 //sysnb Getegid() (egid int) = SYS_GETEGID32
31 //sysnb Geteuid() (euid int) = SYS_GETEUID32
32 //sysnb Getgid() (gid int) = SYS_GETGID32
33 //sysnb Getuid() (uid int) = SYS_GETUID32
34 //sys Ioperm(from int, num int, on int) (err error)
35 //sys Iopl(level int) (err error)
36 //sys Lchown(path string, uid int, gid int) (err error) = SYS_LCHOWN32
37 //sys Lstat(path string, stat *Stat_t) (err error) = SYS_LSTAT64
38 //sys pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64
39 //sys pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64
40 //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error)
41 //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) = SYS_SENDFILE64
42 //sys setfsgid(gid int) (prev int, err error) = SYS_SETFSGID32
43 //sys setfsuid(uid int) (prev int, err error) = SYS_SETFSUID32
44 //sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int, err error)
45 //sys Stat(path string, stat *Stat_t) (err error) = SYS_STAT64
46 //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error)
47 //sys Truncate(path string, length int64) (err error) = SYS_TRUNCATE64
48 //sys Ustat(dev int, ubuf *Ustat_t) (err error)
49 //sysnb getgroups(n int, list *_Gid_t) (nn int, err error) = SYS_GETGROUPS32
50 //sysnb setgroups(n int, list *_Gid_t) (err error) = SYS_SETGROUPS32
51 //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) = SYS__NEWSELECT
53 //sys mmap2(addr uintptr, length uintptr, prot int, flags int, fd int, pageOffset uintptr) (xaddr uintptr, err error)
54 //sys Pause() (err error)
56 func mmap(addr
uintptr, length
uintptr, prot
int, flags
int, fd
int, offset
int64) (xaddr
uintptr, err error
) {
57 page
:= uintptr(offset
/ 4096)
58 if offset
!= int64(page
)*4096 {
61 return mmap2(addr
, length
, prot
, flags
, fd
, page
)
64 type rlimit32
struct {
69 //sysnb getrlimit(resource int, rlim *rlimit32) (err error) = SYS_GETRLIMIT
71 const rlimInf32
= ^uint32(0)
72 const rlimInf64
= ^uint64(0)
74 func Getrlimit(resource
int, rlim
*Rlimit
) (err error
) {
75 err
= Prlimit(0, resource
, nil, rlim
)
81 err
= getrlimit(resource
, &rl
)
86 if rl
.Cur
== rlimInf32
{
89 rlim
.Cur
= uint64(rl
.Cur
)
92 if rl
.Max
== rlimInf32
{
95 rlim
.Max
= uint64(rl
.Max
)
100 //sysnb setrlimit(resource int, rlim *rlimit32) (err error) = SYS_SETRLIMIT
102 func Setrlimit(resource
int, rlim
*Rlimit
) (err error
) {
103 err
= Prlimit(0, resource
, rlim
, nil)
109 if rlim
.Cur
== rlimInf64
{
111 } else if rlim
.Cur
< uint64(rlimInf32
) {
112 rl
.Cur
= uint32(rlim
.Cur
)
116 if rlim
.Max
== rlimInf64
{
118 } else if rlim
.Max
< uint64(rlimInf32
) {
119 rl
.Max
= uint32(rlim
.Max
)
124 return setrlimit(resource
, &rl
)
127 func Seek(fd
int, offset
int64, whence
int) (newoffset
int64, err error
) {
128 newoffset
, errno
:= seek(fd
, offset
, whence
)
132 return newoffset
, nil
135 //sys futimesat(dirfd int, path string, times *[2]Timeval) (err error)
136 //sysnb Gettimeofday(tv *Timeval) (err error)
137 //sysnb Time(t *Time_t) (tt Time_t, err error)
138 //sys Utime(path string, buf *Utimbuf) (err error)
139 //sys utimes(path string, times *[2]Timeval) (err error)
141 // On x86 Linux, all the socket calls go through an extra indirection,
142 // I think because the 5-register system call interface can't handle
143 // the 6-argument calls like sendto and recvfrom. Instead the
144 // arguments to the underlying system call are the number below
145 // and a pointer to an array of uintptr. We hide the pointer in the
146 // socketcall assembly to avoid allocation on every system call.
172 func accept4(s
int, rsa
*RawSockaddrAny
, addrlen
*_Socklen
, flags
int) (fd
int, err error
) {
173 fd
, e
:= socketcall(_ACCEPT4
, uintptr(s
), uintptr(unsafe
.Pointer(rsa
)), uintptr(unsafe
.Pointer(addrlen
)), uintptr(flags
), 0, 0)
180 func getsockname(s
int, rsa
*RawSockaddrAny
, addrlen
*_Socklen
) (err error
) {
181 _
, e
:= rawsocketcall(_GETSOCKNAME
, uintptr(s
), uintptr(unsafe
.Pointer(rsa
)), uintptr(unsafe
.Pointer(addrlen
)), 0, 0, 0)
188 func getpeername(s
int, rsa
*RawSockaddrAny
, addrlen
*_Socklen
) (err error
) {
189 _
, e
:= rawsocketcall(_GETPEERNAME
, uintptr(s
), uintptr(unsafe
.Pointer(rsa
)), uintptr(unsafe
.Pointer(addrlen
)), 0, 0, 0)
196 func socketpair(domain
int, typ
int, flags
int, fd
*[2]int32) (err error
) {
197 _
, e
:= rawsocketcall(_SOCKETPAIR
, uintptr(domain
), uintptr(typ
), uintptr(flags
), uintptr(unsafe
.Pointer(fd
)), 0, 0)
204 func bind(s
int, addr unsafe
.Pointer
, addrlen _Socklen
) (err error
) {
205 _
, e
:= socketcall(_BIND
, uintptr(s
), uintptr(addr
), uintptr(addrlen
), 0, 0, 0)
212 func connect(s
int, addr unsafe
.Pointer
, addrlen _Socklen
) (err error
) {
213 _
, e
:= socketcall(_CONNECT
, uintptr(s
), uintptr(addr
), uintptr(addrlen
), 0, 0, 0)
220 func socket(domain
int, typ
int, proto
int) (fd
int, err error
) {
221 fd
, e
:= rawsocketcall(_SOCKET
, uintptr(domain
), uintptr(typ
), uintptr(proto
), 0, 0, 0)
228 func getsockopt(s
int, level
int, name
int, val unsafe
.Pointer
, vallen
*_Socklen
) (err error
) {
229 _
, e
:= socketcall(_GETSOCKOPT
, uintptr(s
), uintptr(level
), uintptr(name
), uintptr(val
), uintptr(unsafe
.Pointer(vallen
)), 0)
236 func setsockopt(s
int, level
int, name
int, val unsafe
.Pointer
, vallen
uintptr) (err error
) {
237 _
, e
:= socketcall(_SETSOCKOPT
, uintptr(s
), uintptr(level
), uintptr(name
), uintptr(val
), vallen
, 0)
244 func recvfrom(s
int, p
[]byte, flags
int, from
*RawSockaddrAny
, fromlen
*_Socklen
) (n
int, err error
) {
247 base
= uintptr(unsafe
.Pointer(&p
[0]))
249 n
, e
:= socketcall(_RECVFROM
, uintptr(s
), base
, uintptr(len(p
)), uintptr(flags
), uintptr(unsafe
.Pointer(from
)), uintptr(unsafe
.Pointer(fromlen
)))
256 func sendto(s
int, p
[]byte, flags
int, to unsafe
.Pointer
, addrlen _Socklen
) (err error
) {
259 base
= uintptr(unsafe
.Pointer(&p
[0]))
261 _
, e
:= socketcall(_SENDTO
, uintptr(s
), base
, uintptr(len(p
)), uintptr(flags
), uintptr(to
), uintptr(addrlen
))
268 func recvmsg(s
int, msg
*Msghdr
, flags
int) (n
int, err error
) {
269 n
, e
:= socketcall(_RECVMSG
, uintptr(s
), uintptr(unsafe
.Pointer(msg
)), uintptr(flags
), 0, 0, 0)
276 func sendmsg(s
int, msg
*Msghdr
, flags
int) (n
int, err error
) {
277 n
, e
:= socketcall(_SENDMSG
, uintptr(s
), uintptr(unsafe
.Pointer(msg
)), uintptr(flags
), 0, 0, 0)
284 func Listen(s
int, n
int) (err error
) {
285 _
, e
:= socketcall(_LISTEN
, uintptr(s
), uintptr(n
), 0, 0, 0, 0)
292 func Shutdown(s
, how
int) (err error
) {
293 _
, e
:= socketcall(_SHUTDOWN
, uintptr(s
), uintptr(how
), 0, 0, 0, 0)
300 func Fstatfs(fd
int, buf
*Statfs_t
) (err error
) {
301 _
, _
, e
:= Syscall(SYS_FSTATFS64
, uintptr(fd
), unsafe
.Sizeof(*buf
), uintptr(unsafe
.Pointer(buf
)))
308 func Statfs(path
string, buf
*Statfs_t
) (err error
) {
309 pathp
, err
:= BytePtrFromString(path
)
313 _
, _
, e
:= Syscall(SYS_STATFS64
, uintptr(unsafe
.Pointer(pathp
)), unsafe
.Sizeof(*buf
), uintptr(unsafe
.Pointer(buf
)))
320 func (r
*PtraceRegs
) PC() uint64 { return uint64(uint32(r
.Eip
)) }
322 func (r
*PtraceRegs
) SetPC(pc
uint64) { r
.Eip
= int32(pc
) }
324 func (iov
*Iovec
) SetLen(length
int) {
325 iov
.Len
= uint32(length
)
328 func (msghdr
*Msghdr
) SetControllen(length
int) {
329 msghdr
.Controllen
= uint32(length
)
332 func (msghdr
*Msghdr
) SetIovlen(length
int) {
333 msghdr
.Iovlen
= uint32(length
)
336 func (cmsg
*Cmsghdr
) SetLen(length
int) {
337 cmsg
.Len
= uint32(length
)
340 func (rsa
*RawSockaddrNFCLLCP
) SetServiceNameLen(length
int) {
341 rsa
.Service_name_len
= uint32(length
)