Skip to content

Commit 6189c1f

Browse files
committed
fix copySendRight() for send rights that become dead names
1 parent e4d06ae commit 6189c1f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Sources/System/MachPort.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ extension Mach.Port where RightType == Mach.SendRight {
309309

310310
// name is the same because send rights are coalesced
311311
let kr = mach_port_insert_right(mach_task_self_, _name, _name, mach_msg_type_name_t(how))
312-
if kr == KERN_INVALID_NAME {
312+
if kr == KERN_INVALID_NAME || kr == KERN_INVALID_CAPABILITY {
313313
throw Mach.PortRightError.deadName
314314
}
315315
_machPrecondition(kr)

Tests/SystemTests/MachPortTests.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,24 @@ final class MachPortTests: XCTestCase {
185185
}
186186

187187
func testCopyDeadName() throws {
188+
let recv = Mach.Port<Mach.ReceiveRight>()
189+
let send = recv.makeSendRight()
190+
_ = consume recv // and turn `send` into a dead name
191+
do {
192+
let copy = try send.copySendRight()
193+
_ = copy
194+
}
195+
catch Mach.PortRightError.deadName {
196+
}
197+
}
198+
199+
func testCopyDeadName2() throws {
188200
let send = Mach.Port<Mach.SendRight>(name: 0xffffffff)
189201
do {
190202
let copy = try send.copySendRight()
191203
_ = copy
192204
}
193205
catch Mach.PortRightError.deadName {
194-
_ = send.relinquish()
195206
}
196207
}
197208

0 commit comments

Comments
 (0)