Source file src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_ppc.go

     1  // Copyright 2021 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  //go:build linux && ppc
     6  
     7  package unix
     8  
     9  import (
    10  	"syscall"
    11  	"unsafe"
    12  )
    13  
    14  //sys	EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error)
    15  //sys	Fchown(fd int, uid int, gid int) (err error)
    16  //sys	Fstat(fd int, stat *Stat_t) (err error) = SYS_FSTAT64
    17  //sys	Fstatat(dirfd int, path string, stat *Stat_t, flags int) (err error) = SYS_FSTATAT64
    18  //sys	Ftruncate(fd int, length int64) (err error) = SYS_FTRUNCATE64
    19  //sysnb	Getegid() (egid int)
    20  //sysnb	Geteuid() (euid int)
    21  //sysnb	Getgid() (gid int)
    22  //sysnb	Getuid() (uid int)
    23  //sys	Ioperm(from int, num int, on int) (err error)
    24  //sys	Iopl(level int) (err error)
    25  //sys	Lchown(path string, uid int, gid int) (err error)
    26  //sys	Listen(s int, n int) (err error)
    27  //sys	Lstat(path string, stat *Stat_t) (err error) = SYS_LSTAT64
    28  //sys	Pause() (err error)
    29  //sys	pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64
    30  //sys	pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64
    31  //sys	Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error)
    32  //sys	Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) = SYS__NEWSELECT
    33  //sys	sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) = SYS_SENDFILE64
    34  //sys	setfsgid(gid int) (prev int, err error)
    35  //sys	setfsuid(uid int) (prev int, err error)
    36  //sys	Shutdown(fd int, how int) (err error)
    37  //sys	Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int, err error)
    38  //sys	Stat(path string, stat *Stat_t) (err error) = SYS_STAT64
    39  //sys	Truncate(path string, length int64) (err error) = SYS_TRUNCATE64
    40  //sys	Ustat(dev int, ubuf *Ustat_t) (err error)
    41  //sys	accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
    42  //sys	bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
    43  //sys	connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
    44  //sysnb	getgroups(n int, list *_Gid_t) (nn int, err error)
    45  //sysnb	setgroups(n int, list *_Gid_t) (err error)
    46  //sys	getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error)
    47  //sys	setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error)
    48  //sysnb	socket(domain int, typ int, proto int) (fd int, err error)
    49  //sysnb	socketpair(domain int, typ int, proto int, fd *[2]int32) (err error)
    50  //sysnb	getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
    51  //sysnb	getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
    52  //sys	recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error)
    53  //sys	sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error)
    54  //sys	recvmsg(s int, msg *Msghdr, flags int) (n int, err error)
    55  //sys	sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
    56  
    57  //sys	futimesat(dirfd int, path string, times *[2]Timeval) (err error)
    58  //sysnb	Gettimeofday(tv *Timeval) (err error)
    59  //sysnb	Time(t *Time_t) (tt Time_t, err error)
    60  //sys	Utime(path string, buf *Utimbuf) (err error)
    61  //sys	utimes(path string, times *[2]Timeval) (err error)
    62  
    63  func Fadvise(fd int, offset int64, length int64, advice int) (err error) {
    64  	_, _, e1 := Syscall6(SYS_FADVISE64_64, uintptr(fd), uintptr(advice), uintptr(offset>>32), uintptr(offset), uintptr(length>>32), uintptr(length))
    65  	if e1 != 0 {
    66  		err = errnoErr(e1)
    67  	}
    68  	return
    69  }
    70  
    71  func seek(fd int, offset int64, whence int) (int64, syscall.Errno) {
    72  	var newoffset int64
    73  	offsetLow := uint32(offset & 0xffffffff)
    74  	offsetHigh := uint32((offset >> 32) & 0xffffffff)
    75  	_, _, err := Syscall6(SYS__LLSEEK, uintptr(fd), uintptr(offsetHigh), uintptr(offsetLow), uintptr(unsafe.Pointer(&newoffset)), uintptr(whence), 0)
    76  	return newoffset, err
    77  }
    78  
    79  func Seek(fd int, offset int64, whence int) (newoffset int64, err error) {
    80  	newoffset, errno := seek(fd, offset, whence)
    81  	if errno != 0 {
    82  		return 0, errno
    83  	}
    84  	return newoffset, nil
    85  }
    86  
    87  func Fstatfs(fd int, buf *Statfs_t) (err error) {
    88  	_, _, e := Syscall(SYS_FSTATFS64, uintptr(fd), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf)))
    89  	if e != 0 {
    90  		err = e
    91  	}
    92  	return
    93  }
    94  
    95  func Statfs(path string, buf *Statfs_t) (err error) {
    96  	pathp, err := BytePtrFromString(path)
    97  	if err != nil {
    98  		return err
    99  	}
   100  	_, _, e := Syscall(SYS_STATFS64, uintptr(unsafe.Pointer(pathp)), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf)))
   101  	if e != 0 {
   102  		err = e
   103  	}
   104  	return
   105  }
   106  
   107  //sys	mmap2(addr uintptr, length uintptr, prot int, flags int, fd int, pageOffset uintptr) (xaddr uintptr, err error)
   108  
   109  func mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) {
   110  	page := uintptr(offset / 4096)
   111  	if offset != int64(page)*4096 {
   112  		return 0, EINVAL
   113  	}
   114  	return mmap2(addr, length, prot, flags, fd, page)
   115  }
   116  
   117  func setTimespec(sec, nsec int64) Timespec {
   118  	return Timespec{Sec: int32(sec), Nsec: int32(nsec)}
   119  }
   120  
   121  func setTimeval(sec, usec int64) Timeval {
   122  	return Timeval{Sec: int32(sec), Usec: int32(usec)}
   123  }
   124  
   125  type rlimit32 struct {
   126  	Cur uint32
   127  	Max uint32
   128  }
   129  
   130  //sysnb	getrlimit(resource int, rlim *rlimit32) (err error) = SYS_UGETRLIMIT
   131  
   132  const rlimInf32 = ^uint32(0)
   133  const rlimInf64 = ^uint64(0)
   134  
   135  func Getrlimit(resource int, rlim *Rlimit) (err error) {
   136  	err = Prlimit(0, resource, nil, rlim)
   137  	if err != ENOSYS {
   138  		return err
   139  	}
   140  
   141  	rl := rlimit32{}
   142  	err = getrlimit(resource, &rl)
   143  	if err != nil {
   144  		return
   145  	}
   146  
   147  	if rl.Cur == rlimInf32 {
   148  		rlim.Cur = rlimInf64
   149  	} else {
   150  		rlim.Cur = uint64(rl.Cur)
   151  	}
   152  
   153  	if rl.Max == rlimInf32 {
   154  		rlim.Max = rlimInf64
   155  	} else {
   156  		rlim.Max = uint64(rl.Max)
   157  	}
   158  	return
   159  }
   160  
   161  func (r *PtraceRegs) PC() uint32 { return r.Nip }
   162  
   163  func (r *PtraceRegs) SetPC(pc uint32) { r.Nip = pc }
   164  
   165  func (iov *Iovec) SetLen(length int) {
   166  	iov.Len = uint32(length)
   167  }
   168  
   169  func (msghdr *Msghdr) SetControllen(length int) {
   170  	msghdr.Controllen = uint32(length)
   171  }
   172  
   173  func (msghdr *Msghdr) SetIovlen(length int) {
   174  	msghdr.Iovlen = uint32(length)
   175  }
   176  
   177  func (cmsg *Cmsghdr) SetLen(length int) {
   178  	cmsg.Len = uint32(length)
   179  }
   180  
   181  func (rsa *RawSockaddrNFCLLCP) SetServiceNameLen(length int) {
   182  	rsa.Service_name_len = uint32(length)
   183  }
   184  
   185  //sys	syncFileRange2(fd int, flags int, off int64, n int64) (err error) = SYS_SYNC_FILE_RANGE2
   186  
   187  func SyncFileRange(fd int, off int64, n int64, flags int) error {
   188  	// The sync_file_range and sync_file_range2 syscalls differ only in the
   189  	// order of their arguments.
   190  	return syncFileRange2(fd, flags, off, n)
   191  }
   192  
   193  //sys	kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, flags int) (err error)
   194  
   195  func KexecFileLoad(kernelFd int, initrdFd int, cmdline string, flags int) error {
   196  	cmdlineLen := len(cmdline)
   197  	if cmdlineLen > 0 {
   198  		// Account for the additional NULL byte added by
   199  		// BytePtrFromString in kexecFileLoad. The kexec_file_load
   200  		// syscall expects a NULL-terminated string.
   201  		cmdlineLen++
   202  	}
   203  	return kexecFileLoad(kernelFd, initrdFd, cmdlineLen, cmdline, flags)
   204  }
   205  

View as plain text