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  //sysnb	EpollCreate(size int) (fd 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  //sysnb	Setregid(rgid int, egid int) (err error)
    39  //sysnb	Setresgid(rgid int, egid int, sgid int) (err error)
    40  //sysnb	Setresuid(ruid int, euid int, suid int) (err error)
    41  
    42  //sysnb	Setreuid(ruid int, euid int) (err error)
    43  //sys	Shutdown(fd int, how int) (err error)
    44  //sys	Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int, err error)
    45  
    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  //sys	accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
    50  //sys	accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
    51  //sys	bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
    52  //sys	connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
    53  //sysnb	getgroups(n int, list *_Gid_t) (nn int, err error)
    54  //sysnb	setgroups(n int, list *_Gid_t) (err error)
    55  //sys	getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error)
    56  //sys	setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error)
    57  //sysnb	socket(domain int, typ int, proto int) (fd int, err error)
    58  //sysnb	socketpair(domain int, typ int, proto int, fd *[2]int32) (err error)
    59  //sysnb	getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
    60  //sysnb	getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
    61  //sys	recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error)
    62  //sys	sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error)
    63  //sys	recvmsg(s int, msg *Msghdr, flags int) (n int, err error)
    64  //sys	sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
    65  
    66  //sysnb	InotifyInit() (fd int, err error)
    67  //sys	Ioperm(from int, num int, on int) (err error)
    68  //sys	Iopl(level int) (err error)
    69  
    70  //sys	futimesat(dirfd int, path string, times *[2]Timeval) (err error)
    71  //sysnb	Gettimeofday(tv *Timeval) (err error)
    72  //sysnb	Time(t *Time_t) (tt Time_t, err error)
    73  //sys	Utime(path string, buf *Utimbuf) (err error)
    74  //sys	utimes(path string, times *[2]Timeval) (err error)
    75  
    76  //sys	Lstat(path string, stat *Stat_t) (err error) = SYS_LSTAT64
    77  //sys	Fstat(fd int, stat *Stat_t) (err error) = SYS_FSTAT64
    78  //sys	Stat(path string, stat *Stat_t) (err error) = SYS_STAT64
    79  //sys	EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error)
    80  
    81  func Fstatfs(fd int, buf *Statfs_t) (err error) {
    82  	_, _, e := Syscall(SYS_FSTATFS64, uintptr(fd), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf)))
    83  	if e != 0 {
    84  		err = errnoErr(e)
    85  	}
    86  	return
    87  }
    88  
    89  func Statfs(path string, buf *Statfs_t) (err error) {
    90  	p, err := BytePtrFromString(path)
    91  	if err != nil {
    92  		return err
    93  	}
    94  	_, _, e := Syscall(SYS_STATFS64, uintptr(unsafe.Pointer(p)), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf)))
    95  	if e != 0 {
    96  		err = errnoErr(e)
    97  	}
    98  	return
    99  }
   100  
   101  func Seek(fd int, offset int64, whence int) (off int64, err error) {
   102  	_, _, e := Syscall6(SYS__LLSEEK, uintptr(fd), uintptr(offset>>32), uintptr(offset), uintptr(unsafe.Pointer(&off)), uintptr(whence), 0)
   103  	if e != 0 {
   104  		err = errnoErr(e)
   105  	}
   106  	return
   107  }
   108  
   109  func setTimespec(sec, nsec int64) Timespec {
   110  	return Timespec{Sec: int32(sec), Nsec: int32(nsec)}
   111  }
   112  
   113  func setTimeval(sec, usec int64) Timeval {
   114  	return Timeval{Sec: int32(sec), Usec: int32(usec)}
   115  }
   116  
   117  //sysnb pipe2(p *[2]_C_int, flags int) (err error)
   118  
   119  func Pipe2(p []int, flags int) (err error) {
   120  	if len(p) != 2 {
   121  		return EINVAL
   122  	}
   123  	var pp [2]_C_int
   124  	err = pipe2(&pp, flags)
   125  	p[0] = int(pp[0])
   126  	p[1] = int(pp[1])
   127  	return
   128  }
   129  
   130  //sysnb pipe() (p1 int, p2 int, err error)
   131  
   132  func Pipe(p []int) (err error) {
   133  	if len(p) != 2 {
   134  		return EINVAL
   135  	}
   136  	p[0], p[1], err = pipe()
   137  	return
   138  }
   139  
   140  //sys	mmap2(addr uintptr, length uintptr, prot int, flags int, fd int, pageOffset uintptr) (xaddr uintptr, err error)
   141  
   142  func mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) {
   143  	page := uintptr(offset / 4096)
   144  	if offset != int64(page)*4096 {
   145  		return 0, EINVAL
   146  	}
   147  	return mmap2(addr, length, prot, flags, fd, page)
   148  }
   149  
   150  const rlimInf32 = ^uint32(0)
   151  const rlimInf64 = ^uint64(0)
   152  
   153  type rlimit32 struct {
   154  	Cur uint32
   155  	Max uint32
   156  }
   157  
   158  //sysnb getrlimit(resource int, rlim *rlimit32) (err error) = SYS_GETRLIMIT
   159  
   160  func Getrlimit(resource int, rlim *Rlimit) (err error) {
   161  	err = prlimit(0, resource, nil, rlim)
   162  	if err != ENOSYS {
   163  		return err
   164  	}
   165  
   166  	rl := rlimit32{}
   167  	err = getrlimit(resource, &rl)
   168  	if err != nil {
   169  		return
   170  	}
   171  
   172  	if rl.Cur == rlimInf32 {
   173  		rlim.Cur = rlimInf64
   174  	} else {
   175  		rlim.Cur = uint64(rl.Cur)
   176  	}
   177  
   178  	if rl.Max == rlimInf32 {
   179  		rlim.Max = rlimInf64
   180  	} else {
   181  		rlim.Max = uint64(rl.Max)
   182  	}
   183  	return
   184  }
   185  
   186  //sysnb setrlimit(resource int, rlim *rlimit32) (err error) = SYS_SETRLIMIT
   187  
   188  func Setrlimit(resource int, rlim *Rlimit) (err error) {
   189  	err = prlimit(0, resource, rlim, nil)
   190  	if err != ENOSYS {
   191  		return err
   192  	}
   193  
   194  	rl := rlimit32{}
   195  	if rlim.Cur == rlimInf64 {
   196  		rl.Cur = rlimInf32
   197  	} else if rlim.Cur < uint64(rlimInf32) {
   198  		rl.Cur = uint32(rlim.Cur)
   199  	} else {
   200  		return EINVAL
   201  	}
   202  	if rlim.Max == rlimInf64 {
   203  		rl.Max = rlimInf32
   204  	} else if rlim.Max < uint64(rlimInf32) {
   205  		rl.Max = uint32(rlim.Max)
   206  	} else {
   207  		return EINVAL
   208  	}
   209  
   210  	return setrlimit(resource, &rl)
   211  }
   212  
   213  func (r *PtraceRegs) PC() uint64 { return uint64(r.Regs[64]) }
   214  
   215  func (r *PtraceRegs) SetPC(pc uint64) { r.Regs[64] = uint32(pc) }
   216  
   217  func (iov *Iovec) SetLen(length int) {
   218  	iov.Len = uint32(length)
   219  }
   220  
   221  func (msghdr *Msghdr) SetControllen(length int) {
   222  	msghdr.Controllen = uint32(length)
   223  }
   224  
   225  func (cmsg *Cmsghdr) SetLen(length int) {
   226  	cmsg.Len = uint32(length)
   227  }
   228  
   229  func rawVforkSyscall(trap, a1 uintptr) (r1 uintptr, err Errno) {
   230  	panic("not implemented")
   231  }
   232  

View as plain text