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

View as plain text