2009-06-04 13:33:40 -07:00
|
|
|
// Copyright 2009 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
|
|
|
|
|
|
2009-08-12 13:19:17 -07:00
|
|
|
import "unsafe"
|
2009-06-04 13:33:40 -07:00
|
|
|
|
2020-05-28 13:58:45 +02:00
|
|
|
const _SYS_setgroups = SYS_SETGROUPS32
|
2015-03-09 07:03:00 +11:00
|
|
|
|
2016-10-11 21:04:16 -07:00
|
|
|
func setTimespec(sec, nsec int64) Timespec {
|
|
|
|
|
return Timespec{Sec: int32(sec), Nsec: int32(nsec)}
|
2009-06-04 13:33:40 -07:00
|
|
|
}
|
|
|
|
|
|
2016-10-11 21:04:16 -07:00
|
|
|
func setTimeval(sec, usec int64) Timeval {
|
|
|
|
|
return Timeval{Sec: int32(sec), Usec: int32(usec)}
|
2009-06-04 13:33:40 -07:00
|
|
|
}
|
|
|
|
|
|
2015-02-25 10:20:13 +11:00
|
|
|
//sysnb pipe(p *[2]_C_int) (err error)
|
|
|
|
|
|
|
|
|
|
func Pipe(p []int) (err error) {
|
|
|
|
|
if len(p) != 2 {
|
|
|
|
|
return EINVAL
|
|
|
|
|
}
|
|
|
|
|
var pp [2]_C_int
|
|
|
|
|
err = pipe(&pp)
|
|
|
|
|
p[0] = int(pp[0])
|
|
|
|
|
p[1] = int(pp[1])
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//sysnb pipe2(p *[2]_C_int, flags int) (err error)
|
|
|
|
|
|
|
|
|
|
func Pipe2(p []int, flags int) (err error) {
|
|
|
|
|
if len(p) != 2 {
|
|
|
|
|
return EINVAL
|
|
|
|
|
}
|
|
|
|
|
var pp [2]_C_int
|
|
|
|
|
err = pipe2(&pp, flags)
|
|
|
|
|
p[0] = int(pp[0])
|
|
|
|
|
p[1] = int(pp[1])
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-16 17:17:02 -07:00
|
|
|
// 64-bit file system and 32-bit uid calls
|
|
|
|
|
// (386 default is 32-bit file system and 16-bit uid).
|
2015-03-26 08:02:16 -07:00
|
|
|
//sys Dup2(oldfd int, newfd int) (err error)
|
2019-10-05 13:44:36 +02:00
|
|
|
//sysnb EpollCreate(size int) (fd int, err error)
|
2011-11-13 22:44:52 -05:00
|
|
|
//sys Fchown(fd int, uid int, gid int) (err error) = SYS_FCHOWN32
|
|
|
|
|
//sys Fstat(fd int, stat *Stat_t) (err error) = SYS_FSTAT64
|
2018-07-27 10:48:18 -07:00
|
|
|
//sys fstatat(dirfd int, path string, stat *Stat_t, flags int) (err error) = SYS_FSTATAT64
|
2011-11-13 22:44:52 -05:00
|
|
|
//sys Ftruncate(fd int, length int64) (err error) = SYS_FTRUNCATE64
|
2011-03-16 19:03:01 -07:00
|
|
|
//sysnb Getegid() (egid int) = SYS_GETEGID32
|
|
|
|
|
//sysnb Geteuid() (euid int) = SYS_GETEUID32
|
|
|
|
|
//sysnb Getgid() (gid int) = SYS_GETGID32
|
|
|
|
|
//sysnb Getuid() (uid int) = SYS_GETUID32
|
2015-05-07 21:08:40 +00:00
|
|
|
//sysnb InotifyInit() (fd int, err error)
|
2011-11-13 22:44:52 -05:00
|
|
|
//sys Ioperm(from int, num int, on int) (err error)
|
|
|
|
|
//sys Iopl(level int) (err error)
|
2019-10-05 13:44:36 +02:00
|
|
|
//sys Pause() (err error)
|
2011-11-13 22:44:52 -05:00
|
|
|
//sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64
|
|
|
|
|
//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64
|
2019-05-08 12:12:49 +02:00
|
|
|
//sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error)
|
2012-10-29 23:15:06 +04:00
|
|
|
//sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) = SYS_SENDFILE64
|
2011-11-13 22:44:52 -05:00
|
|
|
//sys Setfsgid(gid int) (err error) = SYS_SETFSGID32
|
|
|
|
|
//sys Setfsuid(uid int) (err error) = SYS_SETFSUID32
|
|
|
|
|
//sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int, err error)
|
|
|
|
|
//sys SyncFileRange(fd int, off int64, n int64, flags int) (err error)
|
|
|
|
|
//sys Truncate(path string, length int64) (err error) = SYS_TRUNCATE64
|
2019-10-05 13:44:36 +02:00
|
|
|
//sys Ustat(dev int, ubuf *Ustat_t) (err error)
|
2011-11-13 22:44:52 -05:00
|
|
|
//sysnb getgroups(n int, list *_Gid_t) (nn int, err error) = SYS_GETGROUPS32
|
|
|
|
|
//sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) = SYS__NEWSELECT
|
|
|
|
|
|
|
|
|
|
//sys mmap2(addr uintptr, length uintptr, prot int, flags int, fd int, pageOffset uintptr) (xaddr uintptr, err error)
|
2018-05-31 06:46:50 +00:00
|
|
|
//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error)
|
2011-11-13 22:44:52 -05:00
|
|
|
|
2018-09-22 10:30:05 +02:00
|
|
|
func Stat(path string, stat *Stat_t) (err error) {
|
|
|
|
|
return fstatat(_AT_FDCWD, path, stat, 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Lchown(path string, uid int, gid int) (err error) {
|
|
|
|
|
return Fchownat(_AT_FDCWD, path, uid, gid, _AT_SYMLINK_NOFOLLOW)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Lstat(path string, stat *Stat_t) (err error) {
|
|
|
|
|
return fstatat(_AT_FDCWD, path, stat, _AT_SYMLINK_NOFOLLOW)
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 22:44:52 -05:00
|
|
|
func mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) {
|
2011-04-06 17:52:02 -04:00
|
|
|
page := uintptr(offset / 4096)
|
|
|
|
|
if offset != int64(page)*4096 {
|
|
|
|
|
return 0, EINVAL
|
|
|
|
|
}
|
|
|
|
|
return mmap2(addr, length, prot, flags, fd, page)
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-02 22:57:32 -07:00
|
|
|
type rlimit32 struct {
|
|
|
|
|
Cur uint32
|
|
|
|
|
Max uint32
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//sysnb getrlimit(resource int, rlim *rlimit32) (err error) = SYS_GETRLIMIT
|
|
|
|
|
|
|
|
|
|
const rlimInf32 = ^uint32(0)
|
|
|
|
|
const rlimInf64 = ^uint64(0)
|
|
|
|
|
|
|
|
|
|
func Getrlimit(resource int, rlim *Rlimit) (err error) {
|
2013-07-25 09:56:06 -04:00
|
|
|
err = prlimit(0, resource, nil, rlim)
|
2012-07-02 22:57:32 -07:00
|
|
|
if err != ENOSYS {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rl := rlimit32{}
|
|
|
|
|
err = getrlimit(resource, &rl)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if rl.Cur == rlimInf32 {
|
|
|
|
|
rlim.Cur = rlimInf64
|
|
|
|
|
} else {
|
|
|
|
|
rlim.Cur = uint64(rl.Cur)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if rl.Max == rlimInf32 {
|
|
|
|
|
rlim.Max = rlimInf64
|
|
|
|
|
} else {
|
|
|
|
|
rlim.Max = uint64(rl.Max)
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//sysnb setrlimit(resource int, rlim *rlimit32) (err error) = SYS_SETRLIMIT
|
|
|
|
|
|
|
|
|
|
func Setrlimit(resource int, rlim *Rlimit) (err error) {
|
2013-07-25 09:56:06 -04:00
|
|
|
err = prlimit(0, resource, rlim, nil)
|
2012-07-02 22:57:32 -07:00
|
|
|
if err != ENOSYS {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rl := rlimit32{}
|
|
|
|
|
if rlim.Cur == rlimInf64 {
|
|
|
|
|
rl.Cur = rlimInf32
|
|
|
|
|
} else if rlim.Cur < uint64(rlimInf32) {
|
|
|
|
|
rl.Cur = uint32(rlim.Cur)
|
|
|
|
|
} else {
|
|
|
|
|
return EINVAL
|
|
|
|
|
}
|
|
|
|
|
if rlim.Max == rlimInf64 {
|
|
|
|
|
rl.Max = rlimInf32
|
|
|
|
|
} else if rlim.Max < uint64(rlimInf32) {
|
|
|
|
|
rl.Max = uint32(rlim.Max)
|
|
|
|
|
} else {
|
|
|
|
|
return EINVAL
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return setrlimit(resource, &rl)
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-16 17:17:02 -07:00
|
|
|
// Underlying system call writes to newoffset via pointer.
|
|
|
|
|
// Implemented in assembly to avoid allocation.
|
2014-05-16 12:15:32 -04:00
|
|
|
func seek(fd int, offset int64, whence int) (newoffset int64, err Errno)
|
|
|
|
|
|
|
|
|
|
func Seek(fd int, offset int64, whence int) (newoffset int64, err error) {
|
|
|
|
|
newoffset, errno := seek(fd, offset, whence)
|
|
|
|
|
if errno != 0 {
|
|
|
|
|
return 0, errno
|
|
|
|
|
}
|
|
|
|
|
return newoffset, nil
|
|
|
|
|
}
|
2009-06-16 17:17:02 -07:00
|
|
|
|
2019-10-05 13:44:36 +02:00
|
|
|
//sys futimesat(dirfd int, path string, times *[2]Timeval) (err error)
|
2011-11-13 22:44:52 -05:00
|
|
|
//sysnb Gettimeofday(tv *Timeval) (err error)
|
|
|
|
|
//sysnb Time(t *Time_t) (tt Time_t, err error)
|
2019-10-05 13:44:36 +02:00
|
|
|
//sys Utime(path string, buf *Utimbuf) (err error)
|
|
|
|
|
//sys utimes(path string, times *[2]Timeval) (err error)
|
2010-09-21 06:49:56 -07:00
|
|
|
|
2009-06-04 13:33:40 -07:00
|
|
|
// On x86 Linux, all the socket calls go through an extra indirection,
|
|
|
|
|
// I think because the 5-register system call interface can't handle
|
2016-03-01 23:21:55 +00:00
|
|
|
// the 6-argument calls like sendto and recvfrom. Instead the
|
2009-06-04 13:33:40 -07:00
|
|
|
// arguments to the underlying system call are the number below
|
2016-03-01 23:21:55 +00:00
|
|
|
// and a pointer to an array of uintptr. We hide the pointer in the
|
2009-06-04 13:33:40 -07:00
|
|
|
// socketcall assembly to avoid allocation on every system call.
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
// see linux/net.h
|
2009-12-15 15:40:16 -08:00
|
|
|
_SOCKET = 1
|
|
|
|
|
_BIND = 2
|
|
|
|
|
_CONNECT = 3
|
|
|
|
|
_LISTEN = 4
|
|
|
|
|
_ACCEPT = 5
|
|
|
|
|
_GETSOCKNAME = 6
|
|
|
|
|
_GETPEERNAME = 7
|
|
|
|
|
_SOCKETPAIR = 8
|
|
|
|
|
_SEND = 9
|
|
|
|
|
_RECV = 10
|
|
|
|
|
_SENDTO = 11
|
|
|
|
|
_RECVFROM = 12
|
|
|
|
|
_SHUTDOWN = 13
|
|
|
|
|
_SETSOCKOPT = 14
|
|
|
|
|
_GETSOCKOPT = 15
|
|
|
|
|
_SENDMSG = 16
|
|
|
|
|
_RECVMSG = 17
|
2013-01-28 08:54:15 -08:00
|
|
|
_ACCEPT4 = 18
|
|
|
|
|
_RECVMMSG = 19
|
|
|
|
|
_SENDMMSG = 20
|
2009-06-04 13:33:40 -07:00
|
|
|
)
|
|
|
|
|
|
2011-11-13 22:44:52 -05:00
|
|
|
func socketcall(call int, a0, a1, a2, a3, a4, a5 uintptr) (n int, err Errno)
|
|
|
|
|
func rawsocketcall(call int, a0, a1, a2, a3, a4, a5 uintptr) (n int, err Errno)
|
2009-06-04 13:33:40 -07:00
|
|
|
|
2011-11-13 22:44:52 -05:00
|
|
|
func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) {
|
|
|
|
|
fd, e := socketcall(_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), 0, 0, 0)
|
|
|
|
|
if e != 0 {
|
|
|
|
|
err = e
|
|
|
|
|
}
|
2009-12-15 15:40:16 -08:00
|
|
|
return
|
2009-06-04 13:33:40 -07:00
|
|
|
}
|
|
|
|
|
|
2013-01-28 08:54:15 -08:00
|
|
|
func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) {
|
|
|
|
|
fd, e := socketcall(_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0)
|
|
|
|
|
if e != 0 {
|
|
|
|
|
err = e
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 22:44:52 -05:00
|
|
|
func getsockname(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) {
|
|
|
|
|
_, e := rawsocketcall(_GETSOCKNAME, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), 0, 0, 0)
|
|
|
|
|
if e != 0 {
|
|
|
|
|
err = e
|
|
|
|
|
}
|
2009-12-15 15:40:16 -08:00
|
|
|
return
|
2009-06-17 21:44:26 -07:00
|
|
|
}
|
|
|
|
|
|
2011-11-13 22:44:52 -05:00
|
|
|
func getpeername(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) {
|
|
|
|
|
_, e := rawsocketcall(_GETPEERNAME, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), 0, 0, 0)
|
|
|
|
|
if e != 0 {
|
|
|
|
|
err = e
|
|
|
|
|
}
|
2009-12-15 15:40:16 -08:00
|
|
|
return
|
2009-06-17 21:44:26 -07:00
|
|
|
}
|
|
|
|
|
|
2012-09-24 00:06:22 -04:00
|
|
|
func socketpair(domain int, typ int, flags int, fd *[2]int32) (err error) {
|
2011-11-13 22:44:52 -05:00
|
|
|
_, e := rawsocketcall(_SOCKETPAIR, uintptr(domain), uintptr(typ), uintptr(flags), uintptr(unsafe.Pointer(fd)), 0, 0)
|
|
|
|
|
if e != 0 {
|
|
|
|
|
err = e
|
|
|
|
|
}
|
2010-06-30 14:58:21 -07:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-21 18:54:49 -08:00
|
|
|
func bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) {
|
2011-11-13 22:44:52 -05:00
|
|
|
_, e := socketcall(_BIND, uintptr(s), uintptr(addr), uintptr(addrlen), 0, 0, 0)
|
|
|
|
|
if e != 0 {
|
|
|
|
|
err = e
|
|
|
|
|
}
|
2009-12-15 15:40:16 -08:00
|
|
|
return
|
2009-06-04 13:33:40 -07:00
|
|
|
}
|
|
|
|
|
|
2014-01-21 18:54:49 -08:00
|
|
|
func connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) {
|
2011-11-13 22:44:52 -05:00
|
|
|
_, e := socketcall(_CONNECT, uintptr(s), uintptr(addr), uintptr(addrlen), 0, 0, 0)
|
|
|
|
|
if e != 0 {
|
|
|
|
|
err = e
|
|
|
|
|
}
|
2009-12-15 15:40:16 -08:00
|
|
|
return
|
2009-06-04 13:33:40 -07:00
|
|
|
}
|
|
|
|
|
|
2011-11-13 22:44:52 -05:00
|
|
|
func socket(domain int, typ int, proto int) (fd int, err error) {
|
|
|
|
|
fd, e := rawsocketcall(_SOCKET, uintptr(domain), uintptr(typ), uintptr(proto), 0, 0, 0)
|
|
|
|
|
if e != 0 {
|
|
|
|
|
err = e
|
|
|
|
|
}
|
2009-12-15 15:40:16 -08:00
|
|
|
return
|
2009-06-04 13:33:40 -07:00
|
|
|
}
|
|
|
|
|
|
2014-01-21 18:54:49 -08:00
|
|
|
func getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) {
|
2011-11-13 22:44:52 -05:00
|
|
|
_, e := socketcall(_GETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(unsafe.Pointer(vallen)), 0)
|
|
|
|
|
if e != 0 {
|
|
|
|
|
err = e
|
|
|
|
|
}
|
2011-03-23 14:33:48 -04:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-21 18:54:49 -08:00
|
|
|
func setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) {
|
|
|
|
|
_, e := socketcall(_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), vallen, 0)
|
2011-11-13 22:44:52 -05:00
|
|
|
if e != 0 {
|
|
|
|
|
err = e
|
|
|
|
|
}
|
2009-12-15 15:40:16 -08:00
|
|
|
return
|
2009-06-04 13:33:40 -07:00
|
|
|
}
|
|
|
|
|
|
2011-11-13 22:44:52 -05:00
|
|
|
func recvfrom(s int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) {
|
2009-12-15 15:40:16 -08:00
|
|
|
var base uintptr
|
2009-11-01 11:13:27 -08:00
|
|
|
if len(p) > 0 {
|
2009-11-17 08:39:04 -08:00
|
|
|
base = uintptr(unsafe.Pointer(&p[0]))
|
2009-11-01 11:13:27 -08:00
|
|
|
}
|
2011-11-13 22:44:52 -05:00
|
|
|
n, e := socketcall(_RECVFROM, uintptr(s), base, uintptr(len(p)), uintptr(flags), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen)))
|
|
|
|
|
if e != 0 {
|
|
|
|
|
err = e
|
|
|
|
|
}
|
2009-12-15 15:40:16 -08:00
|
|
|
return
|
2009-11-01 11:13:27 -08:00
|
|
|
}
|
|
|
|
|
|
2014-01-21 18:54:49 -08:00
|
|
|
func sendto(s int, p []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) {
|
2009-12-15 15:40:16 -08:00
|
|
|
var base uintptr
|
2009-11-01 11:13:27 -08:00
|
|
|
if len(p) > 0 {
|
2009-11-17 08:39:04 -08:00
|
|
|
base = uintptr(unsafe.Pointer(&p[0]))
|
2009-11-01 11:13:27 -08:00
|
|
|
}
|
2014-01-21 18:54:49 -08:00
|
|
|
_, e := socketcall(_SENDTO, uintptr(s), base, uintptr(len(p)), uintptr(flags), uintptr(to), uintptr(addrlen))
|
2011-11-13 22:44:52 -05:00
|
|
|
if e != 0 {
|
|
|
|
|
err = e
|
|
|
|
|
}
|
2009-12-15 15:40:16 -08:00
|
|
|
return
|
2009-11-05 10:55:57 -08:00
|
|
|
}
|
2009-11-01 11:13:27 -08:00
|
|
|
|
2011-11-13 22:44:52 -05:00
|
|
|
func recvmsg(s int, msg *Msghdr, flags int) (n int, err error) {
|
|
|
|
|
n, e := socketcall(_RECVMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags), 0, 0, 0)
|
|
|
|
|
if e != 0 {
|
|
|
|
|
err = e
|
|
|
|
|
}
|
2010-12-07 13:40:14 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-29 09:28:40 +09:00
|
|
|
func sendmsg(s int, msg *Msghdr, flags int) (n int, err error) {
|
|
|
|
|
n, e := socketcall(_SENDMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags), 0, 0, 0)
|
2011-11-13 22:44:52 -05:00
|
|
|
if e != 0 {
|
|
|
|
|
err = e
|
|
|
|
|
}
|
2010-12-07 13:40:14 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 22:44:52 -05:00
|
|
|
func Listen(s int, n int) (err error) {
|
|
|
|
|
_, e := socketcall(_LISTEN, uintptr(s), uintptr(n), 0, 0, 0, 0)
|
|
|
|
|
if e != 0 {
|
|
|
|
|
err = e
|
|
|
|
|
}
|
2009-12-15 15:40:16 -08:00
|
|
|
return
|
2009-06-04 13:33:40 -07:00
|
|
|
}
|
2009-09-03 16:17:21 -07:00
|
|
|
|
2011-11-13 22:44:52 -05:00
|
|
|
func Shutdown(s, how int) (err error) {
|
|
|
|
|
_, e := socketcall(_SHUTDOWN, uintptr(s), uintptr(how), 0, 0, 0, 0)
|
|
|
|
|
if e != 0 {
|
|
|
|
|
err = e
|
|
|
|
|
}
|
2009-12-15 15:40:16 -08:00
|
|
|
return
|
2009-12-02 08:24:14 -08:00
|
|
|
}
|
|
|
|
|
|
2011-11-13 22:44:52 -05:00
|
|
|
func Fstatfs(fd int, buf *Statfs_t) (err error) {
|
|
|
|
|
_, _, e := Syscall(SYS_FSTATFS64, uintptr(fd), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf)))
|
|
|
|
|
if e != 0 {
|
|
|
|
|
err = e
|
|
|
|
|
}
|
2009-12-15 15:40:16 -08:00
|
|
|
return
|
2009-12-04 21:58:32 -08:00
|
|
|
}
|
|
|
|
|
|
2011-11-13 22:44:52 -05:00
|
|
|
func Statfs(path string, buf *Statfs_t) (err error) {
|
syscall: return EINVAL when string arguments have NUL characters
Since NUL usually terminates strings in underlying syscalls, allowing
it when converting string arguments is a security risk, especially
when dealing with filenames. For example, a program might reason that
filename like "/root/..\x00/" is a subdirectory or "/root/" and allow
access to it, while underlying syscall will treat "\x00" as an end of
that string and the actual filename will be "/root/..", which might
be unexpected. Returning EINVAL when string arguments have NUL in
them makes sure this attack vector is unusable.
R=golang-dev, r, bradfitz, fullung, rsc, minux.ma
CC=golang-dev
https://golang.org/cl/6458050
2012-08-05 17:24:32 -04:00
|
|
|
pathp, err := BytePtrFromString(path)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
_, _, e := Syscall(SYS_STATFS64, uintptr(unsafe.Pointer(pathp)), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf)))
|
2011-11-13 22:44:52 -05:00
|
|
|
if e != 0 {
|
|
|
|
|
err = e
|
|
|
|
|
}
|
2009-12-15 15:40:16 -08:00
|
|
|
return
|
2009-12-04 21:58:32 -08:00
|
|
|
}
|
|
|
|
|
|
2009-12-15 15:40:16 -08:00
|
|
|
func (r *PtraceRegs) PC() uint64 { return uint64(uint32(r.Eip)) }
|
2009-09-03 16:17:21 -07:00
|
|
|
|
2009-12-15 15:40:16 -08:00
|
|
|
func (r *PtraceRegs) SetPC(pc uint64) { r.Eip = int32(pc) }
|
2010-12-07 13:40:14 -05:00
|
|
|
|
|
|
|
|
func (iov *Iovec) SetLen(length int) {
|
|
|
|
|
iov.Len = uint32(length)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (msghdr *Msghdr) SetControllen(length int) {
|
|
|
|
|
msghdr.Controllen = uint32(length)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (cmsg *Cmsghdr) SetLen(length int) {
|
|
|
|
|
cmsg.Len = uint32(length)
|
|
|
|
|
}
|
2017-02-25 18:37:17 +01:00
|
|
|
|
|
|
|
|
func rawVforkSyscall(trap, a1 uintptr) (r1 uintptr, err Errno) {
|
|
|
|
|
panic("not implemented")
|
|
|
|
|
}
|