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

View as plain text