]> git.saurik.com Git - apple/libpthread.git/commitdiff
libpthread-454.100.8.tar.gz master macos-113 v454.100.8
authorApple <opensource@apple.com>
Mon, 19 Apr 2021 17:14:25 +0000 (17:14 +0000)
committerApple <opensource@apple.com>
Mon, 19 Apr 2021 17:14:25 +0000 (17:14 +0000)
kern/kern_support.c
libpthread.xcodeproj/project.pbxproj
src/prototypes_internal.h
src/pthread.c
xcodescripts/install-sys-headers.sh

index 4c7848f5ccfa3f8570ff01f59d0817cccd6122be..d33d6e31d375a2e61d43ee6695618c0d44a479f0 100644 (file)
@@ -269,16 +269,34 @@ _bsdthread_create(struct proc *p,
        }
 
        PTHREAD_TRACE(pthread_thread_create | DBG_FUNC_START, flags, 0, 0, 0);
-
-       kret = pthread_kern->thread_create(ctask, &th);
+       
+       /* Create thread and make it immovable, do not pin control port yet */
+       if (pthread_kern->thread_create_immovable) {
+               kret = pthread_kern->thread_create_immovable(ctask, &th);
+       } else {
+               kret = pthread_kern->thread_create(ctask, &th);
+       }
+       
        if (kret != KERN_SUCCESS)
                return(ENOMEM);
        thread_reference(th);
 
        pthread_kern->thread_set_tag(th, THREAD_TAG_PTHREAD);
 
-       sright = (void *)pthread_kern->convert_thread_to_port(th);
-       th_thport = pthread_kern->ipc_port_copyout_send(sright, pthread_kern->task_get_ipcspace(ctask));
+       if (pthread_kern->convert_thread_to_port_pinned) {
+               /* Convert to immovable/pinned thread port, but port is not pinned yet */
+               sright = (void *)pthread_kern->convert_thread_to_port_pinned(th);
+       } else {
+               sright = (void *)pthread_kern->convert_thread_to_port(th);
+       }
+       
+       if (pthread_kern->ipc_port_copyout_send_pinned) {
+               /* Atomically, pin and copy out the port */
+               th_thport = pthread_kern->ipc_port_copyout_send_pinned(sright, pthread_kern->task_get_ipcspace(ctask));
+       } else {
+               th_thport = pthread_kern->ipc_port_copyout_send(sright, pthread_kern->task_get_ipcspace(ctask));
+       }
+       
        if (!MACH_PORT_VALID(th_thport)) {
                error = EMFILE; // userland will convert this into a crash
                goto out;
@@ -494,7 +512,11 @@ _bsdthread_terminate(__unused struct proc *p,
        if (pthread_kern->thread_will_park_or_terminate) {
                pthread_kern->thread_will_park_or_terminate(th);
        }
-       (void)thread_terminate(th);
+       if (pthread_kern->thread_terminate_pinned) {
+               (void)pthread_kern->thread_terminate_pinned(th);
+       } else {
+               (void)thread_terminate(th);
+       }
        if (sem != MACH_PORT_NULL) {
                kret = pthread_kern->semaphore_signal_internal_trap(sem);
                if (kret != KERN_SUCCESS) {
index 0c8661138e215dc1a945b8b0b477ff67b12a7c43..d9b5c191efb47cd97889dc56277e71fc29bb3e2d 100644 (file)
                6ED6E66C22BFFC3200CE82C2 /* imports_internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = imports_internal.h; sourceTree = "<group>"; };
                6ED6E67322C0033B00CE82C2 /* prototypes_internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = prototypes_internal.h; sourceTree = "<group>"; };
                74E594A41613AAF4006C417B /* libpthread_eOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libpthread_eOS.a; sourceTree = BUILT_PRODUCTS_DIR; };
+               84D2815025314CEB0097326C /* sys_pthread_types.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; path = sys_pthread_types.modulemap; sourceTree = "<group>"; };
                9202B2301D1A5B3F00945880 /* introspection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = introspection.h; sourceTree = "<group>"; };
                9235CA551CA48D010015C92B /* kext_development.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = kext_development.xcconfig; sourceTree = "<group>"; };
                9240BF321AA669C4003C99B4 /* wqtrace.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = wqtrace.lua; path = tools/wqtrace.lua; sourceTree = SOURCE_ROOT; };
                        children = (
                                C9A325FD15B7513700270056 /* pthread */,
                                FC5A372217CEB3D6008C323E /* sys */,
+                               84D2815025314CEB0097326C /* sys_pthread_types.modulemap */,
                        );
                        path = include;
                        sourceTree = "<group>";
index 8fc4d4c4506ec4f814bbc1a9b41abee4d5f30d85..9694bee8e42325dfa6b18270e2ff3a044713ab3c 100644 (file)
@@ -77,7 +77,7 @@ extern uint64_t _pthread_debugstart;
 
 /* pthread.c */
 void _pthread_deallocate(pthread_t t, bool from_mach_thread);
-void _pthread_main_thread_init(pthread_t p);
+void _pthread_main_thread_init(pthread_t p, mach_port_name_t main_th);
 void _pthread_main_thread_postfork_init(pthread_t p);
 void _pthread_bsdthread_init(struct _pthread_registration_data *data);
 void *_pthread_atomic_xchg_ptr(void **p, void *v);
index 39f313105351f3eebce99a684c0ab6500e440acb..6882fa2e6f33bbeccac35d46b4c7e6851e36d4b7 100644 (file)
@@ -1732,6 +1732,17 @@ parse_ptr_munge_params(const char *envp[], const char *apple[])
        _pthread_init_signature(_main_thread_ptr);
 }
 
+static void
+parse_main_thread_port(const char *apple[], mach_port_name_t *main_th)
+{
+       const char *p, *s;
+       p = _simple_getenv(apple, "th_port");
+       if (p) {
+               *main_th = (mach_port_name_t)_pthread_strtoul(p, &s, 16);
+               bzero((char *)p, strlen(p));
+       }
+}
+
 int
 __pthread_init(const struct _libpthread_functions *pthread_funcs,
                const char *envp[], const char *apple[],
@@ -1812,13 +1823,17 @@ __pthread_init(const struct _libpthread_functions *pthread_funcs,
                        stackaddr, stacksize, allocaddr, allocsize);
        thread->tl_joinable = true;
 
+       // Get main thread port name from the kernel.
+       mach_port_name_t main_th_port = MACH_PORT_NULL;
+       parse_main_thread_port(apple, &main_th_port);
+
        // Finish initialization with common code that is reinvoked on the
        // child side of a fork.
 
        // Finishes initialization of main thread attributes.
        // Initializes the thread list and add the main thread.
        // Calls _pthread_set_self() to prepare the main thread for execution.
-       _pthread_main_thread_init(thread);
+       _pthread_main_thread_init(thread, main_th_port);
 
        struct _pthread_registration_data registration_data;
        // Set up kernel entry points with __bsdthread_register.
@@ -1842,7 +1857,7 @@ __pthread_init(const struct _libpthread_functions *pthread_funcs,
 #endif // !VARIANT_DYLD
 
 void
-_pthread_main_thread_init(pthread_t p)
+_pthread_main_thread_init(pthread_t p, mach_port_name_t main_thread_port)
 {
        TAILQ_INIT(&__pthread_head);
        _pthread_lock_init(&_pthread_list_lock);
@@ -1850,7 +1865,13 @@ _pthread_main_thread_init(pthread_t p)
        p->__cleanup_stack = NULL;
        p->tl_join_ctx = NULL;
        p->tl_exit_gate = MACH_PORT_NULL;
-       _pthread_tsd_slot(p, MACH_THREAD_SELF) = mach_thread_self();
+
+       if (main_thread_port != MACH_PORT_NULL) {
+               _pthread_tsd_slot(p, MACH_THREAD_SELF) = main_thread_port;
+       } else {
+               // Can't get thread port from kernel or we are forking, fallback to mach_thread_self
+               _pthread_tsd_slot(p, MACH_THREAD_SELF) = mach_thread_self();
+       }
        _pthread_tsd_slot(p, MIG_REPLY) = mach_reply_port();
        _pthread_tsd_slot(p, MACH_SPECIAL_REPLY) = MACH_PORT_NULL;
        _pthread_tsd_slot(p, SEMAPHORE_CACHE) = SEMAPHORE_NULL;
@@ -1865,7 +1886,7 @@ _pthread_main_thread_init(pthread_t p)
 void
 _pthread_main_thread_postfork_init(pthread_t p)
 {
-       _pthread_main_thread_init(p);
+       _pthread_main_thread_init(p, MACH_PORT_NULL);
        _pthread_set_self_internal(p);
 }
 
index 7b391fcbd1a36447cb6e9feae91a5514ec272d9b..647bfae976191bdc5fab32284d0c915c6f413f16 100644 (file)
@@ -32,9 +32,18 @@ install_headers()
 
     find "${DSTROOT}/${SDK_INSTALL_HEADERS_ROOT}$2" -type f -name *.h -print0 | \
         xargs -0I % unifdef -t ${COPY_HEADERS_UNIFDEF_FLAGS} -o "%" "%"
+}
+
+install_modulemaps()
+{
+    mkdir -p "${DSTROOT}/${SDK_INSTALL_HEADERS_ROOT}$2"
+    cp "${SRCROOT}/$1/"*.modulemap "${DSTROOT}/${SDK_INSTALL_HEADERS_ROOT}$2"
+
     find "${DSTROOT}/${SDK_INSTALL_HEADERS_ROOT}$2" -type f -name *.modulemap -print0 | \
         xargs -0I % unifdef -t ${COPY_HEADERS_UNIFDEF_FLAGS} -o "%" "%"
 }
 
 install_headers "include/sys" "/usr/include"
 install_headers "private/sys" "/usr/local/include"
+
+install_modulemaps "include" "/usr/include"