...
Run Format

Source file src/syscall/syscall_linux_mipsx.go

Documentation: syscall

     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  // +build linux
     6  // +build mips mipsle
     7  
     8  package syscall
     9  
    10  import "unsafe"
    11  
    12  const (
    13  	_SYS_dup       = SYS_DUP2
    14  	_SYS_setgroups = SYS_SETGROUPS
    15  )
    16  
    17  func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno)
    18  
    19  //sys	Dup2(oldfd int, newfd int) (err error)
    20  //sys	Fchown(fd int, uid int, gid int) (err error)
    21  //sys	fstatat(dirfd int, path string, stat *Stat_t, flags int) (err error) = SYS_FSTATAT64
    22  //sys	Ftruncate(fd int, length int64) (err error) = SYS_FTRUNCATE64
    23  //sysnb	Getegid() (egid int)
    24  //sysnb	Geteuid() (euid int)
    25  //sysnb	Getgid() (gid int)
    26  //sysnb	Getuid() (uid int)
    27  //sys	Lchown(path string, uid int, gid int) (err error)
    28  //sys	Listen(s int, n int) (err error)
    29  //sys	Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64
    30  //sys	Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64
    31  //sys	Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) = SYS__NEWSELECT
    32  //sys	sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) = SYS_SENDFILE64
    33  //sys	Setfsgid(gid int) (err error)
    34  //sys	Setfsuid(uid int) (err error)
    35  //sysnb	Setregid(rgid int, egid int) (err error)
    36  //sysnb	Setresgid(rgid int, egid int, sgid int) (err error)
    37  //sysnb	Setresuid(ruid int, euid int, suid int) (err error)
    38  
    39  //sysnb	Setreuid(ruid int, euid int) (err error)
    40  //sys	Shutdown(fd int, how int) (err error)
    41  //sys	Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int, err error)
    42  
    43  //sys	SyncFileRange(fd int, off int64, n int64, flags int) (err error)
    44  //sys	Truncate(path string, length int64) (err error) = SYS_TRUNCATE64
    45  //sys	accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
    46  //sys	accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
    47  //sys	bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
    48  //sys	connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
    49  //sysnb	getgroups(n int, list *_Gid_t) (nn int, err error)
    50  //sysnb	setgroups(n int, list *_Gid_t) (err error)
    51  //sys	getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error)
    52  //sys	setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error)
    53  //sysnb	socket(domain int, typ int, proto int) (fd int, err error)
    54  //sysnb	socketpair(domain int, typ int, proto int, fd *[2]int32) (err error)
    55  //sysnb	getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
    56  //sysnb	getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
    57  //sys	recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error)
    58  //sys	sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error)
    59  //sys	recvmsg(s int, msg *Msghdr, flags int) (n int, err error)
    60  //sys	sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
    61  
    62  //sysnb	InotifyInit() (fd int, err error)
    63  //sys	Ioperm(from int, num int, on int) (err error)
    64  //sys	Iopl(level int) (err error)
    65  
    66  //sysnb	Gettimeofday(tv *Timeval) (err error)
    67  //sysnb	Time(t *Time_t) (tt Time_t, 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  //sysnb pipe2(p *[2]_C_int, flags int) (err error)
   111  
   112  func Pipe2(p []int, flags int) (err error) {
   113  	if len(p) != 2 {
   114  		return EINVAL
   115  	}
   116  	var pp [2]_C_int
   117  	err = pipe2(&pp, flags)
   118  	p[0] = int(pp[0])
   119  	p[1] = int(pp[1])
   120  	return
   121  }
   122  
   123  //sysnb pipe() (p1 int, p2 int, err error)
   124  
   125  func Pipe(p []int) (err error) {
   126  	if len(p) != 2 {
   127  		return EINVAL
   128  	}
   129  	p[0], p[1], err = pipe()
   130  	return
   131  }
   132  
   133  //sys	mmap2(addr uintptr, length uintptr, prot int, flags int, fd int, pageOffset uintptr) (xaddr uintptr, err error)
   134  
   135  func mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) {
   136  	page := uintptr(offset / 4096)
   137  	if offset != int64(page)*4096 {
   138  		return 0, EINVAL
   139  	}
   140  	return mmap2(addr, length, prot, flags, fd, page)
   141  }
   142  
   143  const rlimInf32 = ^uint32(0)
   144  const rlimInf64 = ^uint64(0)
   145  
   146  type rlimit32 struct {
   147  	Cur uint32
   148  	Max uint32
   149  }
   150  
   151  //sysnb getrlimit(resource int, rlim *rlimit32) (err error) = SYS_GETRLIMIT
   152  
   153  func Getrlimit(resource int, rlim *Rlimit) (err error) {
   154  	err = prlimit(0, resource, nil, rlim)
   155  	if err != ENOSYS {
   156  		return err
   157  	}
   158  
   159  	rl := rlimit32{}
   160  	err = getrlimit(resource, &rl)
   161  	if err != nil {
   162  		return
   163  	}
   164  
   165  	if rl.Cur == rlimInf32 {
   166  		rlim.Cur = rlimInf64
   167  	} else {
   168  		rlim.Cur = uint64(rl.Cur)
   169  	}
   170  
   171  	if rl.Max == rlimInf32 {
   172  		rlim.Max = rlimInf64
   173  	} else {
   174  		rlim.Max = uint64(rl.Max)
   175  	}
   176  	return
   177  }
   178  
   179  //sysnb setrlimit(resource int, rlim *rlimit32) (err error) = SYS_SETRLIMIT
   180  
   181  func Setrlimit(resource int, rlim *Rlimit) (err error) {
   182  	err = prlimit(0, resource, rlim, nil)
   183  	if err != ENOSYS {
   184  		return err
   185  	}
   186  
   187  	rl := rlimit32{}
   188  	if rlim.Cur == rlimInf64 {
   189  		rl.Cur = rlimInf32
   190  	} else if rlim.Cur < uint64(rlimInf32) {
   191  		rl.Cur = uint32(rlim.Cur)
   192  	} else {
   193  		return EINVAL
   194  	}
   195  	if rlim.Max == rlimInf64 {
   196  		rl.Max = rlimInf32
   197  	} else if rlim.Max < uint64(rlimInf32) {
   198  		rl.Max = uint32(rlim.Max)
   199  	} else {
   200  		return EINVAL
   201  	}
   202  
   203  	return setrlimit(resource, &rl)
   204  }
   205  
   206  func (r *PtraceRegs) PC() uint64 { return uint64(r.Regs[64]) }
   207  
   208  func (r *PtraceRegs) SetPC(pc uint64) { r.Regs[64] = uint32(pc) }
   209  
   210  func (iov *Iovec) SetLen(length int) {
   211  	iov.Len = uint32(length)
   212  }
   213  
   214  func (msghdr *Msghdr) SetControllen(length int) {
   215  	msghdr.Controllen = uint32(length)
   216  }
   217  
   218  func (cmsg *Cmsghdr) SetLen(length int) {
   219  	cmsg.Len = uint32(length)
   220  }
   221  
   222  func rawVforkSyscall(trap, a1 uintptr) (r1 uintptr, err Errno) {
   223  	panic("not implemented")
   224  }
   225  

View as plain text