···8899#include <darlingserver/rpc.h>
1010#include "../simple.h"
1111+#include "../elfcalls_wrapper.h"
1212+#include "../mach/lkm.h"
1313+#include "../unistd/close.h"
1414+#include "../../../libsyscall/wrappers/_libkernel_init.h"
1515+1616+extern int driver_fd;
1717+extern _libkernel_functions_t _libkernel_functions;
11181219long sys_fork(void)
1320{
···2431 else if (ret == 0)
2532 {
2633 // in the child
3434+3535+ // close the old RPC fd
3636+ // FIXME: we actually have to close ALL the old RPC fds for any threads the parent process may have had
3737+ close_internal((int)(intptr_t)_os_tsd_get_direct(__TSD_DSERVER_RPC_FD));
3838+3939+ // create a new dserver RPC socket
4040+ int new_rpc_fd = __dserver_new_socket();
4141+ if (new_rpc_fd < 0) {
4242+ // we can't do anything if we don't get our own separate connection to darlingserver
4343+ __simple_printf("Failed to create socket after fork\n");
4444+ __simple_abort();
4545+ }
4646+4747+ // set the new RPC fd
4848+ _os_tsd_set_direct(__TSD_DSERVER_RPC_FD, (void*)(intptr_t)new_rpc_fd);
4949+ driver_fd = new_rpc_fd;
5050+5151+ // update the fd stored in dyld, too
5252+ void (*dyld_set_mach_driver_fd)(int fd);
5353+ _libkernel_functions->dyld_func_lookup("__dyld_set_mach_driver_fd", (void**)&dyld_set_mach_driver_fd);
5454+ dyld_set_mach_driver_fd(new_rpc_fd);
5555+2756 if (dserver_rpc_checkin(true) < 0) {
2857 // we can't do ANYTHING if darlingserver fails to acknowledge us
2958 __simple_printf("Failed to checkin with darlingserver after fork\n");