Source file src/syscall/syscall_linux_loong64.go

     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  package syscall
     6  
     7  import "unsafe"
     8  
     9  const (
    10  	_SYS_setgroups  = SYS_SETGROUPS
    11  	_SYS_clone3     = 435
    12  	_SYS_faccessat2 = 439
    13  	_SYS_fchmodat2  = 452
    14  )
    15  
    16  //sys	EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) = SYS_EPOLL_PWAIT
    17  //sys	Fchown(fd int, uid int, gid int) (err error)
    18  //sys	Fstatfs(fd int, buf *Statfs_t) (err error)
    19  //sys	Ftruncate(fd int, length int64) (err error)
    20  //sysnb	Getegid() (egid int)
    21  //sysnb	Geteuid() (euid int)
    22  //sysnb	Getgid() (gid int)
    23  //sysnb	Getuid() (uid int)
    24  //sys	Listen(s int, n int) (err error)
    25  //sys	pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64
    26  //sys	pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64
    27  //sys	Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) = SYS_RENAMEAT2
    28  //sys	Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK
    29  //sys	sendfile(outfd int, infd int, offset *int64, count int) (written int, err error)
    30  //sys	Setfsgid(gid int) (err error)
    31  //sys	Setfsuid(uid int) (err error)
    32  //sys	Shutdown(fd int, how int) (err error)
    33  //sys	Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error)
    34  //sys	statx(dirfd int, path string, flags int, mask int, stat *statx_t) (err error)
    35  
    36  // makedev makes C dev_t from major and minor numbers the glibc way:
    37  // 0xMMMM_MMMM 0xmmmm_mmmm -> 0xMMMM_Mmmm_mmmM_MMmm
    38  func makedev(major uint32, minor uint32) uint64 {
    39  	majorH := uint64(major >> 12)
    40  	majorL := uint64(major & 0xfff)
    41  	minorH := uint64(minor >> 8)
    42  	minorL := uint64(minor & 0xff)
    43  	return (majorH << 44) | (minorH << 20) | (majorL << 8) | minorL
    44  }
    45  
    46  func timespecFromStatxTimestamp(x statxTimestamp) Timespec {
    47  	return Timespec{
    48  		Sec:  x.Sec,
    49  		Nsec: int64(x.Nsec),
    50  	}
    51  }
    52  
    53  func fstatat(dirfd int, path string, stat *Stat_t, flags int) (err error) {
    54  	var r statx_t
    55  	// Do it the glibc way, add AT_NO_AUTOMOUNT.
    56  	if err = statx(dirfd, path, _AT_NO_AUTOMOUNT|flags, _STATX_BASIC_STATS, &r); err != nil {
    57  		return err
    58  	}
    59  
    60  	stat.Dev = makedev(r.Dev_major, r.Dev_minor)
    61  	stat.Ino = r.Ino
    62  	stat.Mode = uint32(r.Mode)
    63  	stat.Nlink = r.Nlink
    64  	stat.Uid = r.Uid
    65  	stat.Gid = r.Gid
    66  	stat.Rdev = makedev(r.Rdev_major, r.Rdev_minor)
    67  	// hope we don't get to process files so large to overflow these size
    68  	// fields...
    69  	stat.Size = int64(r.Size)
    70  	stat.Blksize = int32(r.Blksize)
    71  	stat.Blocks = int64(r.Blocks)
    72  	stat.Atim = timespecFromStatxTimestamp(r.Atime)
    73  	stat.Mtim = timespecFromStatxTimestamp(r.Mtime)
    74  	stat.Ctim = timespecFromStatxTimestamp(r.Ctime)
    75  
    76  	return nil
    77  }
    78  
    79  func Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) {
    80  	return fstatat(fd, path, stat, flags)
    81  }
    82  
    83  func Fstat(fd int, stat *Stat_t) (err error) {
    84  	return fstatat(fd, "", stat, _AT_EMPTY_PATH)
    85  }
    86  
    87  func Stat(path string, stat *Stat_t) (err error) {
    88  	return fstatat(_AT_FDCWD, path, stat, 0)
    89  }
    90  
    91  func Lchown(path string, uid int, gid int) (err error) {
    92  	return Fchownat(_AT_FDCWD, path, uid, gid, _AT_SYMLINK_NOFOLLOW)
    93  }
    94  
    95  func Lstat(path string, stat *Stat_t) (err error) {
    96  	return fstatat(_AT_FDCWD, path, stat, _AT_SYMLINK_NOFOLLOW)
    97  }
    98  
    99  //sys	Statfs(path string, buf *Statfs_t) (err error)
   100  //sys	SyncFileRange(fd int, off int64, n int64, flags int) (err error)
   101  //sys	Truncate(path string, length int64) (err error)
   102  //sys	accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
   103  //sys	bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
   104  //sys	connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
   105  //sysnb	getgroups(n int, list *_Gid_t) (nn int, err error)
   106  //sys	getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error)
   107  //sys	setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error)
   108  //sysnb	socket(domain int, typ int, proto int) (fd int, err error)
   109  //sysnb	socketpair(domain int, typ int, proto int, fd *[2]int32) (err error)
   110  //sysnb	getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
   111  //sysnb	getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
   112  //sys	recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error)
   113  //sys	sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error)
   114  //sys	recvmsg(s int, msg *Msghdr, flags int) (n int, err error)
   115  //sys	sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
   116  //sys	mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)
   117  
   118  type sigset_t struct {
   119  	X__val [16]uint64
   120  }
   121  
   122  //sys	pselect(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timespec, sigmask *sigset_t) (n int, err error) = SYS_PSELECT6
   123  
   124  func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) {
   125  	var ts *Timespec
   126  	if timeout != nil {
   127  		ts = &Timespec{Sec: timeout.Sec, Nsec: timeout.Usec * 1000}
   128  	}
   129  	return pselect(nfd, r, w, e, ts, nil)
   130  }
   131  
   132  //sysnb	Gettimeofday(tv *Timeval) (err error)
   133  
   134  func setTimespec(sec, nsec int64) Timespec {
   135  	return Timespec{Sec: sec, Nsec: nsec}
   136  }
   137  
   138  func setTimeval(sec, usec int64) Timeval {
   139  	return Timeval{Sec: sec, Usec: usec}
   140  }
   141  
   142  func futimesat(dirfd int, path string, tv *[2]Timeval) (err error) {
   143  	if tv == nil {
   144  		return utimensat(dirfd, path, nil, 0)
   145  	}
   146  
   147  	ts := []Timespec{
   148  		NsecToTimespec(TimevalToNsec(tv[0])),
   149  		NsecToTimespec(TimevalToNsec(tv[1])),
   150  	}
   151  	return utimensat(dirfd, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
   152  }
   153  
   154  func Time(t *Time_t) (Time_t, error) {
   155  	var tv Timeval
   156  	err := Gettimeofday(&tv)
   157  	if err != nil {
   158  		return 0, err
   159  	}
   160  	if t != nil {
   161  		*t = Time_t(tv.Sec)
   162  	}
   163  	return Time_t(tv.Sec), nil
   164  }
   165  
   166  func Utime(path string, buf *Utimbuf) error {
   167  	tv := []Timeval{
   168  		{Sec: buf.Actime},
   169  		{Sec: buf.Modtime},
   170  	}
   171  	return Utimes(path, tv)
   172  }
   173  
   174  func utimes(path string, tv *[2]Timeval) (err error) {
   175  	if tv == nil {
   176  		return utimensat(_AT_FDCWD, path, nil, 0)
   177  	}
   178  
   179  	ts := []Timespec{
   180  		NsecToTimespec(TimevalToNsec(tv[0])),
   181  		NsecToTimespec(TimevalToNsec(tv[1])),
   182  	}
   183  	return utimensat(_AT_FDCWD, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
   184  }
   185  
   186  // Getrlimit prefers the prlimit64 system call.
   187  func Getrlimit(resource int, rlim *Rlimit) error {
   188  	return prlimit(0, resource, nil, rlim)
   189  }
   190  
   191  // setrlimit prefers the prlimit64 system call.
   192  func setrlimit(resource int, rlim *Rlimit) error {
   193  	return prlimit(0, resource, rlim, nil)
   194  }
   195  
   196  //go:nosplit
   197  func rawSetrlimit(resource int, rlim *Rlimit) Errno {
   198  	_, _, errno := RawSyscall6(SYS_PRLIMIT64, 0, uintptr(resource), uintptr(unsafe.Pointer(rlim)), 0, 0, 0)
   199  	return errno
   200  }
   201  
   202  func (r *PtraceRegs) GetEra() uint64 { return r.Era }
   203  
   204  func (r *PtraceRegs) SetEra(era uint64) { r.Era = era }
   205  
   206  func (iov *Iovec) SetLen(length int) {
   207  	iov.Len = uint64(length)
   208  }
   209  
   210  func (msghdr *Msghdr) SetControllen(length int) {
   211  	msghdr.Controllen = uint64(length)
   212  }
   213  
   214  func (cmsg *Cmsghdr) SetLen(length int) {
   215  	cmsg.Len = uint64(length)
   216  }
   217  
   218  func InotifyInit() (fd int, err error) {
   219  	return InotifyInit1(0)
   220  }
   221  
   222  //sys	ppoll(fds *pollFd, nfds int, timeout *Timespec, sigmask *sigset_t) (n int, err error)
   223  
   224  func Pause() error {
   225  	_, err := ppoll(nil, 0, nil, nil)
   226  	return err
   227  }
   228  

View as plain text