Black Lives Matter. Support the Equal Justice Initiative.

Source file src/syscall/syscall_linux_arm.go

Documentation: syscall

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

View as plain text