@@ -179,30 +179,46 @@ extension Mach.Task {
179179}
180180
181181extension Mach . Task {
182- public var spaceInfos : [ ipc_info_name_t ] {
182+ /// Information about the task's IPC space (name space), split into three parts.
183+ private var ipcSpaceInfo : ( ipc_info_space_t , [ ipc_info_name_t ] , [ ipc_info_tree_name_t ] ) {
183184 get throws {
184- let infoNameArrayPointer = UnsafeMutablePointer < ipc_info_name_array_t ?>
185- . allocate ( capacity : 1 )
185+ var info : ipc_info_space_t = ipc_info_space_t ( )
186+ var infoNameArray : ipc_info_name_array_t ?
186187 var infoNameCount = mach_msg_type_number_t. max
187-
188- // These are all unused, but they are required by `mach_port_space_info`.
189- let infoTreeNameArrayPointer = UnsafeMutablePointer< ipc_info_tree_name_array_t?>
190- . allocate( capacity: 1 )
188+ var infoTreeNameArray : ipc_info_tree_name_array_t ?
191189 var infoTreeNameCount = mach_msg_type_number_t. max
192- var info : ipc_info_space_t = ipc_info_space_t ( )
193-
194190 try Mach . call (
195191 mach_port_space_info (
196192 self . name, & info,
197- infoNameArrayPointer , & infoNameCount,
198- infoTreeNameArrayPointer , & infoTreeNameCount
193+ & infoNameArray , & infoNameCount,
194+ & infoTreeNameArray , & infoTreeNameCount
199195 )
200196 )
201-
202- guard let array = infoNameArrayPointer. pointee else {
203- return [ ]
204- }
205- return ( 0 ..< Int ( infoNameCount) ) . map { array [ $0] }
197+ return (
198+ info,
199+ infoNameArray != nil
200+ ? Array ( 0 ..< Int ( infoNameCount) ) . map { infoNameArray![ $0] }
201+ : [ ] ,
202+ infoTreeNameArray != nil
203+ ? Array ( 0 ..< Int ( infoTreeNameCount) ) . map { infoTreeNameArray![ $0] }
204+ : [ ]
205+ )
206206 }
207207 }
208+
209+ /// Information about the task's name space.
210+ public var nameSpaceInfo : ipc_info_space_t {
211+ get throws { try self . ipcSpaceInfo. 0 }
212+ }
213+
214+ /// The task's name space table.
215+ public var nameSpaceTable : [ ipc_info_name_t ] {
216+ get throws { try self . ipcSpaceInfo. 1 }
217+ }
218+
219+ /// The task's name space tree.
220+ /// - Note: This will likely be empty as the name space tree is not currently used.
221+ public var nameSpaceTree : [ ipc_info_tree_name_t ] {
222+ get throws { try self . ipcSpaceInfo. 2 }
223+ }
208224}
0 commit comments