mach_ports_register broken on 10.7+
| Originator: | rsesek | ||
| Number: | rdar://15417334 | Date Originated: | 07-Nov-2013 |
| Status: | Behaves correctly | Resolved: | 2013-11-11 |
| Product: | Mac OS X | Product Version: | 10.7+ |
| Classification: | Other Bug | Reproducible: | Always |
Summary: The mach_ports_register() system call was broken on 10.7 with the introduction of libxpc. Prior to 10.7, you could use mach_ports_register() to pass an array of Mach ports to a child process across fork(). The child could then look up the array of ports with mach_ports_lookup(). In 10.7 and higher, however, XPC clobbers this array of ports for its own use, here: libsystem_kernel.dylib`mach_msg_trap+0xa libsystem_kernel.dylib`mach_ports_register+0x70 libxpc.dylib`xpc_atfork_prepare+0x2b libSystem.B.dylib`libSystem_atfork_prepare+0x9 libsystem_c.dylib`fork+0xc parent`main+0x138 libdyld.dylib`start parent`0x1 This removes the only non-kludgy way to pass a Mach port from a parent to a child. Steps to Reproduce: 1. Unzip the attached program 2. `make` 3. ./parent On 10.6, this works. On 10.7 and higher, it does not. Expected Results: The ./parent program should exit cleanly with output like: Sent message to parent on port 519 Got request: I'm a child: 71489 Child exited:1, status:0 This works on 10.6. Actual Results: On 10.7 and 10.8, the parent program hangs in mach_msg_receive() because the child program has sent the message to its bootstrap port. This happens because the port array has been replaced by XPC via xpc_atfork_prepare(). Version: Works: 10.6.8 10K549 Broken: 10.8.5 12F45 Regressed: 10.7.0 Notes: Configuration: Attachments: 'mach_ports_register.zip' was successfully uploaded.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Engineering has determined that this issue behaves as intended based on the following information:
This API was never shareable, and now the system owns it.
If you have questions regarding the resolution of this issue, please update your bug report with them.
We are now closing this bug report.