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

View as plain text