...

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

View as plain text