Post

Replies

Boosts

Views

Activity

Reply to Get file descriptor of VPN TUN interface
It's end-year 2021, and the file-descriptor method works till now, like: let tunFd = self.packetFlow.value(forKeyPath: "socket.fileDescriptor") as! Int32; . But we need to do: Remove beginning's 4 byte prefix when reading. Maybe prefix with Mac-header instead (if tap-layer packet is required). Later, when writing add back the 4 bytes (and remove any Mac-header instead). See also How to parse network-extension packets?
Oct ’21
Reply to Cannot profile network extension in iOS 10
Still same In Xcode 12.4 (and probably forever). But attaching seems work fine, if you know the trick: Call waitForDebugger(...) method (somewhere you're sure to be executed, by step #5), and place breakpoint after that (at least one). Run App normally (or with debugger). From within Xcode's "Debug" menu, click the "Attach to Process by PID or Name..." entry. In resulting dialog, write your extension-target's Name ONLY (instead of bundle-id), and click "Attach". Start your extension, so that it triggers step #1's logic (and later breakpoint). Now Xcode should be attached and paused on breakpoint; In "Show the Debug navigator" tab (of left sidebar), select extension-process's "Memory" section, then click "Profile in instruments" button. In resulting dialog, click "Profile" button, at last profiler did open, but go back to Xcode and resume the execution (remember was paused on breakpoint). Wait for Debugger (Swift 5 Example) public static func isDebuggerAttached() -> Bool {     var info = kinfo_proc()     var mib : [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]     var size = MemoryLayout.stride(ofValue: info)     let junk = sysctl(&mib, UInt32(mib.count), &info, &size, nil, 0)     assert(junk == 0, "sysctl failed")     return (info.kp_proc.p_flag & P_TRACED) != 0 } @discardableResult public static func waitForDebugger(_ timeout: Int = 30000) -> Bool {     var now: UInt64 = DispatchTime.now().uptimeNanoseconds     let begin = now     repeat {         if isDebuggerAttached() {             // Wait a little bit longer,             // because early breakpoints may still not work.             Thread.sleep(forTimeInterval: 3.0)             return true         } Thread.sleep(forTimeInterval: 0.1)         now = DispatchTime.now().uptimeNanoseconds     } while Double(now - begin) / 1000000.0 < Double(timeout);     return false; } Note that: Once the profiler is attached, for some reason the 15MB memory limit (or whatever) gets removed, and App takes about 3 times more memory!? Just ignore this profiler issues, and somehow count real memory usages :-(
Sep ’21
Reply to Memory mapped file: "Cannot allocate memory"
"iOS puts limits on the address space" OMG! The only advantage of 64 bit (vs 32 bit) is/was the support for up to 16 Exa-Byte memory, no system has that much "physical" memory (of course), but at least virtual-address-space should NEVER be limited to physical-address-space. Isn't it time to fix iOS mistakes? (Instead of telling people that mapped files are useless)
Topic: App & System Services SubTopic: Core OS Tags:
Sep ’21
Reply to Get file descriptor of VPN TUN interface
It's end-year 2021, and the file-descriptor method works till now, like: let tunFd = self.packetFlow.value(forKeyPath: "socket.fileDescriptor") as! Int32; . But we need to do: Remove beginning's 4 byte prefix when reading. Maybe prefix with Mac-header instead (if tap-layer packet is required). Later, when writing add back the 4 bytes (and remove any Mac-header instead). See also How to parse network-extension packets?
Replies
Boosts
Views
Activity
Oct ’21
Reply to Cannot profile network extension in iOS 10
Still same In Xcode 12.4 (and probably forever). But attaching seems work fine, if you know the trick: Call waitForDebugger(...) method (somewhere you're sure to be executed, by step #5), and place breakpoint after that (at least one). Run App normally (or with debugger). From within Xcode's "Debug" menu, click the "Attach to Process by PID or Name..." entry. In resulting dialog, write your extension-target's Name ONLY (instead of bundle-id), and click "Attach". Start your extension, so that it triggers step #1's logic (and later breakpoint). Now Xcode should be attached and paused on breakpoint; In "Show the Debug navigator" tab (of left sidebar), select extension-process's "Memory" section, then click "Profile in instruments" button. In resulting dialog, click "Profile" button, at last profiler did open, but go back to Xcode and resume the execution (remember was paused on breakpoint). Wait for Debugger (Swift 5 Example) public static func isDebuggerAttached() -> Bool {     var info = kinfo_proc()     var mib : [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]     var size = MemoryLayout.stride(ofValue: info)     let junk = sysctl(&mib, UInt32(mib.count), &info, &size, nil, 0)     assert(junk == 0, "sysctl failed")     return (info.kp_proc.p_flag & P_TRACED) != 0 } @discardableResult public static func waitForDebugger(_ timeout: Int = 30000) -> Bool {     var now: UInt64 = DispatchTime.now().uptimeNanoseconds     let begin = now     repeat {         if isDebuggerAttached() {             // Wait a little bit longer,             // because early breakpoints may still not work.             Thread.sleep(forTimeInterval: 3.0)             return true         } Thread.sleep(forTimeInterval: 0.1)         now = DispatchTime.now().uptimeNanoseconds     } while Double(now - begin) / 1000000.0 < Double(timeout);     return false; } Note that: Once the profiler is attached, for some reason the 15MB memory limit (or whatever) gets removed, and App takes about 3 times more memory!? Just ignore this profiler issues, and somehow count real memory usages :-(
Replies
Boosts
Views
Activity
Sep ’21
Reply to Memory mapped file: "Cannot allocate memory"
"iOS puts limits on the address space" OMG! The only advantage of 64 bit (vs 32 bit) is/was the support for up to 16 Exa-Byte memory, no system has that much "physical" memory (of course), but at least virtual-address-space should NEVER be limited to physical-address-space. Isn't it time to fix iOS mistakes? (Instead of telling people that mapped files are useless)
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Sep ’21