github.com/ii64/gouring@v0.4.1/syscall.go (about)

     1  package gouring
     2  
     3  import (
     4  	"syscall"
     5  	"unsafe"
     6  )
     7  
     8  func io_uring_setup(entries uintptr, params *IoUringParams) (ret int, err error) {
     9  	r1, _, e1 := syscall.Syscall(SYS_IO_URING_SETUP, entries, uintptr(unsafe.Pointer(params)), 0)
    10  	ret = int(r1)
    11  	if e1 < 0 {
    12  		err = e1
    13  	}
    14  	return
    15  }
    16  
    17  func io_uring_enter(fd int, toSubmit uint32, minComplete uint32, flags uint32, sig *Sigset_t) (ret int, err error) {
    18  	return io_uring_enter2(fd, toSubmit, minComplete, flags, sig, NSIG/8)
    19  }
    20  
    21  // TODO: decide to use Syscall or RawSyscall
    22  
    23  func io_uring_enter2(fd int, toSubmit uint32, minComplete uint32, flags uint32, sig *Sigset_t, sz int32) (ret int, err error) {
    24  	r1, _, e1 := syscall.Syscall6(SYS_IO_URING_ENTER,
    25  		uintptr(fd),
    26  		uintptr(toSubmit), uintptr(minComplete),
    27  		uintptr(flags), uintptr(unsafe.Pointer(sig)), uintptr(sz))
    28  	ret = int(r1)
    29  	if e1 != 0 {
    30  		err = e1
    31  	}
    32  	return
    33  }
    34  
    35  func io_uring_register(fd int, opcode uint32, arg unsafe.Pointer, nrArgs uintptr) (ret int, err error) {
    36  	r1, _, e1 := syscall.Syscall6(SYS_IO_URING_REGISTER, uintptr(fd), uintptr(opcode), uintptr(arg), uintptr(nrArgs), 0, 0)
    37  	ret = int(r1)
    38  	if e1 != 0 {
    39  		err = e1
    40  	}
    41  	return
    42  }
    43  
    44  //go:linkname mmap syscall.mmap
    45  func mmap(addr unsafe.Pointer, length uintptr, prot int, flags int, fd int, offset int64) (xaddr unsafe.Pointer, err error)
    46  
    47  //go:linkname munmap syscall.munmap
    48  func munmap(addr unsafe.Pointer, length uintptr) (err error)
    49  
    50  //
    51  
    52  func increase_rlimit_nofile(nr uint64) error {
    53  	var rlim syscall.Rlimit
    54  	err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlim)
    55  	if err != nil {
    56  		return err
    57  	}
    58  	if rlim.Cur < nr {
    59  		rlim.Cur += nr
    60  		err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim)
    61  	}
    62  	return err
    63  }