...

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

Documentation: cmd/vendor/golang.org/x/sys/unix

     1  // Copyright 2022 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 loong64 && linux
     6  
     7  package unix
     8  
     9  import "unsafe"
    10  
    11  //sys	EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) = SYS_EPOLL_PWAIT
    12  //sys	Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_FADVISE64
    13  //sys	Fchown(fd int, uid int, gid int) (err error)
    14  //sys	Fstatfs(fd int, buf *Statfs_t) (err error)
    15  //sys	Ftruncate(fd int, length int64) (err error)
    16  //sysnb	Getegid() (egid int)
    17  //sysnb	Geteuid() (euid int)
    18  //sysnb	Getgid() (gid int)
    19  //sysnb	Getuid() (uid int)
    20  //sys	Listen(s int, n int) (err error)
    21  //sys	pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64
    22  //sys	pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64
    23  //sys	Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK
    24  
    25  func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) {
    26  	var ts *Timespec
    27  	if timeout != nil {
    28  		ts = &Timespec{Sec: timeout.Sec, Nsec: timeout.Usec * 1000}
    29  	}
    30  	return pselect6(nfd, r, w, e, ts, nil)
    31  }
    32  
    33  //sys	sendfile(outfd int, infd int, offset *int64, count int) (written int, err error)
    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 int64, err error)
    38  
    39  func timespecFromStatxTimestamp(x StatxTimestamp) Timespec {
    40  	return Timespec{
    41  		Sec:  x.Sec,
    42  		Nsec: int64(x.Nsec),
    43  	}
    44  }
    45  
    46  func Fstatat(fd int, path string, stat *Stat_t, flags int) error {
    47  	var r Statx_t
    48  	// Do it the glibc way, add AT_NO_AUTOMOUNT.
    49  	if err := Statx(fd, path, AT_NO_AUTOMOUNT|flags, STATX_BASIC_STATS, &r); err != nil {
    50  		return err
    51  	}
    52  
    53  	stat.Dev = Mkdev(r.Dev_major, r.Dev_minor)
    54  	stat.Ino = r.Ino
    55  	stat.Mode = uint32(r.Mode)
    56  	stat.Nlink = r.Nlink
    57  	stat.Uid = r.Uid
    58  	stat.Gid = r.Gid
    59  	stat.Rdev = Mkdev(r.Rdev_major, r.Rdev_minor)
    60  	// hope we don't get to process files so large to overflow these size
    61  	// fields...
    62  	stat.Size = int64(r.Size)
    63  	stat.Blksize = int32(r.Blksize)
    64  	stat.Blocks = int64(r.Blocks)
    65  	stat.Atim = timespecFromStatxTimestamp(r.Atime)
    66  	stat.Mtim = timespecFromStatxTimestamp(r.Mtime)
    67  	stat.Ctim = timespecFromStatxTimestamp(r.Ctime)
    68  
    69  	return nil
    70  }
    71  
    72  func Fstat(fd int, stat *Stat_t) (err error) {
    73  	return Fstatat(fd, "", stat, AT_EMPTY_PATH)
    74  }
    75  
    76  func Stat(path string, stat *Stat_t) (err error) {
    77  	return Fstatat(AT_FDCWD, path, stat, 0)
    78  }
    79  
    80  func Lchown(path string, uid int, gid int) (err error) {
    81  	return Fchownat(AT_FDCWD, path, uid, gid, AT_SYMLINK_NOFOLLOW)
    82  }
    83  
    84  func Lstat(path string, stat *Stat_t) (err error) {
    85  	return Fstatat(AT_FDCWD, path, stat, AT_SYMLINK_NOFOLLOW)
    86  }
    87  
    88  //sys	Statfs(path string, buf *Statfs_t) (err error)
    89  //sys	SyncFileRange(fd int, off int64, n int64, flags int) (err error)
    90  //sys	Truncate(path string, length int64) (err error)
    91  
    92  func Ustat(dev int, ubuf *Ustat_t) (err error) {
    93  	return ENOSYS
    94  }
    95  
    96  //sys	accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
    97  //sys	bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
    98  //sys	connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
    99  //sysnb	getgroups(n int, list *_Gid_t) (nn int, err error)
   100  //sysnb	setgroups(n int, list *_Gid_t) (err error)
   101  //sys	getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error)
   102  //sys	setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error)
   103  //sysnb	socket(domain int, typ int, proto int) (fd int, err error)
   104  //sysnb	socketpair(domain int, typ int, proto int, fd *[2]int32) (err error)
   105  //sysnb	getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
   106  //sysnb	getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
   107  //sys	recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error)
   108  //sys	sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error)
   109  //sys	recvmsg(s int, msg *Msghdr, flags int) (n int, err error)
   110  //sys	sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
   111  //sys	mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)
   112  
   113  //sysnb	Gettimeofday(tv *Timeval) (err error)
   114  
   115  func setTimespec(sec, nsec int64) Timespec {
   116  	return Timespec{Sec: sec, Nsec: nsec}
   117  }
   118  
   119  func setTimeval(sec, usec int64) Timeval {
   120  	return Timeval{Sec: sec, Usec: usec}
   121  }
   122  
   123  func Getrlimit(resource int, rlim *Rlimit) (err error) {
   124  	err = Prlimit(0, resource, nil, rlim)
   125  	return
   126  }
   127  
   128  func futimesat(dirfd int, path string, tv *[2]Timeval) (err error) {
   129  	if tv == nil {
   130  		return utimensat(dirfd, path, nil, 0)
   131  	}
   132  
   133  	ts := []Timespec{
   134  		NsecToTimespec(TimevalToNsec(tv[0])),
   135  		NsecToTimespec(TimevalToNsec(tv[1])),
   136  	}
   137  	return utimensat(dirfd, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
   138  }
   139  
   140  func Time(t *Time_t) (Time_t, error) {
   141  	var tv Timeval
   142  	err := Gettimeofday(&tv)
   143  	if err != nil {
   144  		return 0, err
   145  	}
   146  	if t != nil {
   147  		*t = Time_t(tv.Sec)
   148  	}
   149  	return Time_t(tv.Sec), nil
   150  }
   151  
   152  func Utime(path string, buf *Utimbuf) error {
   153  	tv := []Timeval{
   154  		{Sec: buf.Actime},
   155  		{Sec: buf.Modtime},
   156  	}
   157  	return Utimes(path, tv)
   158  }
   159  
   160  func utimes(path string, tv *[2]Timeval) (err error) {
   161  	if tv == nil {
   162  		return utimensat(AT_FDCWD, path, nil, 0)
   163  	}
   164  
   165  	ts := []Timespec{
   166  		NsecToTimespec(TimevalToNsec(tv[0])),
   167  		NsecToTimespec(TimevalToNsec(tv[1])),
   168  	}
   169  	return utimensat(AT_FDCWD, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
   170  }
   171  
   172  func (r *PtraceRegs) PC() uint64 { return r.Era }
   173  
   174  func (r *PtraceRegs) SetPC(era uint64) { r.Era = era }
   175  
   176  func (iov *Iovec) SetLen(length int) {
   177  	iov.Len = uint64(length)
   178  }
   179  
   180  func (msghdr *Msghdr) SetControllen(length int) {
   181  	msghdr.Controllen = uint64(length)
   182  }
   183  
   184  func (msghdr *Msghdr) SetIovlen(length int) {
   185  	msghdr.Iovlen = uint64(length)
   186  }
   187  
   188  func (cmsg *Cmsghdr) SetLen(length int) {
   189  	cmsg.Len = uint64(length)
   190  }
   191  
   192  func (rsa *RawSockaddrNFCLLCP) SetServiceNameLen(length int) {
   193  	rsa.Service_name_len = uint64(length)
   194  }
   195  
   196  func Pause() error {
   197  	_, err := ppoll(nil, 0, nil, nil)
   198  	return err
   199  }
   200  
   201  func Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) {
   202  	return Renameat2(olddirfd, oldpath, newdirfd, newpath, 0)
   203  }
   204  
   205  //sys	kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, flags int) (err error)
   206  
   207  func KexecFileLoad(kernelFd int, initrdFd int, cmdline string, flags int) error {
   208  	cmdlineLen := len(cmdline)
   209  	if cmdlineLen > 0 {
   210  		// Account for the additional NULL byte added by
   211  		// BytePtrFromString in kexecFileLoad. The kexec_file_load
   212  		// syscall expects a NULL-terminated string.
   213  		cmdlineLen++
   214  	}
   215  	return kexecFileLoad(kernelFd, initrdFd, cmdlineLen, cmdline, flags)
   216  }
   217  

View as plain text