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

View as plain text