Skip to content

Commit af87855

Browse files
committed
clean up documentation, add special case for ioMain port
1 parent 19e801f commit af87855

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Sources/Mach/Core/Host/HostSpecialPorts.swift

+10-4
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,16 @@ extension Mach.Host: Mach.PortWithSpecialPorts {
107107
_ specialPort: Mach.HostSpecialPort, as type: PortType.Type = PortType.self
108108
) throws -> PortType {
109109
var portName = mach_port_name_t()
110-
try Mach.call(
111-
// for historical reasons, we pass in HOST_LOCAL_NODE as the second parameter
112-
host_get_special_port(self.name, HOST_LOCAL_NODE, specialPort.rawValue, &portName)
113-
)
110+
switch specialPort {
111+
case .ioMain:
112+
// This works with unprivileged host ports, while the default case does not.
113+
try Mach.call(host_get_io_main(self.name, &portName))
114+
default:
115+
try Mach.call(
116+
// For historical reasons, we pass in HOST_LOCAL_NODE as the second parameter.
117+
host_get_special_port(self.name, HOST_LOCAL_NODE, specialPort.rawValue, &portName)
118+
)
119+
}
114120
return PortType(named: portName)
115121
}
116122

0 commit comments

Comments
 (0)