Source file src/syscall/syscall_aix.go

Documentation: syscall

     1  // Copyright 2018 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  // Aix system calls.
     6  // This file is compiled as ordinary Go code,
     7  // but it is also input to mksyscall,
     8  // which parses the //sys lines and generates system call stubs.
     9  // Note that sometimes we use a lowercase //sys name and
    10  // wrap it in our own nicer implementation.
    11  
    12  package syscall
    13  
    14  import (
    15  	"unsafe"
    16  )
    17  
    18  // Implemented in runtime/syscall_aix.go.
    19  func rawSyscall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
    20  func syscall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
    21  
    22  // Constant expected by package but not supported
    23  const (
    24  	_ = iota
    25  	TIOCSCTTY
    26  	F_DUPFD_CLOEXEC
    27  	SYS_EXECVE
    28  	SYS_FCNTL
    29  )
    30  
    31  /*
    32   * Wrapped
    33   */
    34  
    35  // fcntl must never be called with cmd=F_DUP2FD because it doesn't work on AIX
    36  // There is no way to create a custom fcntl and to keep //sys fcntl easily,
    37  // because we need fcntl name for its libc symbol. This is linked with the script.
    38  // But, as fcntl is currently not exported and isn't called with F_DUP2FD,
    39  // it doesn't matter.
    40  //sys	fcntl(fd int, cmd int, arg int) (val int, err error)
    41  //sys	dup2(old int, new int) (val int, err error)
    42  
    43  //sysnb pipe(p *[2]_C_int) (err error)
    44  func Pipe(p []int) (err error) {
    45  	if len(p) != 2 {
    46  		return EINVAL
    47  	}
    48  	var pp [2]_C_int
    49  	err = pipe(&pp)
    50  	p[0] = int(pp[0])
    51  	p[1] = int(pp[1])
    52  	return
    53  }
    54  
    55  //sys	readlink(path string, buf []byte, bufSize uint64) (n int, err error)
    56  func Readlink(path string, buf []byte) (n int, err error) {
    57  	s := uint64(len(buf))
    58  	return readlink(path, buf, s)
    59  }
    60  
    61  //sys	utimes(path string, times *[2]Timeval) (err error)
    62  func Utimes(path string, tv []Timeval) error {
    63  	if len(tv) != 2 {
    64  		return EINVAL
    65  	}
    66  	return utimes(path, (*[2]Timeval)(unsafe.Pointer(&tv[0])))
    67  }
    68  
    69  //sys	utimensat(dirfd int, path string, times *[2]Timespec, flag int) (err error)
    70  func UtimesNano(path string, ts []Timespec) error {
    71  	if len(ts) != 2 {
    72  		return EINVAL
    73  	}
    74  	return utimensat(_AT_FDCWD, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
    75  }
    76  
    77  //sys	unlinkat(dirfd int, path string, flags int) (err error)
    78  func Unlinkat(dirfd int, path string) (err error) {
    79  	return unlinkat(dirfd, path, 0)
    80  }
    81  
    82  //sys	getcwd(buf *byte, size uint64) (err error)
    83  
    84  const ImplementsGetwd = true
    85  
    86  func Getwd() (ret string, err error) {
    87  	for len := uint64(4096); ; len *= 2 {
    88  		b := make([]byte, len)
    89  		err := getcwd(&b[0], len)
    90  		if err == nil {
    91  			i := 0
    92  			for b[i] != 0 {
    93  				i++
    94  			}
    95  			return string(b[0:i]), nil
    96  		}
    97  		if err != ERANGE {
    98  			return "", err
    99  		}
   100  	}
   101  }
   102  
   103  func Getcwd(buf []byte) (n int, err error) {
   104  	err = getcwd(&buf[0], uint64(len(buf)))
   105  	if err == nil {
   106  		i := 0
   107  		for buf[i] != 0 {
   108  			i++
   109  		}
   110  		n = i + 1
   111  	}
   112  	return
   113  }
   114  
   115  //sysnb	getgroups(ngid int, gid *_Gid_t) (n int, err error)
   116  //sysnb	setgroups(ngid int, gid *_Gid_t) (err error)
   117  
   118  func Getgroups() (gids []int, err error) {
   119  	n, err := getgroups(0, nil)
   120  	if err != nil {
   121  		return nil, err
   122  	}
   123  	if n == 0 {
   124  		return nil, nil
   125  	}
   126  
   127  	// Sanity check group count. Max is 16 on BSD.
   128  	if n < 0 || n > 1000 {
   129  		return nil, EINVAL
   130  	}
   131  
   132  	a := make([]_Gid_t, n)
   133  	n, err = getgroups(n, &a[0])
   134  	if err != nil {
   135  		return nil, err
   136  	}
   137  	gids = make([]int, n)
   138  	for i, v := range a[0:n] {
   139  		gids[i] = int(v)
   140  	}
   141  	return
   142  }
   143  
   144  func Setgroups(gids []int) (err error) {
   145  	if len(gids) == 0 {
   146  		return setgroups(0, nil)
   147  	}
   148  
   149  	a := make([]_Gid_t, len(gids))
   150  	for i, v := range gids {
   151  		a[i] = _Gid_t(v)
   152  	}
   153  	return setgroups(len(a), &a[0])
   154  }
   155  
   156  func direntIno(buf []byte) (uint64, bool) {
   157  	return readInt(buf, unsafe.Offsetof(Dirent{}.Ino), unsafe.Sizeof(Dirent{}.Ino))
   158  }
   159  
   160  func direntReclen(buf []byte) (uint64, bool) {
   161  	return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))
   162  }
   163  
   164  func direntNamlen(buf []byte) (uint64, bool) {
   165  	reclen, ok := direntReclen(buf)
   166  	if !ok {
   167  		return 0, false
   168  	}
   169  	return reclen - uint64(unsafe.Offsetof(Dirent{}.Name)), true
   170  }
   171  
   172  func Gettimeofday(tv *Timeval) (err error) {
   173  	err = gettimeofday(tv, nil)
   174  	return
   175  }
   176  
   177  // TODO
   178  func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
   179  	return -1, ENOSYS
   180  }
   181  
   182  //sys	getdirent(fd int, buf []byte) (n int, err error)
   183  func ReadDirent(fd int, buf []byte) (n int, err error) {
   184  	return getdirent(fd, buf)
   185  }
   186  
   187  //sys  wait4(pid _Pid_t, status *_C_int, options int, rusage *Rusage) (wpid _Pid_t, err error)
   188  func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, err error) {
   189  	var status _C_int
   190  	var r _Pid_t
   191  	err = ERESTART
   192  	// AIX wait4 may return with ERESTART errno, while the processus is still
   193  	// active.
   194  	for err == ERESTART {
   195  		r, err = wait4(_Pid_t(pid), &status, options, rusage)
   196  	}
   197  	wpid = int(r)
   198  	if wstatus != nil {
   199  		*wstatus = WaitStatus(status)
   200  	}
   201  	return
   202  }
   203  
   204  /*
   205   * Socket
   206   */
   207  //sys	bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
   208  //sys	connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
   209  //sys   Getkerninfo(op int32, where uintptr, size uintptr, arg int64) (i int32, err error)
   210  //sys	getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error)
   211  //sys	Listen(s int, backlog int) (err error)
   212  //sys	setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error)
   213  //sys	socket(domain int, typ int, proto int) (fd int, err error)
   214  //sysnb	socketpair(domain int, typ int, proto int, fd *[2]int32) (err error)
   215  //sysnb	getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
   216  //sys	getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
   217  //sys	recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error)
   218  //sys	sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error)
   219  //sys	Shutdown(s int, how int) (err error)
   220  //sys	recvmsg(s int, msg *Msghdr, flags int) (n int, err error)
   221  //sys	sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
   222  
   223  func (sa *SockaddrInet4) sockaddr() (unsafe.Pointer, _Socklen, error) {
   224  	if sa.Port < 0 || sa.Port > 0xFFFF {
   225  		return nil, 0, EINVAL
   226  	}
   227  	sa.raw.Family = AF_INET
   228  	p := (*[2]byte)(unsafe.Pointer(&sa.raw.Port))
   229  	p[0] = byte(sa.Port >> 8)
   230  	p[1] = byte(sa.Port)
   231  	for i := 0; i < len(sa.Addr); i++ {
   232  		sa.raw.Addr[i] = sa.Addr[i]
   233  	}
   234  	return unsafe.Pointer(&sa.raw), SizeofSockaddrInet4, nil
   235  }
   236  
   237  func (sa *SockaddrInet6) sockaddr() (unsafe.Pointer, _Socklen, error) {
   238  	if sa.Port < 0 || sa.Port > 0xFFFF {
   239  		return nil, 0, EINVAL
   240  	}
   241  	sa.raw.Family = AF_INET6
   242  	p := (*[2]byte)(unsafe.Pointer(&sa.raw.Port))
   243  	p[0] = byte(sa.Port >> 8)
   244  	p[1] = byte(sa.Port)
   245  	sa.raw.Scope_id = sa.ZoneId
   246  	for i := 0; i < len(sa.Addr); i++ {
   247  		sa.raw.Addr[i] = sa.Addr[i]
   248  	}
   249  	return unsafe.Pointer(&sa.raw), SizeofSockaddrInet6, nil
   250  }
   251  
   252  func (sa *RawSockaddrUnix) setLen(n int) {
   253  	sa.Len = uint8(3 + n) // 2 for Family, Len; 1 for NUL.
   254  }
   255  
   256  func (sa *SockaddrUnix) sockaddr() (unsafe.Pointer, _Socklen, error) {
   257  	name := sa.Name
   258  	n := len(name)
   259  	if n > len(sa.raw.Path) {
   260  		return nil, 0, EINVAL
   261  	}
   262  	sa.raw.Family = AF_UNIX
   263  	sa.raw.setLen(n)
   264  	for i := 0; i < n; i++ {
   265  		sa.raw.Path[i] = uint8(name[i])
   266  	}
   267  	// length is family (uint16), name, NUL.
   268  	sl := _Socklen(2)
   269  	if n > 0 {
   270  		sl += _Socklen(n) + 1
   271  	}
   272  
   273  	return unsafe.Pointer(&sa.raw), sl, nil
   274  }
   275  
   276  func Getsockname(fd int) (sa Sockaddr, err error) {
   277  	var rsa RawSockaddrAny
   278  	var len _Socklen = SizeofSockaddrAny
   279  	if err = getsockname(fd, &rsa, &len); err != nil {
   280  		return
   281  	}
   282  	return anyToSockaddr(&rsa)
   283  }
   284  
   285  //sys	accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
   286  func Accept(fd int) (nfd int, sa Sockaddr, err error) {
   287  	var rsa RawSockaddrAny
   288  	var len _Socklen = SizeofSockaddrAny
   289  	nfd, err = accept(fd, &rsa, &len)
   290  	if err != nil {
   291  		return
   292  	}
   293  	sa, err = anyToSockaddr(&rsa)
   294  	if err != nil {
   295  		Close(nfd)
   296  		nfd = 0
   297  	}
   298  	return
   299  }
   300  
   301  func Recvmsg(fd int, p, oob []byte, flags int) (n, oobn int, recvflags int, from Sockaddr, err error) {
   302  	var msg Msghdr
   303  	var rsa RawSockaddrAny
   304  	msg.Name = (*byte)(unsafe.Pointer(&rsa))
   305  	msg.Namelen = uint32(SizeofSockaddrAny)
   306  	var iov Iovec
   307  	if len(p) > 0 {
   308  		iov.Base = (*byte)(unsafe.Pointer(&p[0]))
   309  		iov.SetLen(len(p))
   310  	}
   311  	var dummy byte
   312  	if len(oob) > 0 {
   313  		var sockType int
   314  		sockType, err = GetsockoptInt(fd, SOL_SOCKET, SO_TYPE)
   315  		if err != nil {
   316  			return
   317  		}
   318  		// receive at least one normal byte
   319  		if sockType != SOCK_DGRAM && len(p) == 0 {
   320  			iov.Base = &dummy
   321  			iov.SetLen(1)
   322  		}
   323  		msg.Control = (*byte)(unsafe.Pointer(&oob[0]))
   324  		msg.SetControllen(len(oob))
   325  	}
   326  	msg.Iov = &iov
   327  	msg.Iovlen = 1
   328  	if n, err = recvmsg(fd, &msg, flags); err != nil {
   329  		return
   330  	}
   331  	oobn = int(msg.Controllen)
   332  	recvflags = int(msg.Flags)
   333  	// source address is only specified if the socket is unconnected
   334  	if rsa.Addr.Family != AF_UNSPEC {
   335  		from, err = anyToSockaddr(&rsa)
   336  	}
   337  	return
   338  }
   339  
   340  func Sendmsg(fd int, p, oob []byte, to Sockaddr, flags int) (err error) {
   341  	_, err = SendmsgN(fd, p, oob, to, flags)
   342  	return
   343  }
   344  
   345  func SendmsgN(fd int, p, oob []byte, to Sockaddr, flags int) (n int, err error) {
   346  	var ptr unsafe.Pointer
   347  	var salen _Socklen
   348  	if to != nil {
   349  		ptr, salen, err = to.sockaddr()
   350  		if err != nil {
   351  			return 0, err
   352  		}
   353  	}
   354  	var msg Msghdr
   355  	msg.Name = (*byte)(unsafe.Pointer(ptr))
   356  	msg.Namelen = uint32(salen)
   357  	var iov Iovec
   358  	if len(p) > 0 {
   359  		iov.Base = (*byte)(unsafe.Pointer(&p[0]))
   360  		iov.SetLen(len(p))
   361  	}
   362  	var dummy byte
   363  	if len(oob) > 0 {
   364  		var sockType int
   365  		sockType, err = GetsockoptInt(fd, SOL_SOCKET, SO_TYPE)
   366  		if err != nil {
   367  			return 0, err
   368  		}
   369  		// send at least one normal byte
   370  		if sockType != SOCK_DGRAM && len(p) == 0 {
   371  			iov.Base = &dummy
   372  			iov.SetLen(1)
   373  		}
   374  		msg.Control = (*byte)(unsafe.Pointer(&oob[0]))
   375  		msg.SetControllen(len(oob))
   376  	}
   377  	msg.Iov = &iov
   378  	msg.Iovlen = 1
   379  	if n, err = sendmsg(fd, &msg, flags); err != nil {
   380  		return 0, err
   381  	}
   382  	if len(oob) > 0 && len(p) == 0 {
   383  		n = 0
   384  	}
   385  	return n, nil
   386  }
   387  
   388  func (sa *RawSockaddrUnix) getLen() (int, error) {
   389  	// Some versions of AIX have a bug in getsockname (see IV78655).
   390  	// We can't rely on sa.Len being set correctly.
   391  	n := SizeofSockaddrUnix - 3 // substract leading Family, Len, terminating NUL.
   392  	for i := 0; i < n; i++ {
   393  		if sa.Path[i] == 0 {
   394  			n = i
   395  			break
   396  		}
   397  	}
   398  	return n, nil
   399  }
   400  
   401  func anyToSockaddr(rsa *RawSockaddrAny) (Sockaddr, error) {
   402  	switch rsa.Addr.Family {
   403  	case AF_UNIX:
   404  		pp := (*RawSockaddrUnix)(unsafe.Pointer(rsa))
   405  		sa := new(SockaddrUnix)
   406  		n, err := pp.getLen()
   407  		if err != nil {
   408  			return nil, err
   409  		}
   410  		bytes := (*[len(pp.Path)]byte)(unsafe.Pointer(&pp.Path[0]))
   411  		sa.Name = string(bytes[0:n])
   412  		return sa, nil
   413  
   414  	case AF_INET:
   415  		pp := (*RawSockaddrInet4)(unsafe.Pointer(rsa))
   416  		sa := new(SockaddrInet4)
   417  		p := (*[2]byte)(unsafe.Pointer(&pp.Port))
   418  		sa.Port = int(p[0])<<8 + int(p[1])
   419  		for i := 0; i < len(sa.Addr); i++ {
   420  			sa.Addr[i] = pp.Addr[i]
   421  		}
   422  		return sa, nil
   423  
   424  	case AF_INET6:
   425  		pp := (*RawSockaddrInet6)(unsafe.Pointer(rsa))
   426  		sa := new(SockaddrInet6)
   427  		p := (*[2]byte)(unsafe.Pointer(&pp.Port))
   428  		sa.Port = int(p[0])<<8 + int(p[1])
   429  		for i := 0; i < len(sa.Addr); i++ {
   430  			sa.Addr[i] = pp.Addr[i]
   431  		}
   432  		return sa, nil
   433  	}
   434  	return nil, EAFNOSUPPORT
   435  }
   436  
   437  /*
   438   * Wait
   439   */
   440  
   441  type WaitStatus uint32
   442  
   443  func (w WaitStatus) Stopped() bool { return w&0x40 != 0 }
   444  func (w WaitStatus) StopSignal() Signal {
   445  	if !w.Stopped() {
   446  		return -1
   447  	}
   448  	return Signal(w>>8) & 0xFF
   449  }
   450  
   451  func (w WaitStatus) Exited() bool { return w&0xFF == 0 }
   452  func (w WaitStatus) ExitStatus() int {
   453  	if !w.Exited() {
   454  		return -1
   455  	}
   456  	return int((w >> 8) & 0xFF)
   457  }
   458  
   459  func (w WaitStatus) Signaled() bool { return w&0x40 == 0 && w&0xFF != 0 }
   460  func (w WaitStatus) Signal() Signal {
   461  	if !w.Signaled() {
   462  		return -1
   463  	}
   464  	return Signal(w>>16) & 0xFF
   465  }
   466  
   467  func (w WaitStatus) Continued() bool { return w&0x01000000 != 0 }
   468  
   469  func (w WaitStatus) CoreDump() bool { return w&0x200 == 0 }
   470  
   471  func (w WaitStatus) TrapCause() int { return -1 }
   472  
   473  /*
   474   * ptrace
   475   */
   476  
   477  //sys	Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error)
   478  //sys	ptrace64(request int, id int64, addr int64, data int, buff uintptr) (err error)
   479  
   480  func raw_ptrace(request int, pid int, addr *byte, data *byte) Errno {
   481  	if request == PTRACE_TRACEME {
   482  		// Convert to AIX ptrace call.
   483  		err := ptrace64(PT_TRACE_ME, 0, 0, 0, 0)
   484  		if err != nil {
   485  			return err.(Errno)
   486  		}
   487  		return 0
   488  	}
   489  	return ENOSYS
   490  }
   491  
   492  func ptracePeek(pid int, addr uintptr, out []byte) (count int, err error) {
   493  	n := 0
   494  	for len(out) > 0 {
   495  		bsize := len(out)
   496  		if bsize > 1024 {
   497  			bsize = 1024
   498  		}
   499  		err = ptrace64(PT_READ_BLOCK, int64(pid), int64(addr), bsize, uintptr(unsafe.Pointer(&out[0])))
   500  		if err != nil {
   501  			return 0, err
   502  		}
   503  		addr += uintptr(bsize)
   504  		n += bsize
   505  		out = out[n:]
   506  	}
   507  	return n, nil
   508  }
   509  
   510  func PtracePeekText(pid int, addr uintptr, out []byte) (count int, err error) {
   511  	return ptracePeek(pid, addr, out)
   512  }
   513  
   514  func PtracePeekData(pid int, addr uintptr, out []byte) (count int, err error) {
   515  	return ptracePeek(pid, addr, out)
   516  }
   517  
   518  func ptracePoke(pid int, addr uintptr, data []byte) (count int, err error) {
   519  	n := 0
   520  	for len(data) > 0 {
   521  		bsize := len(data)
   522  		if bsize > 1024 {
   523  			bsize = 1024
   524  		}
   525  		err = ptrace64(PT_WRITE_BLOCK, int64(pid), int64(addr), bsize, uintptr(unsafe.Pointer(&data[0])))
   526  		if err != nil {
   527  			return 0, err
   528  		}
   529  		addr += uintptr(bsize)
   530  		n += bsize
   531  		data = data[n:]
   532  	}
   533  	return n, nil
   534  }
   535  
   536  func PtracePokeText(pid int, addr uintptr, data []byte) (count int, err error) {
   537  	return ptracePoke(pid, addr, data)
   538  }
   539  
   540  func PtracePokeData(pid int, addr uintptr, data []byte) (count int, err error) {
   541  	return ptracePoke(pid, addr, data)
   542  }
   543  
   544  func PtraceCont(pid int, signal int) (err error) {
   545  	return ptrace64(PT_CONTINUE, int64(pid), 1, signal, 0)
   546  }
   547  
   548  func PtraceSingleStep(pid int) (err error) { return ptrace64(PT_STEP, int64(pid), 1, 0, 0) }
   549  
   550  func PtraceAttach(pid int) (err error) { return ptrace64(PT_ATTACH, int64(pid), 0, 0, 0) }
   551  
   552  func PtraceDetach(pid int) (err error) { return ptrace64(PT_DETACH, int64(pid), 0, 0, 0) }
   553  
   554  /*
   555   * Direct access
   556   */
   557  
   558  //sys	Acct(path string) (err error)
   559  //sys	Chdir(path string) (err error)
   560  //sys	Chmod(path string, mode uint32) (err error)
   561  //sys	Chown(path string, uid int, gid int) (err error)
   562  //sys	Close(fd int) (err error)
   563  //sys	Dup(fd int) (nfd int, err error)
   564  //sys	Faccessat(dirfd int, path string, mode uint32, flags int) (err error)
   565  //sys	Fchdir(fd int) (err error)
   566  //sys	Fchmod(fd int, mode uint32) (err error)
   567  //sys	Fchmodat(dirfd int, path string, mode uint32, flags int) (err error)
   568  //sys	Fchown(fd int, uid int, gid int) (err error)
   569  //sys	Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error)
   570  //sys	Fpathconf(fd int, name int) (val int, err error)
   571  //sys	Fstat(fd int, stat *Stat_t) (err error)
   572  //sys	Fstatfs(fd int, buf *Statfs_t) (err error)
   573  //sys	Ftruncate(fd int, length int64) (err error)
   574  //sys	Fsync(fd int) (err error)
   575  //sysnb	Getgid() (gid int)
   576  //sysnb	Getpid() (pid int)
   577  //sys	Geteuid() (euid int)
   578  //sys	Getegid() (egid int)
   579  //sys	Getppid() (ppid int)
   580  //sysnb	Getrlimit(which int, lim *Rlimit) (err error)
   581  //sysnb	Getuid() (uid int)
   582  //sys	Kill(pid int, signum Signal) (err error)
   583  //sys	Lchown(path string, uid int, gid int) (err error)
   584  //sys	Link(path string, link string) (err error)
   585  //sys	Lstat(path string, stat *Stat_t) (err error)
   586  //sys	Mkdir(path string, mode uint32) (err error)
   587  //sys	Mkdirat(dirfd int, path string, mode uint32) (err error)
   588  //sys	Mknodat(dirfd int, path string, mode uint32, dev int) (err error)
   589  //sys	Open(path string, mode int, perm uint32) (fd int, err error)
   590  //sys	Pread(fd int, p []byte, offset int64) (n int, err error)
   591  //sys	Pwrite(fd int, p []byte, offset int64) (n int, err error)
   592  //sys	read(fd int, p []byte) (n int, err error)
   593  //sys	Reboot(how int) (err error)
   594  //sys	Rename(from string, to string) (err error)
   595  //sys	Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error)
   596  //sys	Rmdir(path string) (err error)
   597  //sys	Seek(fd int, offset int64, whence int) (newoffset int64, err error) = lseek
   598  //sysnb	Setegid(egid int) (err error)
   599  //sysnb	Seteuid(euid int) (err error)
   600  //sysnb	Setgid(gid int) (err error)
   601  //sysnb	Setpgid(pid int, pgid int) (err error)
   602  //sysnb	Setregid(rgid int, egid int) (err error)
   603  //sysnb	Setreuid(ruid int, euid int) (err error)
   604  //sys	Stat(path string, stat *Stat_t) (err error)
   605  //sys	Statfs(path string, buf *Statfs_t) (err error)
   606  //sys	Symlink(path string, link string) (err error)
   607  //sys	Truncate(path string, length int64) (err error)
   608  //sys	Umask(newmask int) (oldmask int)
   609  //sys	Unlink(path string) (err error)
   610  //sysnb	Uname(buf *Utsname) (err error)
   611  //sys	write(fd int, p []byte) (n int, err error)
   612  
   613  //sys	gettimeofday(tv *Timeval, tzp *Timezone) (err error)
   614  
   615  func setTimespec(sec, nsec int64) Timespec {
   616  	return Timespec{Sec: sec, Nsec: nsec}
   617  }
   618  
   619  func setTimeval(sec, usec int64) Timeval {
   620  	return Timeval{Sec: sec, Usec: int32(usec)}
   621  }
   622  
   623  func readlen(fd int, buf *byte, nbuf int) (n int, err error) {
   624  	r0, _, e1 := syscall6(uintptr(unsafe.Pointer(&libc_read)), 3, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf), 0, 0, 0)
   625  	n = int(r0)
   626  	if e1 != 0 {
   627  		err = e1
   628  	}
   629  	return
   630  }
   631  
   632  /*
   633   * Map
   634   */
   635  
   636  var mapper = &mmapper{
   637  	active: make(map[*byte][]byte),
   638  	mmap:   mmap,
   639  	munmap: munmap,
   640  }
   641  
   642  //sys	mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error)
   643  //sys	munmap(addr uintptr, length uintptr) (err error)
   644  
   645  func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) {
   646  	return mapper.Mmap(fd, offset, length, prot, flags)
   647  }
   648  
   649  func Munmap(b []byte) (err error) {
   650  	return mapper.Munmap(b)
   651  }
   652  

View as plain text