Skip to content

Commit 5e03246

Browse files
committed
test copies of dead mach port names
1 parent 40b5b30 commit 5e03246

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Sources/System/MachPort.swift

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

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

Tests/SystemTests/MachPortTests.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,17 @@ final class MachPortTests: XCTestCase {
183183
XCTAssertEqual(same, one)
184184

185185
}
186+
187+
func testCopyDeadName() throws {
188+
let send = Mach.Port<Mach.SendRight>(name: 0xffffffff)
189+
do {
190+
let copy = try send.copySendRight()
191+
_ = copy
192+
}
193+
catch Mach.PortRightError.deadName {
194+
_ = send.relinquish()
195+
}
196+
}
186197
}
187198

188199
#endif

0 commit comments

Comments
 (0)