Skip to content

Commit 3a919bb

Browse files
committed
improve memory rebinding for mach_port_get_attributes call
1 parent f5edd72 commit 3a919bb

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

Sources/System/MachPort.swift

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,22 @@ extension Mach.Port where RightType == Mach.ReceiveRight {
263263
public var makeSendCount: mach_port_mscount_t {
264264
get {
265265
var status: mach_port_status = mach_port_status()
266-
var size: mach_msg_type_number_t = mach_msg_type_number_t(MemoryLayout<mach_port_status>.size / MemoryLayout<natural_t>.size)
267-
withUnsafeMutablePointer(to: &size) { size in
268-
withUnsafeMutablePointer(to: &status) { status in
269-
let info = UnsafeMutableRawPointer(status).bindMemory(to: integer_t.self, capacity: 1)
270-
_machPrecondition(mach_port_get_attributes(mach_task_self_, _name, MACH_PORT_RECEIVE_STATUS, info, size))
266+
var size = mach_msg_type_number_t(
267+
MemoryLayout<mach_port_status>.size / MemoryLayout<natural_t>.size
268+
)
269+
270+
withUnsafeMutablePointer(to: &status) {
271+
let status = UnsafeMutableBufferPointer(start: $0, count: 1)
272+
status.withMemoryRebound(to: integer_t.self) {
273+
_machPrecondition(
274+
mach_port_get_attributes(
275+
mach_task_self_,
276+
_name,
277+
MACH_PORT_RECEIVE_STATUS,
278+
$0.baseAddress,
279+
&size
280+
)
281+
)
271282
}
272283
}
273284
return status.mps_mscount

0 commit comments

Comments
 (0)