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

View as plain text