Skip to content

Commit d099546

Browse files
committed
fix access control
1 parent 0762f57 commit d099546

File tree

3 files changed

+22
-28
lines changed

3 files changed

+22
-28
lines changed

Sources/System/AsyncFileDescriptor.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
@_implementationOnly import CSystem
22

3-
public class AsyncFileDescriptor {
4-
var open: Bool = true
3+
4+
public final class AsyncFileDescriptor {
5+
@usableFromInline var open: Bool = true
56
@usableFromInline let fileSlot: IORingFileSlot
67
@usableFromInline let ring: ManagedIORing
78

8-
static func openat(
9-
atDirectory: FileDescriptor = FileDescriptor(rawValue: AT_FDCWD),
9+
public static func openat(
10+
atDirectory: FileDescriptor = FileDescriptor(rawValue: -100),
1011
path: FilePath,
1112
_ mode: FileDescriptor.AccessMode,
1213
options: FileDescriptor.OpenOptions = FileDescriptor.OpenOptions(),
@@ -25,7 +26,8 @@ public class AsyncFileDescriptor {
2526
path: cstr,
2627
mode,
2728
options: options,
28-
permissions: permissions, intoSlot: fileSlot
29+
permissions: permissions,
30+
intoSlot: fileSlot
2931
))
3032
if res.result < 0 {
3133
throw Errno(rawValue: -res.result)
@@ -47,7 +49,7 @@ public class AsyncFileDescriptor {
4749
}
4850

4951
@inlinable @inline(__always) @_unsafeInheritExecutor
50-
func read(
52+
public func read(
5153
into buffer: IORequest.Buffer,
5254
atAbsoluteOffset offset: UInt64 = UInt64.max
5355
) async throws -> UInt32 {

Sources/System/IORing.swift

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public final class IORing: @unchecked Sendable {
262262
self.ringFlags = params.flags
263263
}
264264

265-
func blockingConsumeCompletion() -> IOCompletion {
265+
public func blockingConsumeCompletion() -> IOCompletion {
266266
self.completionMutex.lock()
267267
defer { self.completionMutex.unlock() }
268268

@@ -292,7 +292,7 @@ public final class IORing: @unchecked Sendable {
292292
}
293293
}
294294

295-
func tryConsumeCompletion() -> IOCompletion? {
295+
public func tryConsumeCompletion() -> IOCompletion? {
296296
self.completionMutex.lock()
297297
defer { self.completionMutex.unlock() }
298298
return _tryConsumeCompletion()
@@ -312,8 +312,7 @@ public final class IORing: @unchecked Sendable {
312312
return nil
313313
}
314314

315-
316-
func registerFiles(count: UInt32) {
315+
public func registerFiles(count: UInt32) {
317316
guard self.registeredFiles == nil else { fatalError() }
318317
let fileBuf = UnsafeMutableBufferPointer<UInt32>.allocate(capacity: Int(count))
319318
fileBuf.initialize(repeating: UInt32.max)
@@ -327,16 +326,15 @@ public final class IORing: @unchecked Sendable {
327326
self.registeredFiles = ResourceManager(fileBuf)
328327
}
329328

330-
func unregisterFiles() {
329+
public func unregisterFiles() {
331330
fatalError("failed to unregister files")
332331
}
333332

334-
func getFile() -> IORingFileSlot? {
333+
public func getFile() -> IORingFileSlot? {
335334
return self.registeredFiles?.getResource()
336335
}
337336

338-
// register a group of buffers
339-
func registerBuffers(bufSize: UInt32, count: UInt32) {
337+
public func registerBuffers(bufSize: UInt32, count: UInt32) {
340338
let iovecs = UnsafeMutableBufferPointer<iovec>.allocate(capacity: Int(count))
341339
let intBufSize = Int(bufSize)
342340
for i in 0..<iovecs.count {
@@ -355,22 +353,21 @@ public final class IORing: @unchecked Sendable {
355353
self.registeredBuffers = ResourceManager(iovecs)
356354
}
357355

358-
func getBuffer() -> IORingBuffer? {
356+
public func getBuffer() -> IORingBuffer? {
359357
return self.registeredBuffers?.getResource()
360358
}
361359

362-
func unregisterBuffers() {
360+
public func unregisterBuffers() {
363361
fatalError("failed to unregister buffers: TODO")
364362
}
365363

366-
// TODO: types
367-
func submitRequests() {
364+
public func submitRequests() {
368365
self.submissionMutex.lock()
369366
defer { self.submissionMutex.unlock() }
370367
self._submitRequests()
371368
}
372369

373-
func _submitRequests() {
370+
internal func _submitRequests() {
374371
let flushedEvents = _flushQueue()
375372

376373
// Ring always needs enter right now;
@@ -389,6 +386,8 @@ public final class IORing: @unchecked Sendable {
389386
fatalError("fatal error in submitting requests: " +
390387
Errno(rawValue: -ret).debugDescription
391388
)
389+
} else {
390+
break
392391
}
393392
}
394393
}
@@ -403,14 +402,7 @@ public final class IORing: @unchecked Sendable {
403402

404403

405404
@inlinable @inline(__always)
406-
func writeRequest(_ request: __owned IORequest) -> Bool {
407-
self.submissionMutex.lock()
408-
defer { self.submissionMutex.unlock() }
409-
return _writeRequest(request.makeRawRequest())
410-
}
411-
412-
@inlinable @inline(__always)
413-
func writeAndSubmit(_ request: __owned IORequest) -> Bool {
405+
public func writeRequest(_ request: __owned IORequest) -> Bool {
414406
self.submissionMutex.lock()
415407
defer { self.submissionMutex.unlock() }
416408
return _writeRequest(request.makeRawRequest())

Sources/System/ManagedIORing.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
final public class ManagedIORing: @unchecked Sendable {
22
var internalRing: IORing
33

4-
init(queueDepth: UInt32) throws {
4+
public init(queueDepth: UInt32) throws {
55
self.internalRing = try IORing(queueDepth: queueDepth)
66
self.internalRing.registerBuffers(bufSize: 655336, count: 4)
77
self.internalRing.registerFiles(count: 32)

0 commit comments

Comments
 (0)