mirror of
https://github.com/apple/swift-system
synced 2026-11-25 04:47:55 +00:00
81 lines
2.3 KiB
Swift
81 lines
2.3 KiB
Swift
/*
|
|
This source file is part of the Swift System open source project
|
|
|
|
Copyright (c) 2026 Apple Inc. and the Swift System project authors
|
|
Licensed under Apache License v2.0 with Runtime Library Exception
|
|
|
|
See https://swift.org/LICENSE.txt for license information
|
|
*/
|
|
|
|
#if compiler(>=6.2) && $Lifetimes
|
|
#if os(Linux)
|
|
|
|
internal import CSystem
|
|
public import CSystemIOUring
|
|
#if canImport(Glibc)
|
|
import Glibc
|
|
#elseif canImport(Musl)
|
|
import Musl
|
|
#endif
|
|
|
|
/// Throwing wrapper around the `csystem_io_uring_enter2` shim.
|
|
///
|
|
/// On success returns the syscall's non-negative result (the number of SQEs
|
|
/// consumed by the kernel). On failure, reads `errno` and throws the matching
|
|
/// `Errno`. `EINTR` is retried automatically.
|
|
@usableFromInline
|
|
internal func _ioUringEnter2(
|
|
ringDescriptor: Int32,
|
|
toSubmit: UInt32,
|
|
minComplete: UInt32,
|
|
flags: UInt32,
|
|
args: UnsafeMutablePointer<swift_io_uring_getevents_arg>?,
|
|
argsSize: Int
|
|
) throws(Errno) -> Int32 {
|
|
let result = valueOrErrno(retryOnInterrupt: true) {
|
|
csystem_io_uring_enter2(
|
|
ringDescriptor, toSubmit, minComplete, flags, args, argsSize
|
|
)
|
|
}
|
|
return try result.get()
|
|
}
|
|
|
|
/// Throwing wrapper around the `csystem_io_uring_enter` shim.
|
|
///
|
|
/// On success returns the syscall's non-negative result (the number of SQEs
|
|
/// consumed by the kernel). On failure, reads `errno` and throws the matching
|
|
/// `Errno`. `EINTR` is retried automatically.
|
|
@usableFromInline
|
|
internal func _ioUringEnter(
|
|
ringDescriptor: Int32,
|
|
toSubmit: UInt32,
|
|
minComplete: UInt32,
|
|
flags: UInt32,
|
|
sig: UnsafeMutablePointer<sigset_t>?
|
|
) throws(Errno) -> Int32 {
|
|
let result = valueOrErrno(retryOnInterrupt: true) {
|
|
csystem_io_uring_enter(ringDescriptor, toSubmit, minComplete, flags, sig)
|
|
}
|
|
return try result.get()
|
|
}
|
|
|
|
/// Throwing wrapper around the `csystem_io_uring_register` shim.
|
|
///
|
|
/// On success returns the syscall's non-negative result. On failure, reads
|
|
/// `errno` and throws the matching `Errno`. `EINTR` is retried automatically.
|
|
@usableFromInline
|
|
internal func _ioUringRegister(
|
|
ringDescriptor: Int32,
|
|
opcode: UInt32,
|
|
arg: UnsafeMutableRawPointer?,
|
|
nrArgs: UInt32
|
|
) throws(Errno) -> Int32 {
|
|
let result = valueOrErrno(retryOnInterrupt: true) {
|
|
csystem_io_uring_register(ringDescriptor, opcode, arg, nrArgs)
|
|
}
|
|
return try result.get()
|
|
}
|
|
|
|
#endif // os(Linux)
|
|
#endif // compiler(>=6.2) && $Lifetimes
|