+       /*
+        * Add main thread mach port name
+        * +1 uref on main thread port, this ref will be extracted by libpthread in __pthread_init
+        * and consumed in _bsdthread_terminate. Leaking the main thread port name if not linked
+        * against libpthread.
+        */
+       if ((new_thread = imgp->ip_new_thread) != THREAD_NULL) {
+               thread_reference(new_thread);
+               sright = convert_thread_to_port_pinned(new_thread);
+               task_t new_task = get_threadtask(new_thread);
+               mach_port_name_t name = ipc_port_copyout_send(sright, get_task_ipcspace(new_task));
+               char port_name_hex_str[strlen(MAIN_TH_PORT_KEY) + HEX_STR_LEN32 + 1];
+               snprintf(port_name_hex_str, sizeof(port_name_hex_str), MAIN_TH_PORT_KEY "0x%x", name);
+
+               error = exec_add_user_string(imgp, CAST_USER_ADDR_T(port_name_hex_str), UIO_SYSSPACE, FALSE);
+               if (error) {
+                       goto bad;
+               }
+               imgp->ip_applec++;
+       }