Source file src/syscall/syscall_linux_arm.go

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

View as plain text