Source file src/syscall/syscall_linux_mipsx.go

     1  // Copyright 2016 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.
     4  
     5  //go:build linux && (mips || mipsle)
     6  
     7  package syscall
     8  
     9  import "unsafe"
    10  
    11  const _SYS_setgroups = SYS_SETGROUPS
    12  
    13  func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno)
    14  
    15  //sys	Dup2(oldfd int, newfd int) (err error)
    16  //sysnb	EpollCreate(size int) (fd int, err error)
    17  //sys	Fchown(fd int, uid int, gid int) (err error)
    18  //sys	fstatat(dirfd int, path string, stat *Stat_t, flags int) (err error) = SYS_FSTATAT64
    19  //sys	Ftruncate(fd int, length int64) (err error) = SYS_FTRUNCATE64
    20  //sysnb	Getegid() (egid int)
    21  //sysnb	Geteuid() (euid int)
    22  //sysnb	Getgid() (gid int)
    23  //sysnb	Getuid() (uid int)
    24  //sys	Lchown(path string, uid int, gid int) (err error)
    25  //sys	Listen(s int, n int) (err error)
    26  //sys	Pause() (err error)
    27  //sys	pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64
    28  //sys	pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64
    29  //sys	Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error)
    30  //sys	Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) = SYS__NEWSELECT
    31  //sys	sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) = SYS_SENDFILE64
    32  //sys	Setfsgid(gid int) (err error)
    33  //sys	Setfsuid(uid int) (err error)
    34  //sys	Shutdown(fd int, how int) (err error)
    35  //sys	Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int, err error)
    36  
    37  //sys	SyncFileRange(fd int, off int64, n int64, flags int) (err error)
    38  //sys	Truncate(path string, length int64) (err error) = SYS_TRUNCATE64
    39  //sys	Ustat(dev int, ubuf *Ustat_t) (err error)
    40  //sys	accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
    41  //sys	bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
    42  //sys	connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
    43  //sysnb	getgroups(n int, list *_Gid_t) (nn int, err error)
    44  //sys	getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error)
    45  //sys	setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error)
    46  //sysnb	socket(domain int, typ int, proto int) (fd int, err error)
    47  //sysnb	socketpair(domain int, typ int, proto int, fd *[2]int32) (err error)
    48  //sysnb	getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
    49  //sysnb	getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
    50  //sys	recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error)
    51  //sys	sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error)
    52  //sys	recvmsg(s int, msg *Msghdr, flags int) (n int, err error)
    53  //sys	sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
    54  
    55  //sysnb	InotifyInit() (fd int, err error)
    56  //sys	Ioperm(from int, num int, on int) (err error)
    57  //sys	Iopl(level int) (err error)
    58  
    59  //sys	futimesat(dirfd int, path string, times *[2]Timeval) (err error)
    60  //sysnb	Gettimeofday(tv *Timeval) (err error)
    61  //sysnb	Time(t *Time_t) (tt Time_t, err error)
    62  //sys	Utime(path string, buf *Utimbuf) (err error)
    63  //sys	utimes(path string, times *[2]Timeval) (err error)
    64  
    65  //sys	Lstat(path string, stat *Stat_t) (err error) = SYS_LSTAT64
    66  //sys	Fstat(fd int, stat *Stat_t) (err error) = SYS_FSTAT64
    67  //sys	Stat(path string, stat *Stat_t) (err error) = SYS_STAT64
    68  //sys	EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error)
    69  
    70  func Fstatfs(fd int, buf *Statfs_t) (err error) {
    71  	_, _, e := Syscall(SYS_FSTATFS64, uintptr(fd), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf)))
    72  	if e != 0 {
    73  		err = errnoErr(e)
    74  	}
    75  	return
    76  }
    77  
    78  func Statfs(path string, buf *Statfs_t) (err error) {
    79  	p, err := BytePtrFromString(path)
    80  	if err != nil {
    81  		return err
    82  	}
    83  	_, _, e := Syscall(SYS_STATFS64, uintptr(unsafe.Pointer(p)), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf)))
    84  	if e != 0 {
    85  		err = errnoErr(e)
    86  	}
    87  	return
    88  }
    89  
    90  func Seek(fd int, offset int64, whence int) (off int64, err error) {
    91  	_, _, e := Syscall6(SYS__LLSEEK, uintptr(fd), uintptr(offset>>32), uintptr(offset), uintptr(unsafe.Pointer(&off)), uintptr(whence), 0)
    92  	if e != 0 {
    93  		err = errnoErr(e)
    94  	}
    95  	return
    96  }
    97  
    98  func setTimespec(sec, nsec int64) Timespec {
    99  	return Timespec{Sec: int32(sec), Nsec: int32(nsec)}
   100  }
   101  
   102  func setTimeval(sec, usec int64) Timeval {
   103  	return Timeval{Sec: int32(sec), Usec: int32(usec)}
   104  }
   105  
   106  //sys	mmap2(addr uintptr, length uintptr, prot int, flags int, fd int, pageOffset uintptr) (xaddr uintptr, err error)
   107  
   108  func mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) {
   109  	page := uintptr(offset / 4096)
   110  	if offset != int64(page)*4096 {
   111  		return 0, EINVAL
   112  	}
   113  	return mmap2(addr, length, prot, flags, fd, page)
   114  }
   115  
   116  const rlimInf32 = ^uint32(0)
   117  const rlimInf64 = ^uint64(0)
   118  
   119  type rlimit32 struct {
   120  	Cur uint32
   121  	Max uint32
   122  }
   123  
   124  //sysnb getrlimit(resource int, rlim *rlimit32) (err error) = SYS_GETRLIMIT
   125  
   126  func Getrlimit(resource int, rlim *Rlimit) (err error) {
   127  	err = prlimit(0, resource, nil, rlim)
   128  	if err != ENOSYS {
   129  		return err
   130  	}
   131  
   132  	rl := rlimit32{}
   133  	err = getrlimit(resource, &rl)
   134  	if err != nil {
   135  		return
   136  	}
   137  
   138  	if rl.Cur == rlimInf32 {
   139  		rlim.Cur = rlimInf64
   140  	} else {
   141  		rlim.Cur = uint64(rl.Cur)
   142  	}
   143  
   144  	if rl.Max == rlimInf32 {
   145  		rlim.Max = rlimInf64
   146  	} else {
   147  		rlim.Max = uint64(rl.Max)
   148  	}
   149  	return
   150  }
   151  
   152  //sysnb setrlimit(resource int, rlim *rlimit32) (err error) = SYS_SETRLIMIT
   153  
   154  func Setrlimit(resource int, rlim *Rlimit) (err error) {
   155  	err = prlimit(0, resource, rlim, nil)
   156  	if err != ENOSYS {
   157  		return err
   158  	}
   159  
   160  	rl := rlimit32{}
   161  	if rlim.Cur == rlimInf64 {
   162  		rl.Cur = rlimInf32
   163  	} else if rlim.Cur < uint64(rlimInf32) {
   164  		rl.Cur = uint32(rlim.Cur)
   165  	} else {
   166  		return EINVAL
   167  	}
   168  	if rlim.Max == rlimInf64 {
   169  		rl.Max = rlimInf32
   170  	} else if rlim.Max < uint64(rlimInf32) {
   171  		rl.Max = uint32(rlim.Max)
   172  	} else {
   173  		return EINVAL
   174  	}
   175  
   176  	return setrlimit(resource, &rl)
   177  }
   178  
   179  func (r *PtraceRegs) PC() uint64 { return uint64(r.Regs[64]) }
   180  
   181  func (r *PtraceRegs) SetPC(pc uint64) { r.Regs[64] = uint32(pc) }
   182  
   183  func (iov *Iovec) SetLen(length int) {
   184  	iov.Len = uint32(length)
   185  }
   186  
   187  func (msghdr *Msghdr) SetControllen(length int) {
   188  	msghdr.Controllen = uint32(length)
   189  }
   190  
   191  func (cmsg *Cmsghdr) SetLen(length int) {
   192  	cmsg.Len = uint32(length)
   193  }
   194  
   195  func rawVforkSyscall(trap, a1 uintptr) (r1 uintptr, err Errno)
   196  

View as plain text