Post

Replies

Boosts

Views

Activity

Reply to task_for_pid error 5
Sorry to hijack, but that didn't work for me. I'm trying a command-line utility, doing: static size_t get_thread_count(pid_t pid) { mach_port_t me = mach_task_self(); mach_port_t task; kern_return_t res; thread_array_t threads; mach_msg_type_number_t n_threads; res = task_for_pid(me, pid, &task); if (res != KERN_SUCCESS) { fprintf(stderr, "Unable to get task for pid %d: %d\n", pid, res); return 0; } res = task_threads(task, &threads, &n_threads); if (res != KERN_SUCCESS) { fprintf(stderr, "Could not get threads: %d\n", res); return 0; } res = vm_deallocate(me, (vm_address_t)threads, n_threads * sizeof(*threads)); // Ignore error return n_threads; }``` and using an entitlements plist of and using codesign --sign - --entitlements ./ent.plist --deep ./t3 --force to get it in there, but it fails with error 5. (Even when run as root. 😄) This could be how I'm codesigning it, of course; I was just doing a simple CLI tool test first.
Topic: App & System Services SubTopic: Core OS Tags:
Nov ’24
Reply to More DispatchIO problems -- cleanup handler isn't called
I didn't really solve it -- it's a hacky work-around. When I call dio?.close()... it should close. It doesn't. And because it's busy doing one byte of I/O at a time, there was pending data; I had to change it to close it after a delay (0.5 seconds). I don't know what amount the other side is sending. My read-length is 1024 (this is my go-to length when I'm reading from a network), my sample case is 18 bytes in my unit test, it's written all at once, but because of the water marks, the read handler is called 18 times. Well, 19 because of the delayed .close(flags: .stop). If I set the water-marks to something other than 1, then it always waits until the length is available. Which doesn't work when the connection is interactive. Thus: Also, I really wish it would get the data available at once for the read, rather than 1 at a time.)
Topic: App & System Services SubTopic: Core OS Tags:
Nov ’24
Reply to Upgraded to Sequoia & Xcode 16.0, now build doesn't work
As far as I can tell, this is a conflict between the nhollman json library, and a set of formatter headers added in Xcode 16. But since it's C++, I can't figure out what exactly is going on, or how to work around it. But... something that is compiled with Xcode 15 for macOS 14, with a minimum deployment of 12.0, really should still work with Xcode 16 & macOS 15, shouldn't it?
Sep ’24
Reply to Transparent Proxy Provider, UDP, mbufs, and inevitable panics
Well, that's the best way for Apple. It doesn't help me at all, although I guess there's no point to filing a TSI. 😄 My question at the beginning was whether anyone else has run into this, and if they have, did they have any mitigations (other than not including UDP in the includedRules set). I'd still love to know if anyone has, especially to the mitigations part. 😄
Topic: App & System Services SubTopic: Core OS Tags:
Aug ’24
Reply to DispatchIO crashes, tips on debugging?
Most this particular session has been in order to come up with a way to have tests for our transparent proxy provider that can be run without using the main extension -- so I rolled the networking code out, wrote a mimic of NEAppProxyFlow, and then wrote tests for it. It uses socket I/O to communicate with each side ("app" and "TPP"). Internally, it uses DispachIO to handle data sent from the "app", while it exposes the "TPP" side as a FileHandle (and it does that so that I could, if I needed to, pass it over XPC). This isn't the only way I could have implemented it, admittedly, but it grew out of my first approach, which was to use kqueue. (Oh, and I got the FileHandle issue solved -- the class behaves super badly if it gets closed more than once, so I isolated that code into a function, turned the object into an optional, and set it to nil after closing it.) Since I don't think I'll end up using XPC to pass the FileHandle around, I can probably turn it all into DispatchIO. I hadn't primarily because I kept getting crashes, and/or leaked file descriptors, but now that I can get the DispatchIO part working without crashes, it's time to revisit it.
Topic: App & System Services SubTopic: Core OS Tags:
Jul ’24
Reply to DispatchIO crashes, tips on debugging?
Ok, using that information, I was able to reproduce it in a standalone program, which helped me track it down. (And then I had to deal with the cleanupHandler not being called, but I found that out and got it done.) Now I'm sometimes getting a crash: fileHandle?.readabilityHandler = { fh in let data = try fh.availableData print("Got \(data.count) bytes") } *** Terminating app due to uncaught exception 'NSFileHandleOperationException', reason: '*** -[NSConcreteFileHandle availableData]: Bad file descriptor' This only happens sometimes, in my tests.
Topic: App & System Services SubTopic: Core OS Tags:
Jul ’24