IORing+Util.swift 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. This source file is part of the Swift System open source project
  3. Copyright (c) 2026 Apple Inc. and the Swift System project authors
  4. Licensed under Apache License v2.0 with Runtime Library Exception
  5. See https://swift.org/LICENSE.txt for license information
  6. */
  7. #if compiler(>=6.2) && $Lifetimes
  8. #if os(Linux)
  9. import CSystem
  10. #if canImport(Glibc)
  11. import Glibc
  12. #elseif canImport(Musl)
  13. import Musl
  14. #endif
  15. /// Throwing wrapper around the `io_uring_enter2` shim.
  16. ///
  17. /// On success returns the syscall's non-negative result (the number of SQEs
  18. /// consumed by the kernel). On failure, reads `errno` and throws the matching
  19. /// `Errno`. `EINTR` is retried automatically.
  20. @usableFromInline
  21. internal func _ioUringEnter2(
  22. ringDescriptor: Int32,
  23. toSubmit: UInt32,
  24. minComplete: UInt32,
  25. flags: UInt32,
  26. args: UnsafeMutablePointer<swift_io_uring_getevents_arg>?,
  27. argsSize: Int
  28. ) throws(Errno) -> Int32 {
  29. let result = valueOrErrno(retryOnInterrupt: true) {
  30. io_uring_enter2(
  31. ringDescriptor, toSubmit, minComplete, flags, args, argsSize
  32. )
  33. }
  34. return try result.get()
  35. }
  36. /// Throwing wrapper around the `io_uring_enter` shim.
  37. ///
  38. /// On success returns the syscall's non-negative result (the number of SQEs
  39. /// consumed by the kernel). On failure, reads `errno` and throws the matching
  40. /// `Errno`. `EINTR` is retried automatically.
  41. @usableFromInline
  42. internal func _ioUringEnter(
  43. ringDescriptor: Int32,
  44. toSubmit: UInt32,
  45. minComplete: UInt32,
  46. flags: UInt32,
  47. sig: UnsafeMutablePointer<sigset_t>?
  48. ) throws(Errno) -> Int32 {
  49. let result = valueOrErrno(retryOnInterrupt: true) {
  50. io_uring_enter(ringDescriptor, toSubmit, minComplete, flags, sig)
  51. }
  52. return try result.get()
  53. }
  54. /// Throwing wrapper around the `io_uring_register` shim.
  55. ///
  56. /// On success returns the syscall's non-negative result. On failure, reads
  57. /// `errno` and throws the matching `Errno`. `EINTR` is retried automatically.
  58. @usableFromInline
  59. internal func _ioUringRegister(
  60. ringDescriptor: Int32,
  61. opcode: UInt32,
  62. arg: UnsafeMutableRawPointer?,
  63. nrArgs: UInt32
  64. ) throws(Errno) -> Int32 {
  65. let result = valueOrErrno(retryOnInterrupt: true) {
  66. io_uring_register(ringDescriptor, opcode, arg, nrArgs)
  67. }
  68. return try result.get()
  69. }
  70. #endif // os(Linux)
  71. #endif // compiler(>=6.2) && $Lifetimes