@@ -179,30 +179,46 @@ extension Mach.Task {
179
179
}
180
180
181
181
extension 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 ] ) {
183
184
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 ?
186
187
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 ?
191
189
var infoTreeNameCount = mach_msg_type_number_t. max
192
- var info : ipc_info_space_t = ipc_info_space_t ( )
193
-
194
190
try Mach . call (
195
191
mach_port_space_info (
196
192
self . name, & info,
197
- infoNameArrayPointer , & infoNameCount,
198
- infoTreeNameArrayPointer , & infoTreeNameCount
193
+ & infoNameArray , & infoNameCount,
194
+ & infoTreeNameArray , & infoTreeNameCount
199
195
)
200
196
)
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
+ )
206
206
}
207
207
}
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
+ }
208
224
}
0 commit comments