├── .upstream_base_commits ├── include ├── pthread │ ├── introspection.h │ ├── pthread.h │ ├── pthread_impl.h │ ├── pthread_spis.h │ ├── qos.h │ ├── sched.h │ ├── spawn.h │ └── stack_np.h └── sys │ ├── _pthread │ ├── _pthread_attr_t.h │ ├── _pthread_cond_t.h │ ├── _pthread_condattr_t.h │ ├── _pthread_key_t.h │ ├── _pthread_mutex_t.h │ ├── _pthread_mutexattr_t.h │ ├── _pthread_once_t.h │ ├── _pthread_rwlock_t.h │ ├── _pthread_rwlockattr_t.h │ ├── _pthread_t.h │ └── _pthread_types.h │ └── qos.h ├── kern ├── kern_init.c ├── kern_internal.h ├── kern_support.c ├── kern_synch.c ├── kern_trace.h ├── pthread-Info.plist └── synch_internal.h ├── libpthread.xcodeproj └── project.pbxproj ├── lldbmacros └── init.py ├── man ├── pthread.3 ├── pthread_atfork.3 ├── pthread_attr.3 ├── pthread_attr_init_destroy.3 ├── pthread_attr_set_getdetachstate.3 ├── pthread_attr_set_getinheritsched.3 ├── pthread_attr_set_getschedparam.3 ├── pthread_attr_set_getschedpolicy.3 ├── pthread_attr_set_getscope.3 ├── pthread_attr_set_getstackaddr.3 ├── pthread_attr_set_getstacksize.3 ├── pthread_cancel.3 ├── pthread_cleanup_pop.3 ├── pthread_cleanup_push.3 ├── pthread_cond_broadcast.3 ├── pthread_cond_destroy.3 ├── pthread_cond_init.3 ├── pthread_cond_signal.3 ├── pthread_cond_timedwait.3 ├── pthread_cond_wait.3 ├── pthread_condattr.3 ├── pthread_create.3 ├── pthread_detach.3 ├── pthread_equal.3 ├── pthread_exit.3 ├── pthread_getschedparam.3 ├── pthread_getspecific.3 ├── pthread_jit_write_protect_np.3 ├── pthread_join.3 ├── pthread_key_create.3 ├── pthread_key_delete.3 ├── pthread_kill.2 ├── pthread_main_np.3 ├── pthread_mutex_destroy.3 ├── pthread_mutex_init.3 ├── pthread_mutex_lock.3 ├── pthread_mutex_trylock.3 ├── pthread_mutex_unlock.3 ├── pthread_mutexattr.3 ├── pthread_once.3 ├── pthread_rwlock_destroy.3 ├── pthread_rwlock_init.3 ├── pthread_rwlock_rdlock.3 ├── pthread_rwlock_unlock.3 ├── pthread_rwlock_wrlock.3 ├── pthread_rwlockattr_destroy.3 ├── pthread_rwlockattr_getpshared.3 ├── pthread_rwlockattr_init.3 ├── pthread_rwlockattr_setpshared.3 ├── pthread_self.3 ├── pthread_setcancelstate.3 ├── pthread_setname_np.3 ├── pthread_setspecific.3 ├── pthread_sigmask.2 ├── pthread_threadid_np.3 └── pthread_yield_np.3 ├── private ├── pthread │ ├── dependency_private.h │ ├── introspection_private.h │ ├── jit_private.h │ ├── posix_sched.h │ ├── private.h │ ├── qos_private.h │ ├── spinlock_private.h │ ├── tsd_private.h │ ├── workgroup_private.h │ └── workqueue_private.h └── sys │ └── qos_private.h ├── src ├── exports_internal.h ├── imports_internal.h ├── inline_internal.h ├── internal.h ├── offsets_internal.h ├── plockstat.d ├── prototypes_internal.h ├── pthread.c ├── pthread_asm.s ├── pthread_atfork.c ├── pthread_cancelable.c ├── pthread_cond.c ├── pthread_cwd.c ├── pthread_dependency.c ├── pthread_mutex.c ├── pthread_rwlock.c ├── pthread_tsd.c ├── qos.c ├── resolver │ ├── resolver.c │ ├── resolver.h │ └── resolver_internal.h ├── types_internal.h └── variants │ └── pthread_cancelable_cancel.c ├── tests ├── Makefile ├── add_timer_termination.c ├── atfork.c ├── bsdthread_set_self.c ├── com.apple.libpthread.tests.plist ├── cond.c ├── cond_hang3.c ├── cond_prepost.c ├── cond_stress.c ├── cond_timed.c ├── custom_stack.c ├── darwintest_defaults.h ├── detach.c ├── helpers │ ├── libpthreadjittest.c │ ├── pthread_jit_write_with_callback_tool.c │ └── stackoverflow_crash.c ├── join.c ├── main_stack.c ├── main_stack_custom.c ├── main_stack_legacy.c ├── maxwidth.c ├── mutex.c ├── mutex_prepost.c ├── mutex_try.c ├── once_cancel.c ├── perf_contended_mutex_rwlock.c ├── pthread_attr_setstacksize.c ├── pthread_bulk_create.c ├── pthread_cancel.c ├── pthread_create_from_mach_thread.c ├── pthread_cwd.c ├── pthread_dependency.c ├── pthread_exit.c ├── pthread_get_qos_class_np.c ├── pthread_introspection.c ├── pthread_jit_write_freeze_callbacks-ios-entitlements.plist ├── pthread_jit_write_freeze_callbacks-macos-entitlements.plist ├── pthread_jit_write_freeze_callbacks.c ├── pthread_jit_write_lockdown-entitlements.plist ├── pthread_jit_write_lockdown.c ├── pthread_jit_write_protection-entitlements.plist ├── pthread_jit_write_protection.c ├── pthread_jit_write_test_inline.h ├── pthread_jit_write_with_callback-ios-entitlements.plist ├── pthread_jit_write_with_callback-macos-entitlements.plist ├── pthread_jit_write_with_callback.c ├── pthread_setspecific.c ├── pthread_threadid_np.c ├── qos.c ├── rdar_32848402.c ├── rwlock-22244050.c ├── rwlock-signal.c ├── rwlock.c ├── setrlimit_sigsegv.c ├── stack.c ├── stack_aslr.c ├── stack_size.c ├── tsd.c ├── wq_block_handoff.c ├── wq_cooperative.c ├── wq_event_manager.c ├── wq_kevent.c ├── wq_kevent.h ├── wq_kevent_stress.c └── wq_limits.c ├── tools ├── locktrace.lua └── pthtrace.lua └── xcodescripts ├── eos.xcconfig ├── install-codes.sh ├── install-lldbmacros.sh ├── install-manpages.sh ├── install-symlinks.sh ├── install-sys-headers.sh ├── kext.xcconfig ├── kext_development.xcconfig ├── pthread-i386.aliases ├── pthread-tapi.xcconfig ├── pthread.aliases ├── pthread.dirty ├── pthread.xcconfig ├── pthread_driverkit.xcconfig ├── pthread_introspection.xcconfig ├── resolved.xcconfig ├── resolver.xcconfig ├── run-on-install.sh └── static.xcconfig /include/pthread/pthread_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | 24 | #ifndef _PTHREAD_IMPL_H_ 25 | #define _PTHREAD_IMPL_H_ 26 | /* 27 | * Internal implementation details 28 | */ 29 | 30 | /* This whole header file will disappear, so don't depend on it... */ 31 | 32 | #if __has_feature(assume_nonnull) 33 | _Pragma("clang assume_nonnull begin") 34 | #endif 35 | 36 | #ifndef __POSIX_LIB__ 37 | 38 | /* 39 | * [Internal] data structure signatures 40 | */ 41 | #define _PTHREAD_MUTEX_SIG_init 0x32AAABA7 42 | 43 | #define _PTHREAD_ERRORCHECK_MUTEX_SIG_init 0x32AAABA1 44 | #define _PTHREAD_RECURSIVE_MUTEX_SIG_init 0x32AAABA2 45 | #define _PTHREAD_FIRSTFIT_MUTEX_SIG_init 0x32AAABA3 46 | 47 | #define _PTHREAD_COND_SIG_init 0x3CB0B1BB 48 | #define _PTHREAD_ONCE_SIG_init 0x30B1BCBA 49 | #define _PTHREAD_RWLOCK_SIG_init 0x2DA8B3B4 50 | 51 | /* 52 | * POSIX scheduling policies 53 | */ 54 | #define SCHED_OTHER 1 55 | #define SCHED_FIFO 4 56 | #define SCHED_RR 2 57 | 58 | #define __SCHED_PARAM_SIZE__ 4 59 | 60 | #endif /* __POSIX_LIB__ */ 61 | 62 | #if __has_feature(assume_nonnull) 63 | _Pragma("clang assume_nonnull end") 64 | #endif 65 | 66 | #endif /* _PTHREAD_IMPL_H_ */ 67 | -------------------------------------------------------------------------------- /include/pthread/sched.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | 24 | #ifndef _SCHED_H_ 25 | #define _SCHED_H_ 26 | 27 | #include 28 | #include 29 | 30 | __BEGIN_DECLS 31 | /* 32 | * Scheduling paramters 33 | */ 34 | #ifndef __POSIX_LIB__ 35 | struct sched_param { int sched_priority; char __opaque[__SCHED_PARAM_SIZE__]; }; 36 | #else 37 | struct sched_param; 38 | #endif 39 | 40 | extern int sched_yield(void); 41 | extern int sched_get_priority_min(int); 42 | extern int sched_get_priority_max(int); 43 | __END_DECLS 44 | 45 | #endif /* _SCHED_H_ */ 46 | 47 | -------------------------------------------------------------------------------- /include/pthread/spawn.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | 24 | #ifndef _PTHREAD_SPAWN_H 25 | #define _PTHREAD_SPAWN_H 26 | 27 | /*! 28 | * @group posix_spawn QOS class support 29 | * Apple extensions to posix_spawn(2) and posix_spawnp(2) 30 | */ 31 | 32 | #include 33 | #include 34 | 35 | __BEGIN_DECLS 36 | 37 | /*! 38 | * @function posix_spawnattr_set_qos_class_np 39 | * 40 | * @abstract 41 | * Sets the QOS class property of a posix_spawn attributes object, which may be 42 | * used to specify the QOS class a process should be spawned with. 43 | * 44 | * @discussion 45 | * The QOS class specified at the time of process spawn determines both the 46 | * initial requested QOS class of the main thread in the new process, and the 47 | * interpretation by the system of all QOS class values requested by threads in 48 | * the process. 49 | * 50 | * @param __attr 51 | * The spawn attributes object to modify. 52 | * 53 | * @param __qos_class 54 | * A QOS class value: 55 | * - QOS_CLASS_UTILITY 56 | * - QOS_CLASS_BACKGROUND 57 | * EINVAL will be returned if any other value is provided. 58 | * 59 | * @return 60 | * Zero if successful, otherwise an errno value. 61 | */ 62 | __API_AVAILABLE(macos(10.10), ios(8.0)) 63 | int 64 | posix_spawnattr_set_qos_class_np(posix_spawnattr_t * __restrict __attr, 65 | qos_class_t __qos_class); 66 | 67 | /*! 68 | * @function posix_spawnattr_get_qos_class_np 69 | * 70 | * @abstract 71 | * Gets the QOS class property of a posix_spawn attributes object. 72 | * 73 | * @param __attr 74 | * The spawn attributes object to inspect. 75 | * 76 | * @param __qos_class 77 | * On output, a QOS class value: 78 | * - QOS_CLASS_UTILITY 79 | * - QOS_CLASS_BACKGROUND 80 | * - QOS_CLASS_UNSPECIFIED 81 | * 82 | * @return 83 | * Zero if successful, otherwise an errno value. 84 | */ 85 | __API_AVAILABLE(macos(10.10), ios(8.0)) 86 | int 87 | posix_spawnattr_get_qos_class_np(const posix_spawnattr_t *__restrict __attr, 88 | qos_class_t * __restrict __qos_class); 89 | 90 | __END_DECLS 91 | 92 | #endif // _PTHREAD_SPAWN_H 93 | -------------------------------------------------------------------------------- /include/pthread/stack_np.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_APACHE_LICENSE_HEADER_START@ 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | * @APPLE_APACHE_LICENSE_HEADER_END@ 19 | */ 20 | 21 | #ifndef __PTHREAD_STACK_NP__ 22 | #define __PTHREAD_STACK_NP__ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | OS_ASSUME_NONNULL_BEGIN 32 | 33 | /*! @header 34 | * Low-level API to introspect thread stacks. 35 | */ 36 | 37 | __BEGIN_DECLS 38 | 39 | /*! 40 | * @function pthread_stack_frame_decode_np 41 | * 42 | * @abstract 43 | * Decodes the return address and the next stack frame address 44 | * from the given stack frame address. 45 | * 46 | * @discussion 47 | * Validation of the frame address is not performed by this function. 48 | * The caller is responsible for making sure the frame address is valid, 49 | * for example using pthread_get_stackaddr_np() and pthread_get_stacksize_np(). 50 | * 51 | * @param frame_addr 52 | * A valid stack frame address such as __builtin_frame_address(0) or the return 53 | * value of a previous call to pthread_stack_frame_decode_np(). 54 | * 55 | * @param return_addr 56 | * An optional out paramter that will be filled with the return address stored 57 | * at the specified stack frame. 58 | * 59 | * @returns 60 | * This returns the next frame address stored at the specified stack frame. 61 | */ 62 | __OSX_AVAILABLE(10.14) __IOS_AVAILABLE(12.0) 63 | __TVOS_AVAILABLE(12.0) __WATCHOS_AVAILABLE(5.0) 64 | uintptr_t 65 | pthread_stack_frame_decode_np(uintptr_t frame_addr, 66 | uintptr_t *_Nullable return_addr); 67 | 68 | __END_DECLS 69 | 70 | OS_ASSUME_NONNULL_END 71 | 72 | #endif // __PTHREAD_STACK_NP__ 73 | -------------------------------------------------------------------------------- /include/sys/_pthread/_pthread_attr_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2012 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | #ifndef _PTHREAD_ATTR_T 29 | #define _PTHREAD_ATTR_T 30 | #include /* __darwin_pthread_attr_t */ 31 | typedef __darwin_pthread_attr_t pthread_attr_t; 32 | #endif /* _PTHREAD_ATTR_T */ 33 | -------------------------------------------------------------------------------- /include/sys/_pthread/_pthread_cond_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2012 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | #ifndef _PTHREAD_COND_T 29 | #define _PTHREAD_COND_T 30 | #include /* __darwin_pthread_cond_t */ 31 | typedef __darwin_pthread_cond_t pthread_cond_t; 32 | #endif /* _PTHREAD_COND_T */ 33 | -------------------------------------------------------------------------------- /include/sys/_pthread/_pthread_condattr_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2012 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | #ifndef _PTHREAD_CONDATTR_T 29 | #define _PTHREAD_CONDATTR_T 30 | #include /* __darwin_pthread_condattr_t */ 31 | typedef __darwin_pthread_condattr_t pthread_condattr_t; 32 | #endif /* _PTHREAD_CONDATTR_T */ 33 | -------------------------------------------------------------------------------- /include/sys/_pthread/_pthread_key_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2012 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | #ifndef _PTHREAD_KEY_T 29 | #define _PTHREAD_KEY_T 30 | #include /* __darwin_pthread_key_t */ 31 | typedef __darwin_pthread_key_t pthread_key_t; 32 | #endif /* _PTHREAD_KEY_T */ 33 | -------------------------------------------------------------------------------- /include/sys/_pthread/_pthread_mutex_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2012 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | #ifndef _PTHREAD_MUTEX_T 29 | #define _PTHREAD_MUTEX_T 30 | #include /* __darwin_pthread_mutex_t */ 31 | typedef __darwin_pthread_mutex_t pthread_mutex_t; 32 | #endif /*_PTHREAD_MUTEX_T */ 33 | -------------------------------------------------------------------------------- /include/sys/_pthread/_pthread_mutexattr_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2012 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | #ifndef _PTHREAD_MUTEXATTR_T 29 | #define _PTHREAD_MUTEXATTR_T 30 | #include /* __darwin_pthread_mutexattr_t */ 31 | typedef __darwin_pthread_mutexattr_t pthread_mutexattr_t; 32 | #endif /* _PTHREAD_MUTEXATTR_T */ 33 | -------------------------------------------------------------------------------- /include/sys/_pthread/_pthread_once_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2012 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | #ifndef _PTHREAD_ONCE_T 29 | #define _PTHREAD_ONCE_T 30 | #include /* __darwin_pthread_once_t */ 31 | typedef __darwin_pthread_once_t pthread_once_t; 32 | #endif /* _PTHREAD_ONCE_T */ 33 | -------------------------------------------------------------------------------- /include/sys/_pthread/_pthread_rwlock_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2012 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | #ifndef _PTHREAD_RWLOCK_T 29 | #define _PTHREAD_RWLOCK_T 30 | #include /* __darwin_pthread_rwlock_t */ 31 | typedef __darwin_pthread_rwlock_t pthread_rwlock_t; 32 | #endif /* _PTHREAD_RWLOCK_T */ 33 | -------------------------------------------------------------------------------- /include/sys/_pthread/_pthread_rwlockattr_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2012 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | #ifndef _PTHREAD_RWLOCKATTR_T 29 | #define _PTHREAD_RWLOCKATTR_T 30 | #include /* __darwin_pthread_rwlockattr_t */ 31 | typedef __darwin_pthread_rwlockattr_t pthread_rwlockattr_t; 32 | #endif /* _PTHREAD_RWLOCKATTR_T */ 33 | -------------------------------------------------------------------------------- /include/sys/_pthread/_pthread_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2012 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | #ifndef _PTHREAD_T 29 | #define _PTHREAD_T 30 | #include /* __darwin_pthread_t */ 31 | typedef __darwin_pthread_t pthread_t; 32 | #endif /* _PTHREAD_T */ 33 | -------------------------------------------------------------------------------- /kern/kern_init.c: -------------------------------------------------------------------------------- 1 | // 2 | // pthread.c 3 | // pthread 4 | // 5 | // Created by Matt Wright on 9/13/12. 6 | // Copyright (c) 2012 Matt Wright. All rights reserved. 7 | // 8 | 9 | #include 10 | #include 11 | #include "kern/kern_internal.h" 12 | 13 | kern_return_t pthread_start(kmod_info_t * ki, void *d); 14 | kern_return_t pthread_stop(kmod_info_t *ki, void *d); 15 | 16 | pthread_callbacks_t pthread_kern; 17 | 18 | const struct pthread_functions_s pthread_internal_functions = { 19 | .pthread_init = _pthread_init, 20 | .pth_proc_hashinit = _pth_proc_hashinit, 21 | .pth_proc_hashdelete = _pth_proc_hashdelete, 22 | .bsdthread_create = _bsdthread_create, 23 | .bsdthread_register = _bsdthread_register, 24 | .bsdthread_terminate = _bsdthread_terminate, 25 | .thread_selfid = _thread_selfid, 26 | 27 | .psynch_mutexwait = _psynch_mutexwait, 28 | .psynch_mutexdrop = _psynch_mutexdrop, 29 | .psynch_cvbroad = _psynch_cvbroad, 30 | .psynch_cvsignal = _psynch_cvsignal, 31 | .psynch_cvwait = _psynch_cvwait, 32 | .psynch_cvclrprepost = _psynch_cvclrprepost, 33 | .psynch_rw_longrdlock = _psynch_rw_longrdlock, 34 | .psynch_rw_rdlock = _psynch_rw_rdlock, 35 | .psynch_rw_unlock = _psynch_rw_unlock, 36 | .psynch_rw_wrlock = _psynch_rw_wrlock, 37 | .psynch_rw_yieldwrlock = _psynch_rw_yieldwrlock, 38 | 39 | .pthread_find_owner = _pthread_find_owner, 40 | .pthread_get_thread_kwq = _pthread_get_thread_kwq, 41 | 42 | .workq_create_threadstack = workq_create_threadstack, 43 | .workq_destroy_threadstack = workq_destroy_threadstack, 44 | .workq_setup_thread = workq_setup_thread, 45 | .workq_handle_stack_events = workq_handle_stack_events, 46 | .workq_markfree_threadstack = workq_markfree_threadstack, 47 | }; 48 | 49 | kern_return_t pthread_start(__unused kmod_info_t * ki, __unused void *d) 50 | { 51 | pthread_kext_register((pthread_functions_t)&pthread_internal_functions, &pthread_kern); 52 | return KERN_SUCCESS; 53 | } 54 | 55 | kern_return_t pthread_stop(__unused kmod_info_t *ki, __unused void *d) 56 | { 57 | return KERN_FAILURE; 58 | } 59 | 60 | struct uthread* 61 | current_uthread(void) 62 | { 63 | thread_t th = current_thread(); 64 | return pthread_kern->get_bsdthread_info(th); 65 | } 66 | -------------------------------------------------------------------------------- /kern/pthread-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | AppleKernelExternalComponent 6 | 7 | CFBundleDevelopmentRegion 8 | English 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | 13 | CFBundleIdentifier 14 | $(PRODUCT_BUNDLE_IDENTIFIER) 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | KEXT 21 | CFBundleShortVersionString 22 | 1.0 23 | CFBundleSignature 24 | ???? 25 | CFBundleVersion 26 | 1 27 | NSHumanReadableCopyright 28 | Copyright © 2012 Apple Inc. All rights reserved. 29 | OSBundleAllowUserLoad 30 | 31 | OSBundleCompatibleVersion 32 | 1.0 33 | OSBundleLibraries 34 | 35 | com.apple.kpi.bsd 36 | 12.0 37 | com.apple.kpi.iokit 38 | 13.0.0 39 | com.apple.kpi.libkern 40 | 11.2 41 | com.apple.kpi.mach 42 | 11.2 43 | com.apple.kpi.private 44 | 11.2 45 | com.apple.kpi.unsupported 46 | 11.2 47 | 48 | OSBundleRequired 49 | Root 50 | 51 | 52 | -------------------------------------------------------------------------------- /man/pthread_attr_init_destroy.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2004-2007 Apple Inc. All rights reserved. 2 | .Dd December 31, 2007 3 | .Dt PTHREAD_ATTR 3 4 | .Os 5 | .Sh NAME 6 | .Nm pthread_attr_destroy , 7 | .Nm pthread_attr_init 8 | .Nd thread attribute operations 9 | .Sh SYNOPSIS 10 | .Fd #include 11 | .Ft int 12 | .Fo pthread_attr_destroy 13 | .Fa "pthread_attr_t *attr" 14 | .Fc 15 | .Ft int 16 | .Fo pthread_attr_init 17 | .Fa "pthread_attr_t *attr" 18 | .Fc 19 | .Sh DESCRIPTION 20 | Thread attributes are used to specify parameters to 21 | .Fn pthread_create . 22 | One attribute object can be used in multiple calls to 23 | .Fn pthread_create , 24 | with or without modifications between calls. 25 | .Pp 26 | The 27 | .Fn pthread_attr_init 28 | function initializes 29 | .Fa attr 30 | with all the default thread attributes. 31 | .Pp 32 | The 33 | .Fn pthread_attr_destroy 34 | function destroys 35 | .Fa attr . 36 | .Sh RETURN VALUES 37 | If successful, these functions return 0. 38 | Otherwise, an error number is returned to indicate the error. 39 | .Sh ERRORS 40 | .Fn pthread_attr_init 41 | will fail if: 42 | .Bl -tag -width Er 43 | .\" ======== 44 | .It Bq Er ENOMEM 45 | Out of memory. 46 | .El 47 | .Pp 48 | .Fn pthread_attr_destroy 49 | will fail if: 50 | .Bl -tag -width Er 51 | .\" ======== 52 | .It Bq Er EINVAL 53 | Invalid value for 54 | .Fa attr . 55 | .El 56 | .Pp 57 | .Sh SEE ALSO 58 | .Xr pthread_create 3 59 | .Sh STANDARDS 60 | .Fn pthread_attr_init , 61 | .Fn pthread_attr_destroy 62 | conform to 63 | .St -p1003.1-96 64 | .Pp 65 | -------------------------------------------------------------------------------- /man/pthread_attr_set_getdetachstate.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2004-2007 Apple Inc. All rights reserved. 2 | .Dd December 31, 2007 3 | .Dt PTHREAD_ATTR 3 4 | .Os 5 | .Sh NAME 6 | .Nm pthread_attr_getdetachstate , 7 | .Nm pthread_attr_setdetachstate 8 | .Nd thread attribute operations 9 | .Sh SYNOPSIS 10 | .Fd #include 11 | .Ft int 12 | .Fo pthread_attr_getdetachstate 13 | .Fa "const pthread_attr_t *attr" 14 | .Fa "int *detachstate" 15 | .Fc 16 | .Ft int 17 | .Fo pthread_attr_setdetachstate 18 | .Fa "pthread_attr_t *attr" 19 | .Fa "int detachstate" 20 | .Fc 21 | .Sh DESCRIPTION 22 | Thread attributes are used to specify parameters to 23 | .Fn pthread_create . 24 | One attribute object can be used in multiple calls to 25 | .Fn pthread_create , 26 | with or without modifications between calls. 27 | .Pp 28 | One of these thread attributes governs the creation state of the new thread. The new thread 29 | can be either created "detached" or "joinable". The constants corresponding to these states are PTHREAD_CREATE_DETACHED and PTHREAD_CREATE_JOINABLE respectively. 30 | Creating a "joinable" thread allows the user 31 | to call 32 | .Fn pthread_join 33 | and 34 | .Fn pthread_detach , 35 | with the new thread's ID. A "detached" thread's ID cannot be used with 36 | .Fn pthread_join 37 | and 38 | .Fn pthread_detach . 39 | The default value for the "detachstate" attribute is PTHREAD_CREATE_JOINABLE. 40 | .Pp 41 | The 42 | .Fn pthread_attr_setdetachstate 43 | function sets the thread's "detachstate" attribute. 44 | .Pp 45 | The "detachstate" attribute is set within the 46 | .Fa attr 47 | argument, which can subsequently be used as an argument to 48 | .Fn pthread_create . 49 | .Sh RETURN VALUES 50 | If successful, these functions return 0. 51 | Otherwise, an error number is returned to indicate the error. 52 | .Fn pthread_attr_getdetachstate , 53 | on success, will copy the value of the thread's "detachstate" attribute 54 | to the location pointed to by the second function parameter. 55 | .Sh ERRORS 56 | .Fn pthread_attr_getdetachstate 57 | will fail if: 58 | .Bl -tag -width Er 59 | .\" ======== 60 | .It Bq Er EINVAL 61 | Invalid value for 62 | .Fa attr 63 | .El 64 | .Pp 65 | .Fn pthread_attr_setdetachstate 66 | will fail if: 67 | .Bl -tag -width Er 68 | .\" ======== 69 | .It Bq Er EINVAL 70 | Invalid value for 71 | .Fa attr 72 | or 73 | .Fa detachstate . 74 | .El 75 | .Pp 76 | .Sh SEE ALSO 77 | .Xr pthread_create 3 , 78 | .Xr pthread_join 3 , 79 | .Xr pthread_attr_init 3 , 80 | .Xr pthread_detach 3 81 | .Sh STANDARDS 82 | .Fn pthread_attr_setdetachstate , 83 | .Fn pthread_attr_getdetachstate 84 | conform to 85 | .St -p1003.1-96 86 | .Pp 87 | -------------------------------------------------------------------------------- /man/pthread_attr_set_getinheritsched.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2004-2007 Apple Inc. All rights reserved. 2 | .Dd December 31, 2007 3 | .Dt PTHREAD_ATTR 3 4 | .Os 5 | .Sh NAME 6 | .Nm pthread_attr_getinheritsched , 7 | .Nm pthread_attr_setinheritsched 8 | .Nd thread attribute operations 9 | .Sh SYNOPSIS 10 | .Fd #include 11 | .Ft int 12 | .Fo pthread_attr_getinheritsched 13 | .Fa "const pthread_attr_t *restrict attr" 14 | .Fa "int *restrict inheritsched" 15 | .Fc 16 | .Ft int 17 | .Fo pthread_attr_setinheritsched 18 | .Fa "pthread_attr_t *attr" 19 | .Fa "int inheritsched" 20 | .Fc 21 | .Sh DESCRIPTION 22 | Thread attributes are used to specify parameters to 23 | .Fn pthread_create . 24 | One attribute object can be used in multiple calls to 25 | .Fn pthread_create , 26 | with or without modifications between calls. 27 | .Pp 28 | One of the thread attributes of interest is the "inheritsched" attribute. This attribute 29 | controls the scheduling policy and related attributes of the newly created thread. The values of the 30 | "inheritsched" attribute can be either PTHREAD_INHERIT_SCHED or PTHREAD_EXPLICIT_SCHED. 31 | .Pp 32 | PTHREAD_INHERIT_SCHED 33 | .Pp 34 | Indicates that the newly created thread should inherit all it's scheduling related attributes from it's creating 35 | thread. It ignores the values of the relevant attributes within the 36 | .Fa attr 37 | argument. 38 | .Pp 39 | PTHREAD_EXPLICIT_SCHED 40 | .Pp 41 | Indicates that the newly created thread should set it's scheduling related attributes based on 42 | .Fa attr 43 | argument. 44 | .Pp 45 | The 46 | .Fn pthread_attr_setinheritsched 47 | functions set the "inheritsched" attribute within the 48 | .Fa attr 49 | argument to the desired value. 50 | .Pp 51 | The 52 | .Fn pthread_attr_getinheritsched 53 | functions copy the value of the "inheritsched" attribute to the location pointed to by the second function parameter. 54 | .Sh RETURN VALUES 55 | If successful, these functions return 0. 56 | Otherwise, an error number is returned to indicate the error. 57 | .Sh ERRORS 58 | .Pp 59 | .Fn pthread_attr_getinheritsched 60 | will fail if: 61 | .Bl -tag -width Er 62 | .\" ======== 63 | .It Bq Er EINVAL 64 | Invalid value for 65 | .Fa attr . 66 | .El 67 | .Pp 68 | .Fn pthread_attr_setinheritsched 69 | will fail if: 70 | .Bl -tag -width Er 71 | .\" ======== 72 | .It Bq Er EINVAL 73 | Invalid value for 74 | .Fa attr . 75 | .El 76 | .Sh BUGS 77 | .Pp 78 | The "inheritsched" attribute has no effect on Darwin. It is provided for compatibility only. 79 | .Sh SEE ALSO 80 | .Xr pthread_create 3 , 81 | .Xr pthread_attr_init 3 , 82 | .Xr pthread_attr_setschedparam 3 83 | .Sh STANDARDS 84 | .Pp 85 | .Fn pthread_attr_setinheritsched , 86 | .Fn pthread_attr_getinheritsched 87 | conform to 88 | .St -susv2 89 | -------------------------------------------------------------------------------- /man/pthread_attr_set_getschedparam.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2004-2007 Apple Inc. All rights reserved. 2 | .Dd December 31, 2007 3 | .Dt PTHREAD_ATTR 3 4 | .Os 5 | .Sh NAME 6 | .Nm pthread_attr_getschedparam , 7 | .Nm pthread_attr_setschedparam 8 | .Nd thread attribute operations 9 | .Sh SYNOPSIS 10 | .Fd #include 11 | .Ft int 12 | .Fo pthread_attr_getschedparam 13 | .Fa "const pthread_attr_t *restrict attr" 14 | .Fa "struct sched_param *restrict param" 15 | .Fc 16 | .Ft int 17 | .Fo pthread_attr_setschedparam 18 | .Fa "pthread_attr_t *restrict attr" 19 | .Fa "const struct sched_param *restrict param" 20 | .Fc 21 | .Sh DESCRIPTION 22 | Thread attributes are used to specify parameters to 23 | .Fn pthread_create . 24 | One attribute object can be used in multiple calls to 25 | .Fn pthread_create , 26 | with or without modifications between calls. 27 | .Pp 28 | .Fn pthread_attr_getschedparam 29 | and 30 | .Fn pthread_attr_setschedparam 31 | get and set the scheduling parameters within the 32 | .Fa attr 33 | argument. See 34 | .Fd /usr/include/sched.h 35 | for the definition of 36 | .Fa struct sched_param . 37 | The 38 | .Fa sched_priority 39 | field of 40 | .Fa struct sched_param 41 | must be within the range returned by the 42 | .Xr sched_get_priority_min 2 43 | and 44 | .Xr sched_get_priority_max 2 45 | system calls. 46 | .Sh RETURN VALUES 47 | If successful, these functions return 0. 48 | Otherwise, an error number is returned to indicate the error. 49 | .Fn pthread_attr_getschedparam , 50 | on success, will copy the value of the thread's scheduling parameter attribute 51 | to the location pointed to by the second function parameter. 52 | .Sh ERRORS 53 | .Pp 54 | .Fn pthread_attr_getschedparam 55 | will fail if: 56 | .Bl -tag -width Er 57 | .\" ======== 58 | .It Bq Er EINVAL 59 | Invalid value for 60 | .Fa attr . 61 | .\" ======== 62 | .El 63 | .Pp 64 | .Fn pthread_attr_setschedparam 65 | will fail if: 66 | .Bl -tag -width Er 67 | .\" ======== 68 | .It Bq Er EINVAL 69 | Invalid value for 70 | .Fa attr . 71 | .\" ======== 72 | .It Bq Er ENOTSUP 73 | Invalid value for 74 | .Fa param . 75 | .El 76 | .Sh SEE ALSO 77 | .Xr pthread_create 3 , 78 | .Xr pthread_attr_init 3 , 79 | .Xr pthread_attr_setinheritsched 3 80 | .Sh STANDARDS 81 | .Pp 82 | .Fn pthread_attr_setschedparam , 83 | .Fn pthread_attr_getschedparam 84 | conform to 85 | .St -susv2 86 | -------------------------------------------------------------------------------- /man/pthread_attr_set_getschedpolicy.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2004-2007 Apple Inc. All rights reserved. 2 | .Dd December 31, 2007 3 | .Dt PTHREAD_ATTR 3 4 | .Os 5 | .Sh NAME 6 | .Nm pthread_attr_getschedpolicy , 7 | .Nm pthread_attr_setschedpolicy 8 | .Nd thread attribute operations 9 | .Sh SYNOPSIS 10 | .Fd #include 11 | .Ft int 12 | .Fo pthread_attr_getschedpolicy 13 | .Fa "const pthread_attr_t *restrict attr" 14 | .Fa "int *restrict policy" 15 | .Fc 16 | .Ft int 17 | .Fo pthread_attr_setschedpolicy 18 | .Fa "pthread_attr_t *attr" 19 | .Fa "int policy" 20 | .Fc 21 | .Sh DESCRIPTION 22 | Thread attributes are used to specify parameters to 23 | .Fn pthread_create . 24 | One attribute object can be used in multiple calls to 25 | .Fn pthread_create , 26 | with or without modifications between calls. 27 | .Pp 28 | The functions 29 | .Fn pthread_attr_setschedpolicy 30 | and 31 | .Fn pthread_attr_getschedpolicy , 32 | set and get the attribute in the 33 | .Fa attr 34 | argument related to the scheduling policy. 35 | The value for the aforementioned attribute can be SCHED_FIFO, SCHED_RR and SCHED_OTHER. 36 | .Sh RETURN VALUES 37 | If successful, these functions return 0. 38 | Otherwise, an error number is returned to indicate the error. 39 | .Fn pthread_attr_getschedpolicy , 40 | on success, will copy the value of the thread's scheduling policy attribute 41 | to the location pointed to by the second function parameter. 42 | .Sh ERRORS 43 | .Pp 44 | .Fn pthread_attr_getschedpolicy 45 | will fail if: 46 | .Bl -tag -width Er 47 | .\" ======== 48 | .It Bq Er EINVAL 49 | Invalid value for 50 | .Fa attr . 51 | .El 52 | .Pp 53 | .Fn pthread_attr_setschedpolicy 54 | will fail if: 55 | .Bl -tag -width Er 56 | .\" ======== 57 | .It Bq Er EINVAL 58 | Invalid value for 59 | .Fa attr . 60 | .It Bq Er ENOTSUP 61 | Invalid or unsupported value for 62 | .Fa policy . 63 | .El 64 | .Sh SEE ALSO 65 | .Xr pthread_create 3 , 66 | .Xr pthread_attr_init 3 , 67 | .Xr pthread_attr_setschedparam 3 , 68 | .Xr pthread_attr_setinheritsched 3 69 | .Sh STANDARDS 70 | .Fn pthread_attr_setschedpolicy , 71 | .Fn pthread_attr_getschedpolicy 72 | conform to 73 | .St -susv2 74 | -------------------------------------------------------------------------------- /man/pthread_attr_set_getscope.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2004-2007 Apple Inc. All rights reserved. 2 | .Dd December 31, 2007 3 | .Dt PTHREAD_ATTR 3 4 | .Os 5 | .Sh NAME 6 | .Nm pthread_attr_getscope , 7 | .Nm pthread_attr_setscope 8 | .Nd thread attribute operations 9 | .Sh SYNOPSIS 10 | .Fd #include 11 | .Ft int 12 | .Fo pthread_attr_getscope 13 | .Fa "const pthread_attr_t *restrict attr" 14 | .Fa "int *restrict contentionscope" 15 | .Fc 16 | .Ft int 17 | .Fo pthread_attr_setscope 18 | .Fa "pthread_attr_t *attr" 19 | .Fa "int contentionscope" 20 | .Fc 21 | .Sh DESCRIPTION 22 | Thread attributes are used to specify parameters to 23 | .Fn pthread_create . 24 | One attribute object can be used in multiple calls to 25 | .Fn pthread_create , 26 | with or without modifications between calls. 27 | .Pp 28 | The 29 | .Fn pthread_attr_setscope 30 | and 31 | .Fn pthread_attr_getscope 32 | functions, respectively, set and get the attribute within 33 | .Fa attr 34 | argument that controls the contention scope of the thread. 35 | The acceptable values are PTHREAD_SCOPE_SYSTEM, indicating a scheduling contention scope that 36 | is system-wide, and PTHREAD_SCOPE_PROCESS, which indicates a process scheduling contention scope. 37 | Currently on Mac OS X we only support PTHREAD_SCOPE_SYSTEM. 38 | .Sh RETURN VALUES 39 | If successful, these functions return 0. 40 | Otherwise, an error number is returned to indicate the error. 41 | .Sh ERRORS 42 | .Pp 43 | .Fn pthread_attr_getscope 44 | will fail if: 45 | .Bl -tag -width Er 46 | .\" ======== 47 | .It Bq Er EINVAL 48 | Invalid value for 49 | .Fa attr . 50 | .\" ======== 51 | .El 52 | .Pp 53 | .Fn pthread_attr_setscope 54 | will fail if: 55 | .Bl -tag -width Er 56 | .\" ======== 57 | .It Bq Er EINVAL 58 | Invalid value for 59 | .Fa attr . 60 | .\" ======== 61 | .It Bq Er ENOTSUP 62 | Invalid or unsupported value for 63 | .Fa contentionscope . 64 | .El 65 | .Sh SEE ALSO 66 | .Xr pthread_create 3 , 67 | .Xr pthread_attr_init 3 , 68 | .Xr pthread_attr_setinheritsched 3 , 69 | .Xr pthread_attr_setschedpolicy 3 , 70 | .Xr pthread_attr_setschedparam 3 71 | .Sh STANDARDS 72 | .Fn pthread_attr_setscope , 73 | .Fn pthread_attr_getscope 74 | conform to 75 | .St -susv2 76 | -------------------------------------------------------------------------------- /man/pthread_attr_set_getstackaddr.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2004-2007 Apple Inc. All rights reserved. 2 | .Dd December 31, 2007 3 | .Dt PTHREAD_ATTR 3 4 | .Os 5 | .Sh NAME 6 | .Nm pthread_attr_getstackaddr , 7 | .Nm pthread_attr_setstackaddr 8 | .Nd thread attribute operations 9 | .Sh SYNOPSIS 10 | .Fd #include 11 | .Ft int 12 | .Fo pthread_attr_getstackaddr 13 | .Fa "const pthread_attr_t *restrict attr" 14 | .Fa "void **restrict stackaddr" 15 | .Fc 16 | .Ft int 17 | .Fo pthread_attr_setstackaddr 18 | .Fa "pthread_attr_t *attr" 19 | .Fa "void *stackaddr" 20 | .Fc 21 | .Sh DESCRIPTION 22 | Thread attributes are used to specify parameters to 23 | .Fn pthread_create . 24 | One attribute object can be used in multiple calls to 25 | .Fn pthread_create , 26 | with or without modifications between calls. 27 | .Pp 28 | The functions 29 | .Fn pthread_attr_setstackaddr 30 | and 31 | .Fn pthread_attr_getstackaddr 32 | respectively, set and get the address at which the stack of the newly created thread should be located. 33 | The stackaddr attribute is set within the 34 | .Fa attr 35 | argument, which can subsequently be used as an argument to 36 | .Fn pthread_create . 37 | .Sh RETURN VALUES 38 | If successful, these functions return 0. 39 | Otherwise, an error number is returned to indicate the error. 40 | .Fn pthread_attr_getstackaddr 41 | returns the stackaddr attribute value in 42 | .Fa stackaddr 43 | if successful. 44 | .Sh ERRORS 45 | .Fn pthread_attr_setstackaddr 46 | will fail if: 47 | .Bl -tag -width Er 48 | .\" ======== 49 | .It Bq Er EINVAL 50 | Invalid value for 51 | .Fa attr . 52 | .\" ======== 53 | .El 54 | .Pp 55 | .Fn pthread_attr_getstackaddr 56 | will fail if: 57 | .Bl -tag -width Er 58 | .\" ======== 59 | .It Bq Er EINVAL 60 | Invalid value for 61 | .Fa attr . 62 | .\" ======== 63 | .El 64 | .Pp 65 | .Sh SEE ALSO 66 | .Xr pthread_create 3 , 67 | .Xr pthread_attr_init 3 , 68 | .Xr pthread_attr_setdetachstate 3 , 69 | .Xr pthread_attr_setstacksize 3 70 | .Sh STANDARDS 71 | .Fn pthread_attr_setstackaddr , 72 | .Fn pthread_attr_getstackaddr , 73 | conform to 74 | .St -p1003.1-96 75 | -------------------------------------------------------------------------------- /man/pthread_attr_set_getstacksize.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2004-2007 Apple Inc. All rights reserved. 2 | .Dd December 31, 2007 3 | .Dt PTHREAD_ATTR 3 4 | .Os 5 | .Sh NAME 6 | .Nm pthread_attr_getstacksize , 7 | .Nm pthread_attr_setstacksize 8 | .Nd thread attribute operations 9 | .Sh SYNOPSIS 10 | .Fd #include 11 | .Ft int 12 | .Fo pthread_attr_getstacksize 13 | .Fa "const pthread_attr_t *restrict attr" 14 | .Fa "size_t *restrict stacksize" 15 | .Fc 16 | .Ft int 17 | .Fo pthread_attr_setstacksize 18 | .Fa "pthread_attr_t *attr" 19 | .Fa "size_t stacksize" 20 | .Fc 21 | .Sh DESCRIPTION 22 | Thread attributes are used to specify parameters to 23 | .Fn pthread_create . 24 | One attribute object can be used in multiple calls to 25 | .Fn pthread_create , 26 | with or without modifications between calls. 27 | .Pp 28 | The functions 29 | .Fn pthread_attr_setstacksize 30 | and 31 | .Fn pthread_attr_getstacksize , 32 | respectively, set and get the size of the stack that is to be created for the new thread. The stack size attribute is set within the 33 | .Fa attr 34 | argument, which can subsequently be used as an argument to 35 | .Fn pthread_create . 36 | .Sh RETURN VALUES 37 | If successful, these functions return 0. 38 | Otherwise, an error number is returned to indicate the error. 39 | .Fn pthread_attr_getstacksize 40 | returns the stacksize attribute value in 41 | .Fa stacksize 42 | if successful. 43 | .Sh ERRORS 44 | .Fn pthread_attr_getstacksize 45 | will fail if: 46 | .Bl -tag -width Er 47 | .\" ======== 48 | .It Bq Er EINVAL 49 | Invalid value for 50 | .Fa attr . 51 | .El 52 | .Pp 53 | .Fn pthread_attr_setstacksize 54 | will fail if: 55 | .Bl -tag -width Er 56 | .\" ======== 57 | .It Bq Er EINVAL 58 | Invalid value for 59 | .Fa attr . 60 | .\" ======== 61 | .It Bq Er EINVAL 62 | .Fa stacksize 63 | is less than 64 | .Dv PTHREAD_STACK_MIN . 65 | .\" ======== 66 | .It Bq Er EINVAL 67 | .Fa stacksize 68 | is not a multiple of the system page size. 69 | .El 70 | .Sh SEE ALSO 71 | .Xr pthread_create 3 , 72 | .Xr pthread_attr_init 3 , 73 | .Xr pthread_attr_setstackaddr 3 74 | .Sh STANDARDS 75 | .Fn pthread_attr_setstacksize , 76 | .Fn pthread_attr_getstacksize 77 | conform to 78 | .St -p1003.1-96 79 | -------------------------------------------------------------------------------- /man/pthread_cancel.3: -------------------------------------------------------------------------------- 1 | .\" $FreeBSD$ 2 | .Dd January 17, 1999 3 | .Dt PTHREAD_CANCEL 3 4 | .Os 5 | .Sh NAME 6 | .Nm pthread_cancel 7 | .Nd cancel execution of a thread 8 | .Sh SYNOPSIS 9 | .In pthread.h 10 | .Ft int 11 | .Fn pthread_cancel "pthread_t thread" 12 | .Sh DESCRIPTION 13 | The 14 | .Fn pthread_cancel 15 | function requests that 16 | .Fa thread 17 | be canceled. 18 | The target thread's cancelability state and type determines 19 | when the cancellation takes effect. 20 | When the cancellation is acted on, 21 | the cancellation cleanup handlers for 22 | .Fa thread 23 | are called. 24 | When the last cancellation cleanup handler returns, 25 | the thread-specific data destructor functions will be called for 26 | .Fa thread . 27 | When the last destructor function returns, 28 | .Fa thread 29 | will be terminated. 30 | .Pp 31 | The cancellation processing in the target thread runs asynchronously with 32 | respect to the calling thread returning from 33 | .Fn pthread_cancel . 34 | .Pp 35 | A status of 36 | .Dv PTHREAD_CANCELED 37 | is made available to any threads joining with the target. 38 | The symbolic 39 | constant 40 | .Dv PTHREAD_CANCELED 41 | expands to a constant expression of type 42 | .Ft "(void *)" , 43 | whose value matches no pointer to an object in memory nor the value 44 | .Dv NULL . 45 | .Sh RETURN VALUES 46 | If successful, the 47 | .Fn pthread_cancel 48 | functions will return zero. 49 | Otherwise an error number will be returned to 50 | indicate the error. 51 | .Sh ERRORS 52 | The 53 | .Fn pthread_cancel 54 | function will fail if: 55 | .Bl -tag -width Er 56 | .It Bq Er ESRCH 57 | No thread could be found corresponding to that specified by the given 58 | thread ID. 59 | .El 60 | .Sh SEE ALSO 61 | .Xr pthread_cleanup_pop 3 , 62 | .Xr pthread_cleanup_push 3 , 63 | .Xr pthread_exit 3 , 64 | .Xr pthread_join 3 , 65 | .Xr pthread_setcancelstate 3 , 66 | .Xr pthread_setcanceltype 3 , 67 | .Xr pthread_testcancel 3 68 | .Sh STANDARDS 69 | The 70 | .Fn pthread_cancel 71 | function conforms to 72 | .St -p1003.1-96 . 73 | .Sh AUTHORS 74 | This manual page was written by 75 | .An David Leonard Aq Mt d@openbsd.org 76 | for the 77 | .Ox 78 | implementation of 79 | .Fn pthread_cancel . 80 | -------------------------------------------------------------------------------- /man/pthread_cleanup_pop.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1997 Brian Cully 2 | .\" All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 3. Neither the name of the author nor the names of any co-contributors 13 | .\" may be used to endorse or promote products derived from this software 14 | .\" without specific prior written permission. 15 | .\" 16 | .\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 17 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | .\" SUCH DAMAGE. 27 | .\" 28 | .\" $FreeBSD$ 29 | .\" 30 | .Dd October 25, 2014 31 | .Dt PTHREAD_CLEANUP_POP 3 32 | .Os 33 | .Sh NAME 34 | .Nm pthread_cleanup_pop 35 | .Nd call the first cleanup routine 36 | .Sh SYNOPSIS 37 | .In pthread.h 38 | .Ft void 39 | .Fn pthread_cleanup_pop "int execute" 40 | .Sh DESCRIPTION 41 | The 42 | .Fn pthread_cleanup_pop 43 | function pops the top cleanup routine off of the current threads cleanup 44 | routine stack, and, if 45 | .Fa execute 46 | is non-zero, it will execute the function. 47 | If there is no cleanup routine 48 | then 49 | .Fn pthread_cleanup_pop 50 | does nothing. 51 | .Pp 52 | The 53 | .Fn pthread_cleanup_pop 54 | function is implemented as a macro that closes a block. 55 | Invocations of this function must appear as standalone statements that are 56 | paired with an earlier call of 57 | .Xr pthread_cleanup_push 3 58 | in the same lexical scope. 59 | .Sh RETURN VALUES 60 | The 61 | .Fn pthread_cleanup_pop 62 | function does not return any value. 63 | .Sh ERRORS 64 | None 65 | .Sh SEE ALSO 66 | .Xr pthread_cleanup_push 3 , 67 | .Xr pthread_exit 3 68 | .Sh STANDARDS 69 | The 70 | .Fn pthread_cleanup_pop 71 | function conforms to 72 | .St -p1003.1-96 . 73 | -------------------------------------------------------------------------------- /man/pthread_cleanup_push.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1997 Brian Cully 2 | .\" All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 3. Neither the name of the author nor the names of any co-contributors 13 | .\" may be used to endorse or promote products derived from this software 14 | .\" without specific prior written permission. 15 | .\" 16 | .\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 17 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | .\" SUCH DAMAGE. 27 | .\" 28 | .\" $FreeBSD$ 29 | .\" 30 | .Dd October 25, 2014 31 | .Dt PTHREAD_CLEANUP_PUSH 3 32 | .Os 33 | .Sh NAME 34 | .Nm pthread_cleanup_push 35 | .Nd add a cleanup function for thread exit 36 | .Sh SYNOPSIS 37 | .In pthread.h 38 | .Ft void 39 | .Fn pthread_cleanup_push "void \*[lp]*cleanup_routine\*[rp]\*[lp]void *\*[rp]" "void *arg" 40 | .Sh DESCRIPTION 41 | The 42 | .Fn pthread_cleanup_push 43 | function adds 44 | .Fa cleanup_routine 45 | to the top of the stack of cleanup handlers that 46 | get called when the current thread exits. 47 | .Pp 48 | When 49 | .Fa cleanup_routine 50 | is called, it is passed 51 | .Fa arg 52 | as its only argument. 53 | .Pp 54 | The 55 | .Fn pthread_cleanup_push 56 | function is implemented as a macro that opens a new block. 57 | Invocations of this function must appear as standalone statements that are 58 | paired with a later call of 59 | .Xr pthread_cleanup_pop 3 60 | in the same lexical scope. 61 | .Sh RETURN VALUES 62 | The 63 | .Fn pthread_cleanup_push 64 | function does not return any value. 65 | .Sh ERRORS 66 | None 67 | .Sh SEE ALSO 68 | .Xr pthread_cleanup_pop 3 , 69 | .Xr pthread_exit 3 70 | .Sh STANDARDS 71 | The 72 | .Fn pthread_cleanup_push 73 | function conforms to 74 | .St -p1003.1-96 . 75 | -------------------------------------------------------------------------------- /man/pthread_cond_broadcast.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1997 Brian Cully 2 | .\" All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 3. Neither the name of the author nor the names of any co-contributors 13 | .\" may be used to endorse or promote products derived from this software 14 | .\" without specific prior written permission. 15 | .\" 16 | .\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 17 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | .\" SUCH DAMAGE. 27 | .\" 28 | .\" $FreeBSD$ 29 | .\" 30 | .Dd July 28, 1998 31 | .Dt PTHREAD_COND_BROADCAST 3 32 | .Os 33 | .Sh NAME 34 | .Nm pthread_cond_broadcast 35 | .Nd unblock all threads waiting for a condition variable 36 | .Sh SYNOPSIS 37 | .In pthread.h 38 | .Ft int 39 | .Fn pthread_cond_broadcast "pthread_cond_t *cond" 40 | .Sh DESCRIPTION 41 | The 42 | .Fn pthread_cond_broadcast 43 | function unblocks all threads waiting for the condition variable 44 | .Fa cond . 45 | .Sh RETURN VALUES 46 | If successful, the 47 | .Fn pthread_cond_broadcast 48 | function will return zero, otherwise an error number will be returned 49 | to indicate the error. 50 | .Sh ERRORS 51 | The 52 | .Fn pthread_cond_broadcast 53 | function will fail if: 54 | .Bl -tag -width Er 55 | .It Bq Er EINVAL 56 | The value specified by 57 | .Fa cond 58 | is invalid. 59 | .El 60 | .Sh SEE ALSO 61 | .Xr pthread_cond_destroy 3 , 62 | .Xr pthread_cond_init 3 , 63 | .Xr pthread_cond_signal 3 , 64 | .Xr pthread_cond_timedwait 3 , 65 | .Xr pthread_cond_wait 3 66 | .Sh STANDARDS 67 | The 68 | .Fn pthread_cond_broadcast 69 | function conforms to 70 | .St -p1003.1-96 . 71 | -------------------------------------------------------------------------------- /man/pthread_cond_destroy.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1997 Brian Cully 2 | .\" All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 3. Neither the name of the author nor the names of any co-contributors 13 | .\" may be used to endorse or promote products derived from this software 14 | .\" without specific prior written permission. 15 | .\" 16 | .\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 17 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | .\" SUCH DAMAGE. 27 | .\" 28 | .\" $FreeBSD$ 29 | .\" 30 | .Dd July 28, 1998 31 | .Dt PTHREAD_COND_DESTROY 3 32 | .Os 33 | .Sh NAME 34 | .Nm pthread_cond_destroy 35 | .Nd destroy a condition variable 36 | .Sh SYNOPSIS 37 | .In pthread.h 38 | .Ft int 39 | .Fn pthread_cond_destroy "pthread_cond_t *cond" 40 | .Sh DESCRIPTION 41 | The 42 | .Fn pthread_cond_destroy 43 | function frees the resources allocated by the condition variable 44 | .Fa cond . 45 | .Sh RETURN VALUES 46 | If successful, the 47 | .Fn pthread_cond_destroy 48 | function will return zero, otherwise an error number will be returned 49 | to indicate the error. 50 | .Sh ERRORS 51 | The 52 | .Fn pthread_cond_destroy 53 | function will fail if: 54 | .Bl -tag -width Er 55 | .It Bq Er EINVAL 56 | The value specified by 57 | .Fa cond 58 | is invalid. 59 | .It Bq Er EBUSY 60 | The variable 61 | .Fa cond 62 | is locked by another thread. 63 | .El 64 | .Sh SEE ALSO 65 | .Xr pthread_cond_broadcast 3 , 66 | .Xr pthread_cond_init 3 , 67 | .Xr pthread_cond_signal 3 , 68 | .Xr pthread_cond_timedwait 3 , 69 | .Xr pthread_cond_wait 3 70 | .Sh STANDARDS 71 | The 72 | .Fn pthread_cond_destroy 73 | function conforms to 74 | .St -p1003.1-96 . 75 | -------------------------------------------------------------------------------- /man/pthread_cond_init.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1997 Brian Cully 2 | .\" All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 3. Neither the name of the author nor the names of any co-contributors 13 | .\" may be used to endorse or promote products derived from this software 14 | .\" without specific prior written permission. 15 | .\" 16 | .\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 17 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | .\" SUCH DAMAGE. 27 | .\" 28 | .\" $FreeBSD$ 29 | .\" 30 | .Dd November 4, 2006 31 | .Dt PTHREAD_COND_INIT 3 32 | .Os 33 | .Sh NAME 34 | .Nm pthread_cond_init 35 | .Nd create a condition variable 36 | .Sh SYNOPSIS 37 | .In pthread.h 38 | .Ft int 39 | .Fn pthread_cond_init "pthread_cond_t *cond" "const pthread_condattr_t *attr" 40 | .Sh DESCRIPTION 41 | The 42 | .Fn pthread_cond_init 43 | function creates a new condition variable, with attributes specified with 44 | .Fa attr . 45 | If 46 | .Fa attr 47 | is NULL the default attributes are used. 48 | .Sh RETURN VALUES 49 | If successful, the 50 | .Fn pthread_cond_init 51 | function will return zero and put the new condition variable id into 52 | .Fa cond , 53 | otherwise an error number will be returned to indicate the error. 54 | .Sh ERRORS 55 | The 56 | .Fn pthread_cond_init 57 | function will fail if: 58 | .Bl -tag -width Er 59 | .It Bq Er EINVAL 60 | The value specified by 61 | .Fa attr 62 | is invalid. 63 | .It Bq Er ENOMEM 64 | The process cannot allocate enough memory to create another condition 65 | variable. 66 | .It Bq Er EAGAIN 67 | The system temporarily lacks the resources to create another condition 68 | variable. 69 | .El 70 | .Sh SEE ALSO 71 | .Xr pthread_cond_broadcast 3 , 72 | .Xr pthread_cond_destroy 3 , 73 | .Xr pthread_cond_signal 3 , 74 | .Xr pthread_cond_timedwait 3 , 75 | .Xr pthread_cond_wait 3 , 76 | .Xr pthread_condattr 3 77 | .Sh STANDARDS 78 | The 79 | .Fn pthread_cond_init 80 | function conforms to 81 | .St -p1003.1-96 . 82 | -------------------------------------------------------------------------------- /man/pthread_cond_signal.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1997 Brian Cully 2 | .\" All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 3. Neither the name of the author nor the names of any co-contributors 13 | .\" may be used to endorse or promote products derived from this software 14 | .\" without specific prior written permission. 15 | .\" 16 | .\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 17 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | .\" SUCH DAMAGE. 27 | .\" 28 | .\" $FreeBSD$ 29 | .\" 30 | .Dd July 28, 1998 31 | .Dt PTHREAD_COND_SIGNAL 3 32 | .Os 33 | .Sh NAME 34 | .Nm pthread_cond_signal 35 | .Nd unblock a thread waiting for a condition variable 36 | .Sh SYNOPSIS 37 | .In pthread.h 38 | .Ft int 39 | .Fn pthread_cond_signal "pthread_cond_t *cond" 40 | .Sh DESCRIPTION 41 | The 42 | .Fn pthread_cond_signal 43 | function unblocks one thread waiting for the condition variable 44 | .Fa cond . 45 | .Sh RETURN VALUES 46 | If successful, the 47 | .Fn pthread_cond_signal 48 | function will return zero, otherwise an error number will be returned 49 | to indicate the error. 50 | .Sh ERRORS 51 | The 52 | .Fn pthread_cond_signal 53 | function will fail if: 54 | .Bl -tag -width Er 55 | .It Bq Er EINVAL 56 | The value specified by 57 | .Fa cond 58 | is invalid. 59 | .El 60 | .Sh SEE ALSO 61 | .Xr pthread_cond_broadcast 3 , 62 | .Xr pthread_cond_destroy 3 , 63 | .Xr pthread_cond_init 3 , 64 | .Xr pthread_cond_timedwait 3 , 65 | .Xr pthread_cond_wait 3 66 | .Sh STANDARDS 67 | The 68 | .Fn pthread_cond_signal 69 | function conforms to 70 | .St -p1003.1-96 . 71 | -------------------------------------------------------------------------------- /man/pthread_cond_wait.3: -------------------------------------------------------------------------------- 1 | .\" Portions Copyright (c) 2001 Apple Computer, Inc. All Rights Reserved. 2 | .\" Copyright (c) 1997 Brian Cully 3 | .\" All rights reserved. 4 | .\" 5 | .\" Redistribution and use in source and binary forms, with or without 6 | .\" modification, are permitted provided that the following conditions 7 | .\" are met: 8 | .\" 1. Redistributions of source code must retain the above copyright 9 | .\" notice, this list of conditions and the following disclaimer. 10 | .\" 2. Redistributions in binary form must reproduce the above copyright 11 | .\" notice, this list of conditions and the following disclaimer in the 12 | .\" documentation and/or other materials provided with the distribution. 13 | .\" 3. Neither the name of the author nor the names of any co-contributors 14 | .\" may be used to endorse or promote products derived from this software 15 | .\" without specific prior written permission. 16 | .\" 17 | .\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 18 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | .\" SUCH DAMAGE. 28 | .\" 29 | .\" $FreeBSD$ 30 | .\" 31 | .Dd February 16, 2006 32 | .Dt PTHREAD_COND_WAIT 3 33 | .Os Darwin 34 | .Sh NAME 35 | .Nm pthread_cond_wait 36 | .Nd wait on a condition variable 37 | .Sh SYNOPSIS 38 | .In pthread.h 39 | .Ft int 40 | .Fn pthread_cond_wait "pthread_cond_t *cond" "pthread_mutex_t *mutex" 41 | .Sh DESCRIPTION 42 | The 43 | .Fn pthread_cond_wait 44 | function atomically blocks the current thread waiting on the condition 45 | variable specified by 46 | .Fa cond , 47 | and releases the mutex specified by 48 | .Fa mutex . 49 | The waiting thread unblocks only after another thread calls 50 | .Xr pthread_cond_signal 3 , 51 | or 52 | .Xr pthread_cond_broadcast 3 53 | with the same condition variable, and the current thread reacquires the lock 54 | on 55 | .Fa mutex . 56 | .Sh RETURN VALUES 57 | If successful, the 58 | .Fn pthread_cond_wait 59 | function will return zero. 60 | Otherwise an error number will be returned to 61 | indicate the error. 62 | .Sh ERRORS 63 | The 64 | .Fn pthread_cond_wait 65 | function will fail if: 66 | .Bl -tag -width Er 67 | .It Bq Er EINVAL 68 | The value specified by 69 | .Fa cond 70 | or the value specified by 71 | .Fa mutex 72 | is invalid. 73 | .El 74 | .Sh SEE ALSO 75 | .Xr pthread_cond_broadcast 3 , 76 | .Xr pthread_cond_destroy 3 , 77 | .Xr pthread_cond_init 3 , 78 | .Xr pthread_cond_signal 3 , 79 | .Xr pthread_cond_timedwait 3 80 | .Sh STANDARDS 81 | The 82 | .Fn pthread_cond_wait 83 | function conforms to 84 | .St -p1003.1-96 . 85 | -------------------------------------------------------------------------------- /man/pthread_condattr.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2000 Jason Evans . 2 | .\" All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice(s), this list of conditions and the following disclaimer as 9 | .\" the first lines of this file unmodified other than the possible 10 | .\" addition of one or more copyright notices. 11 | .\" 2. Redistributions in binary form must reproduce the above copyright 12 | .\" notice(s), this list of conditions and the following disclaimer in 13 | .\" the documentation and/or other materials provided with the 14 | .\" distribution. 15 | .\" 16 | .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY 17 | .\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE 20 | .\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 | .\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25 | .\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 26 | .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | .\" 28 | .\" $FreeBSD$ 29 | .Dd May 9, 2010 30 | .Dt PTHREAD_CONDATTR 3 31 | .Os 32 | .Sh NAME 33 | .Nm pthread_condattr_init , 34 | .Nm pthread_condattr_destroy , 35 | .Nd condition attribute operations 36 | .Sh SYNOPSIS 37 | .In pthread.h 38 | .Ft int 39 | .Fn pthread_condattr_init "pthread_condattr_t *attr" 40 | .Ft int 41 | .Fn pthread_condattr_destroy "pthread_condattr_t *attr" 42 | .Sh DESCRIPTION 43 | Condition attribute objects are used to specify parameters to 44 | .Fn pthread_cond_init . 45 | .Fx Ns 's 46 | implementation of conditions does not support any non-default 47 | attributes, so these functions are not very useful, though they are required to 48 | to be present by 49 | .Tn POSIX . 50 | .Pp 51 | The 52 | .Fn pthread_condattr_init 53 | function initializes a condition attribute object with the default attributes. 54 | .Pp 55 | The 56 | .Fn pthread_condattr_destroy 57 | function destroys a condition attribute object. 58 | .Sh RETURN VALUES 59 | If successful, these functions return 0. 60 | Otherwise, an error number is returned to indicate the error. 61 | .Sh ERRORS 62 | .Fn pthread_condattr_destroy 63 | will fail if: 64 | .Bl -tag -width Er 65 | .It Bq Er EINVAL 66 | Invalid value for 67 | .Fa attr . 68 | .El 69 | .Pp 70 | .Fn pthread_condattr_init 71 | will fail if: 72 | .Bl -tag -width Er 73 | .It Bq Er ENOMEM 74 | Out of memory. 75 | .El 76 | .Sh SEE ALSO 77 | .Xr pthread_cond_init 3 78 | .Sh STANDARDS 79 | The 80 | .Fn pthread_condattr_init 81 | and 82 | .Fn pthread_condattr_destroy 83 | functions conform to 84 | .St -p1003.1-96 85 | -------------------------------------------------------------------------------- /man/pthread_equal.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1996 John Birrell . 2 | .\" All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 3. All advertising materials mentioning features or use of this software 13 | .\" must display the following acknowledgement: 14 | .\" This product includes software developed by John Birrell. 15 | .\" 4. Neither the name of the author nor the names of any co-contributors 16 | .\" may be used to endorse or promote products derived from this software 17 | .\" without specific prior written permission. 18 | .\" 19 | .\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 20 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | .\" SUCH DAMAGE. 30 | .\" 31 | .\" $FreeBSD$ 32 | .\" 33 | .Dd April 4, 1996 34 | .Dt PTHREAD_EQUAL 3 35 | .Os 36 | .Sh NAME 37 | .Nm pthread_equal 38 | .Nd compare thread IDs 39 | .Sh SYNOPSIS 40 | .In pthread.h 41 | .Ft int 42 | .Fn pthread_equal "pthread_t t1" "pthread_t t2" 43 | .Sh DESCRIPTION 44 | The 45 | .Fn pthread_equal 46 | function compares the thread IDs 47 | .Fa t1 48 | and 49 | .Fa t2 . 50 | .Sh RETURN VALUES 51 | The 52 | .Fn pthread_equal 53 | function will return non-zero if the thread IDs 54 | .Fa t1 55 | and 56 | .Fa t2 57 | correspond to the same thread, otherwise it will return zero. 58 | .Sh ERRORS 59 | None. 60 | .Sh SEE ALSO 61 | .Xr pthread_create 3 , 62 | .Xr pthread_exit 3 63 | .Sh STANDARDS 64 | The 65 | .Fn pthread_equal 66 | function conforms to 67 | .St -p1003.1-96 . 68 | -------------------------------------------------------------------------------- /man/pthread_getspecific.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1996 John Birrell . 2 | .\" All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 3. All advertising materials mentioning features or use of this software 13 | .\" must display the following acknowledgement: 14 | .\" This product includes software developed by John Birrell. 15 | .\" 4. Neither the name of the author nor the names of any co-contributors 16 | .\" may be used to endorse or promote products derived from this software 17 | .\" without specific prior written permission. 18 | .\" 19 | .\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 20 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | .\" SUCH DAMAGE. 30 | .\" 31 | .\" $FreeBSD$ 32 | .\" 33 | .Dd April 4, 1996 34 | .Dt PTHREAD_GETSPECIFIC 3 35 | .Os 36 | .Sh NAME 37 | .Nm pthread_getspecific 38 | .Nd get a thread-specific data value 39 | .Sh SYNOPSIS 40 | .In pthread.h 41 | .Ft void * 42 | .Fn pthread_getspecific "pthread_key_t key" 43 | .Sh DESCRIPTION 44 | The 45 | .Fn pthread_getspecific 46 | function returns the value currently bound to the specified 47 | .Fa key 48 | on behalf of the calling thread. 49 | .Pp 50 | The effect of calling 51 | .Fn pthread_getspecific 52 | with a 53 | .Fa key 54 | value not obtained from 55 | .Fn pthread_key_create 56 | or after 57 | .Fa key 58 | has been deleted with 59 | .Fn pthread_key_delete 60 | is undefined. 61 | .Pp 62 | The 63 | .Fn pthread_getspecific 64 | function may be called from a thread-specific data destructor function. 65 | .Sh RETURN VALUES 66 | The 67 | .Fn pthread_getspecific 68 | function will return the thread-specific data value associated with the given 69 | .Fa key . 70 | If no thread-specific data value is associated with 71 | .Fa key , 72 | then the value NULL is returned. 73 | .Sh ERRORS 74 | None. 75 | .Sh SEE ALSO 76 | .Xr pthread_key_create 3 , 77 | .Xr pthread_key_delete 3 , 78 | .Xr pthread_setspecific 3 79 | .Sh STANDARDS 80 | The 81 | .Fn pthread_getspecific 82 | function conforms to 83 | .St -p1003.1-96 . 84 | -------------------------------------------------------------------------------- /man/pthread_kill.2: -------------------------------------------------------------------------------- 1 | .\" Darwin 2 | .\" 3 | .\" Copyright (C) 2000 Jason Evans . 4 | .\" All rights reserved. 5 | .\" 6 | .\" Redistribution and use in source and binary forms, with or without 7 | .\" modification, are permitted provided that the following conditions 8 | .\" are met: 9 | .\" 1. Redistributions of source code must retain the above copyright 10 | .\" notice(s), this list of conditions and the following disclaimer as 11 | .\" the first lines of this file unmodified other than the possible 12 | .\" addition of one or more copyright notices. 13 | .\" 2. Redistributions in binary form must reproduce the above copyright 14 | .\" notice(s), this list of conditions and the following disclaimer in 15 | .\" the documentation and/or other materials provided with the 16 | .\" distribution. 17 | .\" 18 | .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY 19 | .\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE 22 | .\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 25 | .\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 | .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 27 | .\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 28 | .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | .\" 30 | .\" $FreeBSD: src/lib/libc_r/man/pthread_kill.3,v 1.8 2001/10/01 16:09:09 ru Exp $ 31 | .Dd Feb 05, 2002 32 | .Dt PTHREAD_KILL 2 33 | .Os 34 | .Sh NAME 35 | .Nm pthread_kill 36 | .Nd send a signal to a specified thread 37 | .Sh SYNOPSIS 38 | .In signal.h 39 | .Ft int 40 | .Fn pthread_kill "pthread_t thread" "int sig" 41 | .Sh DESCRIPTION 42 | The 43 | .Fn pthread_kill 44 | function sends a signal, specified by 45 | .Fa sig , 46 | to a thread, specified by 47 | .Fa thread . 48 | If 49 | .Fa sig 50 | is 0, error checking is performed, but no signal is actually sent. 51 | .Sh RETURN VALUES 52 | If successful, 53 | .Fn pthread_kill 54 | returns 0. 55 | Otherwise, an error number is returned. 56 | .Sh ERRORS 57 | The 58 | .Fn pthread_kill 59 | function will fail if: 60 | .Bl -tag -width Er 61 | .It Bq Er ESRCH 62 | .Fa thread 63 | is an invalid thread ID. 64 | .It Bq Er EINVAL 65 | .Fa sig 66 | is an invalid or unsupported signal number. 67 | .It Bq Er ENOTSUP 68 | .Fa thread 69 | was not created by 70 | .Fn pthread_create 71 | and does not support being killed with 72 | .Fn pthread_kill 73 | .El 74 | .Sh LEGACY SYNOPSIS 75 | .Fd #include 76 | .Fd #include 77 | .Pp 78 | The include file 79 | .In pthread.h 80 | is necessary. 81 | .Sh SEE ALSO 82 | .Xr kill 2 , 83 | .Xr pthread_self 3 , 84 | .Xr raise 3 , 85 | .Xr compat 5 86 | .Sh STANDARDS 87 | .Fn pthread_kill 88 | conforms to ISO/IEC 9945-1:1996 (``POSIX.1'') 89 | -------------------------------------------------------------------------------- /man/pthread_main_np.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2003 Alexey Zelkin 2 | .\" All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 13 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 | .\" SUCH DAMAGE. 24 | .\" 25 | .\" $FreeBSD$ 26 | .\" 27 | .Dd February 13, 2003 28 | .Dt PTHREAD_MAIN_NP 3 29 | .Os 30 | .Sh NAME 31 | .Nm pthread_main_np 32 | .Nd identify the initial thread 33 | .Sh SYNOPSIS 34 | .In pthread.h 35 | .Ft int 36 | .Fn pthread_main_np void 37 | .Sh DESCRIPTION 38 | The 39 | .Fn pthread_main_np 40 | function 41 | is to identify the initial thread. 42 | .Sh RETURN VALUES 43 | The 44 | .Fn pthread_main_np 45 | function returns 46 | 1 if the calling thread is the initial thread, 47 | 0 if the calling thread is not the initial thread, 48 | and \-1 if the thread's initialization has not yet completed. 49 | .Sh SEE ALSO 50 | .Xr pthread_create 3 , 51 | .Xr pthread_equal 3 , 52 | .Xr pthread_self 3 53 | .Sh AUTHORS 54 | This manual page was written by 55 | .An Alexey Zelkin Aq Mt phantom@FreeBSD.org . 56 | -------------------------------------------------------------------------------- /man/pthread_mutex_destroy.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1997 Brian Cully 2 | .\" All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 3. Neither the name of the author nor the names of any co-contributors 13 | .\" may be used to endorse or promote products derived from this software 14 | .\" without specific prior written permission. 15 | .\" 16 | .\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 17 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | .\" SUCH DAMAGE. 27 | .\" 28 | .\" $FreeBSD$ 29 | .\" 30 | .Dd July 29, 1998 31 | .Dt PTHREAD_MUTEX_DESTROY 3 32 | .Os 33 | .Sh NAME 34 | .Nm pthread_mutex_destroy 35 | .Nd free resources allocated for a mutex 36 | .Sh SYNOPSIS 37 | .In pthread.h 38 | .Ft int 39 | .Fn pthread_mutex_destroy "pthread_mutex_t *mutex" 40 | .Sh DESCRIPTION 41 | The 42 | .Fn pthread_mutex_destroy 43 | function frees the resources allocated for 44 | .Fa mutex . 45 | .Sh RETURN VALUES 46 | If successful, 47 | .Fn pthread_mutex_destroy 48 | will return zero, otherwise an error number will be returned to 49 | indicate the error. 50 | .Sh ERRORS 51 | The 52 | .Fn pthread_mutex_destroy 53 | function will fail if: 54 | .Bl -tag -width Er 55 | .It Bq Er EINVAL 56 | The value specified by 57 | .Fa mutex 58 | is invalid. 59 | .It Bq Er EBUSY 60 | .Fa Mutex 61 | is locked. 62 | .El 63 | .Sh SEE ALSO 64 | .Xr pthread_mutex_init 3 , 65 | .Xr pthread_mutex_lock 3 , 66 | .Xr pthread_mutex_trylock 3 , 67 | .Xr pthread_mutex_unlock 3 68 | .Sh STANDARDS 69 | The 70 | .Fn pthread_mutex_destroy 71 | function conforms to 72 | .St -p1003.1-96 . 73 | -------------------------------------------------------------------------------- /man/pthread_mutex_init.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1997 Brian Cully 2 | .\" All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 3. Neither the name of the author nor the names of any co-contributors 13 | .\" may be used to endorse or promote products derived from this software 14 | .\" without specific prior written permission. 15 | .\" 16 | .\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 17 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | .\" SUCH DAMAGE. 27 | .\" 28 | .\" $FreeBSD$ 29 | .\" 30 | .Dd November 4, 2006 31 | .Dt PTHREAD_MUTEX_INIT 3 32 | .Os 33 | .Sh NAME 34 | .Nm pthread_mutex_init 35 | .Nd create a mutex 36 | .Sh SYNOPSIS 37 | .In pthread.h 38 | .Ft int 39 | .Fn pthread_mutex_init "pthread_mutex_t *mutex" "const pthread_mutexattr_t *attr" 40 | .Sh DESCRIPTION 41 | The 42 | .Fn pthread_mutex_init 43 | function creates a new mutex, with attributes specified with 44 | .Fa attr . 45 | If 46 | .Fa attr 47 | is NULL the default attributes are used. 48 | .Sh RETURN VALUES 49 | If successful, 50 | .Fn pthread_mutex_init 51 | will return zero and put the new mutex id into 52 | .Fa mutex , 53 | otherwise an error number will be returned to indicate the error. 54 | .Sh ERRORS 55 | The 56 | .Fn pthread_mutex_init 57 | function will fail if: 58 | .Bl -tag -width Er 59 | .It Bq Er EINVAL 60 | The value specified by 61 | .Fa attr 62 | is invalid. 63 | .It Bq Er ENOMEM 64 | The process cannot allocate enough memory to create another mutex. 65 | .El 66 | .Sh SEE ALSO 67 | .Xr pthread_mutex_destroy 3 , 68 | .Xr pthread_mutex_lock 3 , 69 | .Xr pthread_mutex_trylock 3 , 70 | .Xr pthread_mutex_unlock 3 , 71 | .Xr pthread_mutexattr 3 72 | .Sh STANDARDS 73 | The 74 | .Fn pthread_mutex_init 75 | function conforms to 76 | .St -p1003.1-96 . 77 | -------------------------------------------------------------------------------- /man/pthread_mutex_lock.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1997 Brian Cully 2 | .\" All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 3. Neither the name of the author nor the names of any co-contributors 13 | .\" may be used to endorse or promote products derived from this software 14 | .\" without specific prior written permission. 15 | .\" 16 | .\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 17 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | .\" SUCH DAMAGE. 27 | .\" 28 | .\" $FreeBSD$ 29 | .\" 30 | .Dd January 31, 2006 31 | .Dt PTHREAD_MUTEX_LOCK 3 32 | .Os 33 | .Sh NAME 34 | .Nm pthread_mutex_lock 35 | .Nd lock a mutex 36 | .Sh SYNOPSIS 37 | .In pthread.h 38 | .Ft int 39 | .Fn pthread_mutex_lock "pthread_mutex_t *mutex" 40 | .Sh DESCRIPTION 41 | The 42 | .Fn pthread_mutex_lock 43 | function locks 44 | .Fa mutex . 45 | If the mutex is already locked, the calling thread will block until the 46 | mutex becomes available. 47 | .Sh RETURN VALUES 48 | If successful, 49 | .Fn pthread_mutex_lock 50 | will return zero, otherwise an error number will be returned to 51 | indicate the error. 52 | .Sh ERRORS 53 | The 54 | .Fn pthread_mutex_lock 55 | function will fail if: 56 | .Bl -tag -width Er 57 | .It Bq Er EINVAL 58 | The value specified by 59 | .Fa mutex 60 | is invalid. 61 | .It Bq Er EDEADLK 62 | A deadlock would occur if the thread blocked waiting for 63 | .Fa mutex . 64 | .El 65 | .Sh SEE ALSO 66 | .Xr pthread_mutex_destroy 3 , 67 | .Xr pthread_mutex_init 3 , 68 | .Xr pthread_mutex_trylock 3 , 69 | .Xr pthread_mutex_unlock 3 70 | .Sh STANDARDS 71 | The 72 | .Fn pthread_mutex_lock 73 | function conforms to 74 | .St -p1003.1-96 . 75 | -------------------------------------------------------------------------------- /man/pthread_mutex_trylock.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1997 Brian Cully 2 | .\" All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 3. Neither the name of the author nor the names of any co-contributors 13 | .\" may be used to endorse or promote products derived from this software 14 | .\" without specific prior written permission. 15 | .\" 16 | .\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 17 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | .\" SUCH DAMAGE. 27 | .\" 28 | .\" $FreeBSD$ 29 | .\" 30 | .Dd July 30, 1998 31 | .Dt PTHREAD_MUTEX_TRYLOCK 3 32 | .Os 33 | .Sh NAME 34 | .Nm pthread_mutex_trylock 35 | .Nd attempt to lock a mutex without blocking 36 | .Sh SYNOPSIS 37 | .In pthread.h 38 | .Ft int 39 | .Fn pthread_mutex_trylock "pthread_mutex_t *mutex" 40 | .Sh DESCRIPTION 41 | The 42 | .Fn pthread_mutex_trylock 43 | function locks 44 | .Fa mutex . 45 | If the mutex is already locked, 46 | .Fn pthread_mutex_trylock 47 | will not block waiting for the mutex, but will return an error condition. 48 | .Sh RETURN VALUES 49 | If successful, 50 | .Fn pthread_mutex_trylock 51 | will return zero, otherwise an error number will be returned to 52 | indicate the error. 53 | .Sh ERRORS 54 | The 55 | .Fn pthread_mutex_trylock 56 | function will fail if: 57 | .Bl -tag -width Er 58 | .It Bq Er EINVAL 59 | The value specified by 60 | .Fa mutex 61 | is invalid. 62 | .It Bq Er EBUSY 63 | .Fa Mutex 64 | is already locked. 65 | .El 66 | .Sh SEE ALSO 67 | .Xr pthread_mutex_destroy 3 , 68 | .Xr pthread_mutex_init 3 , 69 | .Xr pthread_mutex_lock 3 , 70 | .Xr pthread_mutex_unlock 3 71 | .Sh STANDARDS 72 | The 73 | .Fn pthread_mutex_trylock 74 | function conforms to 75 | .St -p1003.1-96 . 76 | -------------------------------------------------------------------------------- /man/pthread_mutex_unlock.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1997 Brian Cully 2 | .\" All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 3. Neither the name of the author nor the names of any co-contributors 13 | .\" may be used to endorse or promote products derived from this software 14 | .\" without specific prior written permission. 15 | .\" 16 | .\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 17 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | .\" SUCH DAMAGE. 27 | .\" 28 | .\" $FreeBSD$ 29 | .\" 30 | .Dd July 30, 1998 31 | .Dt PTHREAD_MUTEX_UNLOCK 3 32 | .Os 33 | .Sh NAME 34 | .Nm pthread_mutex_unlock 35 | .Nd unlock a mutex 36 | .Sh SYNOPSIS 37 | .In pthread.h 38 | .Ft int 39 | .Fn pthread_mutex_unlock "pthread_mutex_t *mutex" 40 | .Sh DESCRIPTION 41 | If the current thread holds the lock on 42 | .Fa mutex , 43 | then the 44 | .Fn pthread_mutex_unlock 45 | function unlocks 46 | .Fa mutex . 47 | .Pp 48 | Calling 49 | .Fn pthread_mutex_unlock 50 | with a 51 | .Fa mutex 52 | that the calling thread does not hold will result 53 | in undefined behavior. 54 | .Sh RETURN VALUES 55 | If successful, 56 | .Fn pthread_mutex_unlock 57 | will return zero, otherwise an error number will be returned to 58 | indicate the error. 59 | .Sh ERRORS 60 | The 61 | .Fn pthread_mutex_unlock 62 | function will fail if: 63 | .Bl -tag -width Er 64 | .It Bq Er EINVAL 65 | The value specified by 66 | .Fa mutex 67 | is invalid. 68 | .It Bq Er EPERM 69 | The current thread does not hold a lock on 70 | .Fa mutex . 71 | .El 72 | .Sh SEE ALSO 73 | .Xr pthread_mutex_destroy 3 , 74 | .Xr pthread_mutex_init 3 , 75 | .Xr pthread_mutex_lock 3 , 76 | .Xr pthread_mutex_trylock 3 77 | .Sh STANDARDS 78 | The 79 | .Fn pthread_mutex_unlock 80 | function conforms to 81 | .St -p1003.1-96 . 82 | -------------------------------------------------------------------------------- /man/pthread_rwlock_destroy.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1998 Alex Nash 2 | .\" All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 13 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 | .\" SUCH DAMAGE. 24 | .\" 25 | .\" $FreeBSD$ 26 | .\" 27 | .Dd August 4, 1998 28 | .Dt PTHREAD_RWLOCK_DESTROY 3 29 | .Os 30 | .Sh NAME 31 | .Nm pthread_rwlock_destroy 32 | .Nd destroy a read/write lock 33 | .Sh SYNOPSIS 34 | .In pthread.h 35 | .Ft int 36 | .Fn pthread_rwlock_destroy "pthread_rwlock_t *lock" 37 | .Sh DESCRIPTION 38 | The 39 | .Fn pthread_rwlock_destroy 40 | function is used to destroy a read/write lock previously created with 41 | .Fn pthread_rwlock_init . 42 | .Sh RETURN VALUES 43 | If successful, the 44 | .Fn pthread_rwlock_destroy 45 | function will return zero. 46 | Otherwise an error number will be returned 47 | to indicate the error. 48 | .Sh ERRORS 49 | The 50 | .Fn pthread_rwlock_destroy 51 | function will fail if: 52 | .Bl -tag -width Er 53 | .It Bq Er EPERM 54 | The caller does not have the privilege to perform the operation. 55 | .El 56 | .Pp 57 | The 58 | .Fn pthread_rwlock_destroy 59 | function may fail if: 60 | .Bl -tag -width Er 61 | .It Bq Er EBUSY 62 | The system has detected an attempt to destroy the object referenced by 63 | .Fa lock 64 | while it is locked. 65 | .It Bq Er EINVAL 66 | The value specified by 67 | .Fa lock 68 | is invalid. 69 | .El 70 | .Sh SEE ALSO 71 | .Xr pthread_rwlock_init 3 72 | .Sh STANDARDS 73 | The 74 | .Fn pthread_rwlock_destroy 75 | function is expected to conform to 76 | .St -susv2 . 77 | .Sh HISTORY 78 | The 79 | .Fn pthread_rwlock_destroy 80 | function first appeared in 81 | .Fx 3.0 . 82 | -------------------------------------------------------------------------------- /man/pthread_rwlock_unlock.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1998 Alex Nash 2 | .\" All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 13 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 | .\" SUCH DAMAGE. 24 | .\" 25 | .\" $FreeBSD$ 26 | .\" 27 | .Dd August 4, 1998 28 | .Dt PTHREAD_RWLOCK_UNLOCK 3 29 | .Os 30 | .Sh NAME 31 | .Nm pthread_rwlock_unlock 32 | .Nd release a read/write lock 33 | .Sh SYNOPSIS 34 | .In pthread.h 35 | .Ft int 36 | .Fn pthread_rwlock_unlock "pthread_rwlock_t *lock" 37 | .Sh DESCRIPTION 38 | The 39 | .Fn pthread_rwlock_unlock 40 | function is used to release the read/write lock previously obtained by 41 | .Fn pthread_rwlock_rdlock , 42 | .Fn pthread_rwlock_wrlock , 43 | .Fn pthread_rwlock_tryrdlock , 44 | or 45 | .Fn pthread_rwlock_trywrlock . 46 | .Sh RETURN VALUES 47 | If successful, the 48 | .Fn pthread_rwlock_unlock 49 | function will return zero. 50 | Otherwise an error number will be returned 51 | to indicate the error. 52 | .Pp 53 | The results are undefined if 54 | .Fa lock 55 | is not held by the calling thread. 56 | .Sh ERRORS 57 | The 58 | .Fn pthread_rwlock_unlock 59 | function may fail if: 60 | .Bl -tag -width Er 61 | .It Bq Er EINVAL 62 | The value specified by 63 | .Fa lock 64 | is invalid. 65 | .It Bq Er EPERM 66 | The current thread does not own the read/write lock. 67 | .El 68 | .Sh SEE ALSO 69 | .Xr pthread_rwlock_rdlock 3 , 70 | .Xr pthread_rwlock_wrlock 3 71 | .Sh STANDARDS 72 | The 73 | .Fn pthread_rwlock_unlock 74 | function is expected to conform to 75 | .St -susv2 . 76 | .Sh HISTORY 77 | The 78 | .Fn pthread_rwlock_unlock 79 | function first appeared in 80 | .Fx 3.0 . 81 | -------------------------------------------------------------------------------- /man/pthread_rwlockattr_destroy.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1998 Alex Nash 2 | .\" All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 13 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 | .\" SUCH DAMAGE. 24 | .\" 25 | .\" $FreeBSD$ 26 | .\" 27 | .Dd August 4, 1998 28 | .Dt PTHREAD_RWLOCKATTR_DESTROY 3 29 | .Os 30 | .Sh NAME 31 | .Nm pthread_rwlockattr_destroy 32 | .Nd destroy a read/write lock 33 | .Sh SYNOPSIS 34 | .In pthread.h 35 | .Ft int 36 | .Fn pthread_rwlockattr_destroy "pthread_rwlockattr_t *attr" 37 | .Sh DESCRIPTION 38 | The 39 | .Fn pthread_rwlockattr_destroy 40 | function is used to destroy a read/write lock attribute object 41 | previously created with 42 | .Fn pthread_rwlockattr_init . 43 | .Sh RETURN VALUES 44 | If successful, the 45 | .Fn pthread_rwlockattr_destroy 46 | function will return zero. 47 | Otherwise an error number will be returned 48 | to indicate the error. 49 | .Sh ERRORS 50 | The 51 | .Fn pthread_rwlockattr_destroy 52 | function may fail if: 53 | .Bl -tag -width Er 54 | .It Bq Er EINVAL 55 | The value specified by 56 | .Fa attr 57 | is invalid. 58 | .El 59 | .Sh SEE ALSO 60 | .Xr pthread_rwlockattr_init 3 61 | .Sh STANDARDS 62 | The 63 | .Fn pthread_rwlockattr_destroy 64 | function is expected to conform to 65 | .St -susv2 . 66 | .Sh HISTORY 67 | The 68 | .Fn pthread_rwlockattr_destroy 69 | function first appeared in 70 | .Fx 3.0 . 71 | -------------------------------------------------------------------------------- /man/pthread_rwlockattr_getpshared.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1998 Alex Nash 2 | .\" All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 13 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 | .\" SUCH DAMAGE. 24 | .\" 25 | .\" $FreeBSD$ 26 | .\" 27 | .Dd March 22, 1999 28 | .Dt PTHREAD_RWLOCKATTR_GETPSHARED 3 29 | .Os 30 | .Sh NAME 31 | .Nm pthread_rwlockattr_getpshared 32 | .Nd get the process shared attribute 33 | .Sh SYNOPSIS 34 | .In pthread.h 35 | .Ft int 36 | .Fn pthread_rwlockattr_getpshared "const pthread_rwlockattr_t *attr" "int *pshared" 37 | .Sh DESCRIPTION 38 | The 39 | .Fn pthread_rwlockattr_getpshared 40 | function is used to get the process shared setting of a read/write 41 | lock attribute object. 42 | The setting is returned via 43 | .Fa pshared , 44 | and may be one of two values: 45 | .Bl -tag -width PTHREAD_PROCESS_PRIVATE 46 | .It Dv PTHREAD_PROCESS_SHARED 47 | Any thread of any process that has access to the memory where the 48 | read/write lock resides can manipulate the lock. 49 | .It Dv PTHREAD_PROCESS_PRIVATE 50 | Only threads created within the same process as the thread that 51 | initialized the read/write lock can manipulate the lock. 52 | This is 53 | the default value. 54 | .El 55 | .Sh RETURN VALUES 56 | If successful, the 57 | .Fn pthread_rwlockattr_getpshared 58 | function will return zero. 59 | Otherwise an error number will be returned 60 | to indicate the error. 61 | .Sh ERRORS 62 | The 63 | .Fn pthread_rwlockattr_getpshared 64 | function may fail if: 65 | .Bl -tag -width Er 66 | .It Bq Er EINVAL 67 | The value specified by 68 | .Fa attr 69 | is invalid. 70 | .El 71 | .Sh SEE ALSO 72 | .Xr pthread_rwlock_init 3 , 73 | .Xr pthread_rwlockattr_init 3 , 74 | .Xr pthread_rwlockattr_setpshared 3 75 | .Sh STANDARDS 76 | The 77 | .Fn pthread_rwlockattr_getpshared 78 | function is expected to conform to 79 | .St -susv2 . 80 | .Sh HISTORY 81 | The 82 | .Fn pthread_rwlockattr_getpshared 83 | function first appeared in 84 | .Fx 3.0 . 85 | -------------------------------------------------------------------------------- /man/pthread_rwlockattr_init.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1998 Alex Nash 2 | .\" All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 13 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 | .\" SUCH DAMAGE. 24 | .\" 25 | .\" $FreeBSD$ 26 | .\" 27 | .Dd August 4, 1998 28 | .Dt PTHREAD_RWLOCKATTR_INIT 3 29 | .Os 30 | .Sh NAME 31 | .Nm pthread_rwlockattr_init 32 | .Nd initialize a read/write lock 33 | .Sh SYNOPSIS 34 | .In pthread.h 35 | .Ft int 36 | .Fn pthread_rwlockattr_init "pthread_rwlockattr_t *attr" 37 | .Sh DESCRIPTION 38 | The 39 | .Fn pthread_rwlockattr_init 40 | function is used to initialize a read/write lock attributes object. 41 | .Sh RETURN VALUES 42 | If successful, the 43 | .Fn pthread_rwlockattr_init 44 | function will return zero. 45 | Otherwise an error number will be returned 46 | to indicate the error. 47 | .Sh ERRORS 48 | The 49 | .Fn pthread_rwlockattr_init 50 | function will fail if: 51 | .Bl -tag -width Er 52 | .It Bq Er ENOMEM 53 | Insufficient memory exists to initialize the attribute object. 54 | .El 55 | .Sh SEE ALSO 56 | .Xr pthread_rwlock_init 3 , 57 | .Xr pthread_rwlockattr_destroy 3 , 58 | .Xr pthread_rwlockattr_getpshared 3 , 59 | .Xr pthread_rwlockattr_setpshared 3 60 | .Sh STANDARDS 61 | The 62 | .Fn pthread_rwlockattr_init 63 | function is expected to conform to 64 | .St -susv2 . 65 | .Sh HISTORY 66 | The 67 | .Fn pthread_rwlockattr_init 68 | function first appeared in 69 | .Fx 3.0 . 70 | -------------------------------------------------------------------------------- /man/pthread_self.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1996 John Birrell . 2 | .\" All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 3. All advertising materials mentioning features or use of this software 13 | .\" must display the following acknowledgement: 14 | .\" This product includes software developed by John Birrell. 15 | .\" 4. Neither the name of the author nor the names of any co-contributors 16 | .\" may be used to endorse or promote products derived from this software 17 | .\" without specific prior written permission. 18 | .\" 19 | .\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 20 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | .\" SUCH DAMAGE. 30 | .\" 31 | .\" $FreeBSD$ 32 | .\" 33 | .Dd April 4, 1996 34 | .Dt PTHREAD_SELF 3 35 | .Os 36 | .Sh NAME 37 | .Nm pthread_self 38 | .Nd get the calling thread's ID 39 | .Sh SYNOPSIS 40 | .In pthread.h 41 | .Ft pthread_t 42 | .Fn pthread_self "void" 43 | .Sh DESCRIPTION 44 | The 45 | .Fn pthread_self 46 | function returns the thread ID of the calling thread. 47 | .Sh RETURN VALUES 48 | The 49 | .Fn pthread_self 50 | function returns the thread ID of the calling thread. 51 | .Sh ERRORS 52 | None. 53 | .Sh SEE ALSO 54 | .Xr pthread_create 3 , 55 | .Xr pthread_equal 3 56 | .Sh STANDARDS 57 | The 58 | .Fn pthread_self 59 | function conforms to 60 | .St -p1003.1-96 . 61 | -------------------------------------------------------------------------------- /man/pthread_setname_np.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2003 Alexey Zelkin 2 | .\" All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 13 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 | .\" SUCH DAMAGE. 24 | .\" 25 | .\" $FreeBSD$ 26 | .\" 27 | .Dd February 13, 2003 28 | .Dt PTHREAD_SETNAME_NP 3 29 | .Os 30 | .Sh NAME 31 | .Nm pthread_setname_np 32 | .Nd set the thread name 33 | .Sh SYNOPSIS 34 | .In pthread.h 35 | .Ft void 36 | .Fn pthread_setname_np "const char *name" 37 | .Sh DESCRIPTION 38 | The 39 | .Fn pthread_setname_np 40 | function sets the internal name for the calling thread to string value specified by 41 | .Fa name 42 | argument. 43 | .Sh AUTHORS 44 | This manual page was written by 45 | .An Alexey Zelkin Aq Mt phantom@FreeBSD.org . 46 | -------------------------------------------------------------------------------- /man/pthread_threadid_np.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2016 Apple Inc. All rights reserved. 2 | .\" 3 | .\" @APPLE_LICENSE_HEADER_START@ 4 | .\" 5 | .\" This file contains Original Code and/or Modifications of Original Code 6 | .\" as defined in and that are subject to the Apple Public Source License 7 | .\" Version 2.0 (the 'License'). You may not use this file except in 8 | .\" compliance with the License. Please obtain a copy of the License at 9 | .\" http://www.opensource.apple.com/apsl/ and read it before using this 10 | .\" file. 11 | .\" 12 | .\" The Original Code and all software distributed under the License are 13 | .\" distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 14 | .\" EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 15 | .\" INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 16 | .\" FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 17 | .\" Please see the License for the specific language governing rights and 18 | .\" limitations under the License. 19 | .\" 20 | .\" @APPLE_LICENSE_HEADER_END@ 21 | .\" 22 | .Dd April 12, 2016 23 | .Dt PTHREAD_THREADID_NP 3 24 | .Os 25 | .Sh NAME 26 | .Nm pthread_threadid_np 27 | .Nd get the calling thread's unique ID 28 | .Sh SYNOPSIS 29 | .In pthread.h 30 | .Ft int 31 | .Fn pthread_threadid_np "pthread_t thread" "uint64_t *thread_id" 32 | .Sh DESCRIPTION 33 | The 34 | .Fn pthread_threadid_np 35 | function stores the system-wide unique integral ID of 36 | .Fa thread 37 | in the location spedified by 38 | .Fa thread_id . 39 | If 40 | .Fa thread 41 | is NULL, the ID of the current thread is provided. 42 | .Sh RETURN VALUES 43 | If successful, the 44 | .Fn pthread_threadid_np 45 | function will return zero. Otherwise an error number will be returned to 46 | indicate the error. 47 | .Sh ERRORS 48 | The 49 | .Fn pthread_threadid_np 50 | function will fail if: 51 | .Bl -tag -width Er 52 | .It Bq Er EINVAL 53 | NULL value for 54 | .Fa thread_id . 55 | .It Bq Er ESRCH 56 | Non-existent thread 57 | .Fa thread . 58 | .El 59 | .Sh SEE ALSO 60 | .Xr pthread_self 3 61 | -------------------------------------------------------------------------------- /man/pthread_yield_np.3: -------------------------------------------------------------------------------- 1 | .\" $OpenBSD: pthread_yield.3,v 1.3 2004/01/25 14:48:32 jmc Exp $ 2 | .\" 3 | .\" PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman 4 | .\" 5 | .\" $FreeBSD$ 6 | .\" 7 | .Dd September 18, 2006 8 | .Dt PTHREAD_YIELD_NP 3 9 | .Os 10 | .Sh NAME 11 | .Nm pthread_yield_np 12 | .Nd yield control of the current thread 13 | .Sh SYNOPSIS 14 | .In pthread.h 15 | .Ft void 16 | .Fn pthread_yield_np void 17 | .Sh DESCRIPTION 18 | The 19 | .Fn pthread_yield 20 | causes the running thread to relinquish the processor. 21 | -------------------------------------------------------------------------------- /private/pthread/introspection_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, 2016 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | 24 | #ifndef __PTHREAD_INTROSPECTION_PRIVATE__ 25 | #define __PTHREAD_INTROSPECTION_PRIVATE__ 26 | 27 | #include 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /private/pthread/jit_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | 24 | #ifndef __PTHREAD_JIT_PRIVATE_H__ 25 | #define __PTHREAD_JIT_PRIVATE_H__ 26 | 27 | #include 28 | 29 | /* all content moved to pthread.h */ 30 | 31 | #endif /* __PTHREAD_JIT_PRIVATE_H__ */ 32 | -------------------------------------------------------------------------------- /private/pthread/posix_sched.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | /* 24 | * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 25 | * All Rights Reserved 26 | * 27 | * Permission to use, copy, modify, and distribute this software and 28 | * its documentation for any purpose and without fee is hereby granted, 29 | * provided that the above copyright notice appears in all copies and 30 | * that both the copyright notice and this permission notice appear in 31 | * supporting documentation. 32 | * 33 | * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE 34 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | * FOR A PARTICULAR PURPOSE. 36 | * 37 | * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR 38 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 39 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, 40 | * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 41 | * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 42 | * 43 | */ 44 | /* 45 | * MkLinux 46 | */ 47 | 48 | /* 49 | * POSIX Realtime Scheduling Framework - IEEE 1003.1b 50 | */ 51 | 52 | #ifndef _POSIX_SCHED_H 53 | #define _POSIX_SCHED_H 54 | 55 | #ifdef __POSIX_LIB__ 56 | 57 | #include 58 | 59 | struct sched_param 60 | { 61 | int sched_priority; 62 | int quantum; 63 | }; 64 | 65 | /* 66 | * POSIX scheduling policies 67 | */ 68 | 69 | #define SCHED_OTHER POLICY_TIMESHARE 70 | #define SCHED_FIFO POLICY_FIFO 71 | #define SCHED_RR POLICY_RR 72 | 73 | #endif /* __POSIX_LIB__ */ 74 | 75 | #endif /* _POSIX_SCHED_H */ 76 | -------------------------------------------------------------------------------- /private/sys/qos_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | 24 | #ifndef _QOS_SYS_PRIVATE_H 25 | #define _QOS_SYS_PRIVATE_H 26 | 27 | /*! 28 | * @constant QOS_CLASS_MAINTENANCE 29 | * @abstract A QOS class which indicates work performed by this thread was not 30 | * initiated by the user and that the user may be unaware of the results. 31 | * @discussion Such work is requested to run at a priority far below other work 32 | * including significant I/O throttling. The use of this QOS class indicates 33 | * the work should be run in the most energy and thermally-efficient manner 34 | * possible, and may be deferred for a long time in order to preserve 35 | * system responsiveness for the user. 36 | * This is SPI for use by Spotlight and Time Machine only. 37 | */ 38 | #define QOS_CLASS_MAINTENANCE ((qos_class_t)0x05) 39 | 40 | #endif //_QOS_SYS_PRIVATE_H 41 | -------------------------------------------------------------------------------- /src/offsets_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | 24 | #ifndef _POSIX_PTHREAD_OFFSETS_H 25 | #define _POSIX_PTHREAD_OFFSETS_H 26 | 27 | #if defined(__i386__) 28 | #define _PTHREAD_STRUCT_DIRECT_STACKADDR_OFFSET 140 29 | #define _PTHREAD_STRUCT_DIRECT_STACKBOTTOM_OFFSET 144 30 | #elif __LP64__ 31 | #define _PTHREAD_STRUCT_DIRECT_STACKADDR_OFFSET -48 32 | #define _PTHREAD_STRUCT_DIRECT_STACKBOTTOM_OFFSET -40 33 | #else 34 | #define _PTHREAD_STRUCT_DIRECT_STACKADDR_OFFSET -36 35 | #define _PTHREAD_STRUCT_DIRECT_STACKBOTTOM_OFFSET -32 36 | #endif 37 | 38 | #ifndef __ASSEMBLER__ 39 | #include "pthread/private.h" // for other _PTHREAD_STRUCT_DIRECT_*_OFFSET 40 | 41 | #define check_backward_offset(field, value) \ 42 | _Static_assert(offsetof(struct pthread_s, tsd) + value == \ 43 | offsetof(struct pthread_s, field), #value " is correct") 44 | #define check_forward_offset(field, value) \ 45 | _Static_assert(offsetof(struct pthread_s, field) == value, \ 46 | #value " is correct") 47 | 48 | check_forward_offset(tsd, _PTHREAD_STRUCT_DIRECT_TSD_OFFSET); 49 | check_backward_offset(thread_id, _PTHREAD_STRUCT_DIRECT_THREADID_OFFSET); 50 | #if defined(__i386__) 51 | check_forward_offset(stackaddr, _PTHREAD_STRUCT_DIRECT_STACKADDR_OFFSET); 52 | check_forward_offset(stackbottom, _PTHREAD_STRUCT_DIRECT_STACKBOTTOM_OFFSET); 53 | #else 54 | check_backward_offset(stackaddr, _PTHREAD_STRUCT_DIRECT_STACKADDR_OFFSET); 55 | check_backward_offset(stackbottom, _PTHREAD_STRUCT_DIRECT_STACKBOTTOM_OFFSET); 56 | #endif 57 | 58 | #endif // __ASSEMBLER__ 59 | 60 | #endif /* _POSIX_PTHREAD_OFFSETS_H */ 61 | -------------------------------------------------------------------------------- /src/plockstat.d: -------------------------------------------------------------------------------- 1 | typedef struct _opaque_pthread_mutex_t pthread_mutex_t; 2 | typedef struct _opaque_pthread_rwlock_t pthread_rwlock_t; 3 | 4 | provider plockstat { 5 | probe mutex__acquire(pthread_mutex_t *mutex, int recursive, int spin_count); 6 | probe mutex__release(pthread_mutex_t *mutex, int recursive); 7 | probe mutex__error(pthread_mutex_t *mutex, int errno); 8 | probe mutex__block(pthread_mutex_t *mutex); 9 | probe mutex__blocked(pthread_mutex_t *mutex, int successful); 10 | probe mutex__spin(pthread_mutex_t *mutex); 11 | probe mutex__spun(pthread_mutex_t *mutex, int successful, int spin_count); 12 | 13 | probe rw__acquire(pthread_rwlock_t *rwlock, int write_lock); 14 | probe rw__block(pthread_rwlock_t *rwlock, int write_lock); 15 | probe rw__blocked(pthread_rwlock_t *rwlock, int write_lock, int successful); 16 | probe rw__release(pthread_rwlock_t *rwlock, int write_lock); 17 | probe rw__error(pthread_rwlock_t *rwlock, int write_lock, int error); 18 | }; 19 | 20 | #pragma D attributes Evolving/Evolving/ISA provider plockstat provider 21 | #pragma D attributes Private/Private/Unknown provider plockstat module 22 | #pragma D attributes Private/Private/Unknown provider plockstat function 23 | #pragma D attributes Evolving/Evolving/ISA provider plockstat name 24 | #pragma D attributes Evolving/Evolving/ISA provider plockstat args 25 | -------------------------------------------------------------------------------- /src/pthread_cwd.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | 24 | #include "internal.h" 25 | 26 | int 27 | pthread_chdir_np(const char *path) 28 | { 29 | return __pthread_chdir(path); 30 | } 31 | 32 | int 33 | pthread_fchdir_np(int fd) 34 | { 35 | return __pthread_fchdir(fd); 36 | } 37 | -------------------------------------------------------------------------------- /src/resolver/resolver.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_APACHE_LICENSE_HEADER_START@ 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | * @APPLE_APACHE_LICENSE_HEADER_END@ 19 | */ 20 | 21 | 22 | struct _os_empty_files_are_not_c_files; 23 | -------------------------------------------------------------------------------- /src/resolver/resolver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_APACHE_LICENSE_HEADER_START@ 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | * @APPLE_APACHE_LICENSE_HEADER_END@ 19 | */ 20 | 21 | #ifndef __PTHREAD_RESOLVER_H__ 22 | #define __PTHREAD_RESOLVER_H__ 23 | 24 | #include "resolver_internal.h" 25 | 26 | 27 | #endif // __PTHREAD_RESOLVER_H__ 28 | -------------------------------------------------------------------------------- /src/resolver/resolver_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_APACHE_LICENSE_HEADER_START@ 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | * @APPLE_APACHE_LICENSE_HEADER_END@ 19 | */ 20 | 21 | #ifndef __PTHREAD_RESOLVER_INTERNAL_H__ 22 | #define __PTHREAD_RESOLVER_INTERNAL_H__ 23 | 24 | 25 | #endif // __PTHREAD_RESOLVER_INTERNAL_H__ 26 | -------------------------------------------------------------------------------- /src/variants/pthread_cancelable_cancel.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | 24 | #define BUILDING_VARIANT 1 25 | #define VARIANT_CANCELABLE 1 26 | 27 | #undef __DARWIN_NON_CANCELABLE 28 | #define __DARWIN_NON_CANCELABLE 0 29 | 30 | #include "../pthread_cancelable.c" 31 | -------------------------------------------------------------------------------- /tests/add_timer_termination.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | #include "darwintest_defaults.h" 22 | #include 23 | 24 | extern void __exit(int) __attribute__((noreturn)); 25 | 26 | static void __attribute__((noreturn)) 27 | run_add_timer_termination(void) 28 | { 29 | const int SOURCES = 32; 30 | static unsigned int time_to_sleep; time_to_sleep = (unsigned int)(arc4random() % 5000 + 500); 31 | 32 | static int pipes[SOURCES][2]; 33 | static dispatch_source_t s[SOURCES]; 34 | for (int i = 0; i < SOURCES; i++) { 35 | pipe(pipes[i]); 36 | s[i] = dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, (uintptr_t)pipes[i][0], 0, NULL); 37 | dispatch_source_set_event_handler(s[i], ^{ 38 | while(1) pause(); 39 | }); 40 | dispatch_resume(s[i]); 41 | } 42 | 43 | dispatch_async(dispatch_get_global_queue(0,0), ^{ 44 | for (int i = 1; i < SOURCES; i++){ 45 | write(pipes[i][1], &SOURCES, 1); 46 | usleep(1); 47 | } 48 | while(1) pause(); 49 | }); 50 | 51 | usleep(time_to_sleep); 52 | __exit(0); 53 | } 54 | 55 | T_DECL(add_timer_termination, "termination during add timer", 56 | T_META_CHECK_LEAKS(NO)) 57 | { 58 | const int ROUNDS = 128; 59 | const int TIMEOUT = 5; 60 | for (int i = 0; i < ROUNDS; i++){ 61 | pid_t pid = fork(); 62 | T_QUIET; T_ASSERT_POSIX_SUCCESS(pid, "fork"); 63 | if (pid == 0) { // child 64 | run_add_timer_termination(); 65 | } else { // parent 66 | bool success = dt_waitpid(pid, NULL, NULL, TIMEOUT); 67 | T_ASSERT_TRUE(success, "Child %d exits successfully", i); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /tests/com.apple.libpthread.tests.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BATSConfigVersion 6 | 0.1.0 7 | Project 8 | libpthread.workqueue.tests 9 | Tests 10 | 11 | 12 | Command 13 | 14 | /AppleInternal/Tests/libpthread/wq_cooperative 15 | 16 | TestName 17 | libpthread.workqueue.wq_cooperative 18 | AsRoot 19 | 20 | WorkingDirectory 21 | /AppleInternal/Tests/libpthread 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /tests/custom_stack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "darwintest_defaults.h" 8 | 9 | 10 | static uintptr_t stackaddr; 11 | static const size_t stacksize = 4096 * 8; 12 | 13 | static void *function(void *arg) { 14 | // Use the stack... 15 | char buffer[BUFSIZ]; 16 | strlcpy(buffer, arg, sizeof(buffer)); 17 | strlcat(buffer, arg, sizeof(buffer)); 18 | 19 | T_ASSERT_LT((uintptr_t)__builtin_frame_address(0), stackaddr, NULL); 20 | T_ASSERT_GT((uintptr_t)__builtin_frame_address(0), stackaddr - stacksize, NULL); 21 | 22 | return (void *)(uintptr_t)strlen(buffer); 23 | } 24 | 25 | T_DECL(custom_stack, "creating a pthread with a custom stack", 26 | T_META_ALL_VALID_ARCHS(YES)){ 27 | char *arg = "This is a test and only a test of the pthread stackaddr system.\n"; 28 | stackaddr = (uintptr_t)valloc(stacksize); 29 | stackaddr += stacksize; // address starts at top of stack. 30 | 31 | pthread_t thread; 32 | pthread_attr_t attr; 33 | 34 | T_ASSERT_POSIX_ZERO(pthread_attr_init(&attr), NULL); 35 | T_ASSERT_POSIX_ZERO(pthread_attr_setstacksize(&attr, stacksize), NULL); 36 | T_ASSERT_POSIX_ZERO(pthread_attr_setstackaddr(&attr, (void *)stackaddr), NULL); 37 | 38 | T_ASSERT_POSIX_ZERO(pthread_create(&thread, &attr, function, arg), NULL); 39 | 40 | void *result; 41 | T_ASSERT_POSIX_ZERO(pthread_join(thread, &result), NULL); 42 | T_ASSERT_EQ((uintptr_t)result, (uintptr_t)strlen(arg)*2, "thread should return correct value"); 43 | 44 | free((void*)(stackaddr - stacksize)); 45 | } 46 | -------------------------------------------------------------------------------- /tests/darwintest_defaults.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | 24 | #ifndef DARWINTEST_DEFAULTS_H 25 | #define DARWINTEST_DEFAULTS_H 26 | 27 | #include 28 | 29 | T_GLOBAL_META ( 30 | T_META_TIMEOUT(30), 31 | T_META_LTEPHASE(LTE_POSTINIT) 32 | ); 33 | 34 | 35 | #endif // DARWINTEST_DEFAULTS_H 36 | -------------------------------------------------------------------------------- /tests/detach.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "darwintest_defaults.h" 9 | 10 | static void* 11 | thread_routine(void *loc) 12 | { 13 | uintptr_t i = (uintptr_t)loc; 14 | 15 | switch (i % 3) { 16 | case 0: 17 | usleep(1000); 18 | break; 19 | case 1: 20 | pthread_exit(pthread_self()); 21 | __builtin_unreachable(); 22 | case 2: 23 | break; 24 | } 25 | return NULL; 26 | } 27 | 28 | T_DECL(pthread_detach, "Test creating and detaching threads in a loop", 29 | T_META_CHECK_LEAKS(NO), T_META_ALL_VALID_ARCHS(YES)) 30 | { 31 | const size_t count = 32; 32 | pthread_t ths[count]; 33 | 34 | for (size_t i = 0; i < 100; i++) { 35 | for (size_t j = 0; j < count; j++) { 36 | T_ASSERT_POSIX_ZERO(pthread_create(&ths[j], NULL, 37 | thread_routine, (void *)j), "thread creation"); 38 | T_ASSERT_POSIX_ZERO(pthread_detach(ths[j]), "thread detach"); 39 | } 40 | usleep(50000); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/helpers/libpthreadjittest.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int 4 | test_dylib_jit_write_callback(void *ctx); 5 | 6 | int 7 | test_dylib_jit_write_callback(void *ctx) 8 | { 9 | pthread_jit_write_callback_t cb = ctx; 10 | return cb(NULL); 11 | } 12 | 13 | PTHREAD_JIT_WRITE_ALLOW_CALLBACKS_NP(test_dylib_jit_write_callback); 14 | -------------------------------------------------------------------------------- /tests/helpers/pthread_jit_write_with_callback_tool.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | static int 12 | test_callback_should_not_actually_run(void *ctx) 13 | { 14 | (void)ctx; 15 | printf("This callback was not expected to actually run\n"); 16 | return 0; 17 | } 18 | 19 | #define HELPER_LIBRARY_PATH "/AppleInternal/Tests/libpthread/assets/libpthreadjittest.notdylib" 20 | 21 | int 22 | main(int argc, char *argv[]) 23 | { 24 | if (argc != 2) { 25 | // The test is checking whether we exited with a signal to see if the 26 | // expected abort occurs, so if we need to bail out because of a 27 | // misconfiguration we should try to exit with an error code instead 28 | return 1; 29 | } 30 | #if TARGET_OS_OSX 31 | if (!strcmp(argv[1], "pthread_jit_write_protect_np")) { 32 | printf("Attempting pthread_jit_write_protect_np\n"); 33 | pthread_jit_write_protect_np(false); 34 | printf("Should not have made it here\n"); 35 | } else 36 | #endif // TARGET_OS_OSX 37 | if (!strcmp(argv[1], "pthread_jit_write_with_callback_np")) { 38 | printf("Attempting pthread_jit_write_with_callback_np\n"); 39 | (void)pthread_jit_write_with_callback_np( 40 | test_callback_should_not_actually_run, NULL); 41 | printf("Should not have made it here\n"); 42 | } else if (!strcmp(argv[1], "pthread_jit_write_freeze_callbacks_np")) { 43 | printf("Attempting freeze + dlopen + write_with_callback\n"); 44 | 45 | pthread_jit_write_freeze_callbacks_np(); 46 | 47 | void *handle = dlopen(HELPER_LIBRARY_PATH, RTLD_NOW); 48 | if (!handle) { 49 | printf("dlopen failed\n"); 50 | return 1; 51 | } 52 | 53 | pthread_jit_write_callback_t cb = dlsym(handle, 54 | "test_dylib_jit_write_callback"); 55 | if (!cb) { 56 | printf("dlsym failed\n"); 57 | return 1; 58 | } 59 | 60 | (void)pthread_jit_write_with_callback_np(cb, NULL); 61 | printf("Should not have made it here\n"); 62 | } 63 | 64 | return 1; 65 | } 66 | -------------------------------------------------------------------------------- /tests/helpers/stackoverflow_crash.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static volatile int * array1_ref = NULL; 5 | static long last_stack_addr = 0; 6 | 7 | static void 8 | recursive_fn(void) 9 | { 10 | volatile int array1[1024]; /* leave this as it is */ 11 | int addr; 12 | last_stack_addr = (long)&addr; 13 | array1_ref = array1; /* make sure compiler cannot discard storage */ 14 | array1[0] = 0; 15 | if (array1_ref == 0) { 16 | /* fool clang -Winfinite-recursion */ 17 | return; 18 | } 19 | recursive_fn(); 20 | return; 21 | } 22 | 23 | int 24 | main(__unused int argc, __unused const char *argv[]) 25 | { 26 | struct rlimit save; 27 | 28 | if (getrlimit(RLIMIT_STACK, &save) == -1) { 29 | printf("child: ERROR - getrlimit"); 30 | return 2; 31 | } 32 | printf("child: LOG - current stack limits cur=0x%llx, max=0x%llx, inf=0x%llx\n", save.rlim_cur, save.rlim_max, RLIM_INFINITY); 33 | 34 | if(save.rlim_cur >= save.rlim_max) { 35 | printf("child: ERROR - invalid limits"); 36 | return 2; 37 | } 38 | 39 | if(save.rlim_max == RLIM_INFINITY) { 40 | printf("child: ERROR - rlim_max = RLIM_INFINITY"); 41 | return 2; 42 | } 43 | 44 | save.rlim_cur += 4; 45 | 46 | printf("child: LOG - Raising setrlimit rlim_cur=0x%llx, rlim_max=0x%llx\n", save.rlim_cur, save.rlim_max); 47 | 48 | if (setrlimit(RLIMIT_STACK, &save) == -1) { 49 | printf("child: ERROR - Raising the limits failed."); 50 | return 2; 51 | } 52 | 53 | printf("child: LOG - Make the stack grow such that a SIGSEGV is generated.\n"); 54 | recursive_fn(); 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /tests/main_stack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "darwintest_defaults.h" 4 | #include 5 | 6 | T_DECL(main_stack, "tests the reported values for the main thread stack", 7 | T_META_CHECK_LEAKS(NO), T_META_ALL_VALID_ARCHS(YES)){ 8 | const uintptr_t stackaddr = (uintptr_t)pthread_get_stackaddr_np(pthread_self()); 9 | const size_t stacksize = pthread_get_stacksize_np(pthread_self()); 10 | T_LOG("stack: %zx -> %zx (+%zx)", stackaddr - stacksize, stackaddr, stacksize); 11 | T_EXPECT_LT((uintptr_t)__builtin_frame_address(0), stackaddr, NULL); 12 | T_EXPECT_GT((uintptr_t)__builtin_frame_address(0), stackaddr - stacksize, NULL); 13 | 14 | struct rlimit lim; 15 | T_ASSERT_POSIX_SUCCESS(getrlimit(RLIMIT_STACK, &lim), NULL); 16 | T_EXPECT_EQ((size_t)lim.rlim_cur, pthread_get_stacksize_np(pthread_self()), "reported rlimit should match stacksize"); 17 | 18 | lim.rlim_cur = lim.rlim_cur / 8; 19 | T_ASSERT_POSIX_SUCCESS(setrlimit(RLIMIT_STACK, &lim), NULL); 20 | 21 | T_EXPECTFAIL; 22 | T_EXPECT_EQ((size_t)lim.rlim_cur, pthread_get_stacksize_np(pthread_self()), "new rlimit should should match stacksize"); 23 | } 24 | -------------------------------------------------------------------------------- /tests/main_stack_custom.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "darwintest_defaults.h" 4 | #include 5 | 6 | T_DECL(main_stack_custom, "tests the reported values for a custom main thread stack"){ 7 | T_EXPECT_EQ((size_t)STACKSIZE, pthread_get_stacksize_np(pthread_self()), NULL); 8 | 9 | const uintptr_t stackaddr = (uintptr_t)pthread_get_stackaddr_np(pthread_self()); 10 | size_t stacksize = pthread_get_stacksize_np(pthread_self()); 11 | T_LOG("stack: %zx -> %zx (+%zx)", stackaddr - stacksize, stackaddr, stacksize); 12 | T_EXPECT_LT((uintptr_t)__builtin_frame_address(0), stackaddr, NULL); 13 | T_EXPECT_GT((uintptr_t)__builtin_frame_address(0), stackaddr - stacksize, NULL); 14 | 15 | struct rlimit lim; 16 | T_QUIET; T_ASSERT_POSIX_SUCCESS(getrlimit(RLIMIT_STACK, &lim), NULL); 17 | lim.rlim_cur = lim.rlim_cur + 32 * PAGE_SIZE; 18 | T_EXPECT_EQ(setrlimit(RLIMIT_STACK, &lim), -1, "setrlimit for stack should fail with custom stack"); 19 | T_EXPECT_EQ((size_t)STACKSIZE, pthread_get_stacksize_np(pthread_self()), "reported stacksize shouldn't change"); 20 | } 21 | -------------------------------------------------------------------------------- /tests/main_stack_legacy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "darwintest_defaults.h" 4 | #include 5 | 6 | T_DECL(main_stack_legacy, "tests the reported values for a custom main thread stack", 7 | T_META_CHECK_LEAKS(NO)) 8 | { 9 | T_EXPECT_LT((uintptr_t)0, pthread_get_stacksize_np(pthread_self()), NULL); 10 | 11 | const uintptr_t stackaddr = (uintptr_t)pthread_get_stackaddr_np(pthread_self()); 12 | size_t stacksize = pthread_get_stacksize_np(pthread_self()); 13 | T_LOG("stack: %zx -> %zx (+%zx)", stackaddr - stacksize, stackaddr, stacksize); 14 | T_EXPECT_LT((uintptr_t)__builtin_frame_address(0), stackaddr, NULL); 15 | T_EXPECT_GT((uintptr_t)__builtin_frame_address(0), stackaddr - stacksize, NULL); 16 | } 17 | -------------------------------------------------------------------------------- /tests/maxwidth.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define NUM 100000 6 | static volatile size_t concur; 7 | static volatile size_t final; 8 | dispatch_queue_t resultsq; 9 | dispatch_group_t rgroup; 10 | 11 | void finish(void* ctxt) 12 | { 13 | int c = (uintptr_t)ctxt; 14 | if (c > final) final = c; 15 | } 16 | 17 | void work(void* ctxt) 18 | { 19 | int c = __sync_add_and_fetch(&concur, 1); 20 | if (ctxt) { 21 | usleep(1000); 22 | } else { 23 | for (int i=0; i<100000; i++) { 24 | __asm__ __volatile__ (""); 25 | } 26 | } 27 | dispatch_group_async_f(rgroup, resultsq, (void*)(uintptr_t)c, finish); 28 | __sync_sub_and_fetch(&concur, 1); 29 | } 30 | 31 | int main(int argc, const char *argv[]) 32 | { 33 | size_t i; 34 | 35 | rgroup = dispatch_group_create(); 36 | resultsq = dispatch_queue_create("results", 0); 37 | dispatch_suspend(resultsq); 38 | 39 | dispatch_group_t group = dispatch_group_create(); 40 | 41 | final = concur = 0; 42 | for (i=0; i 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "darwintest_defaults.h" 9 | 10 | struct ctx { 11 | volatile int last_holder; 12 | volatile int quit; 13 | int iterations[2]; 14 | pthread_mutex_t l; 15 | }; 16 | 17 | static void * 18 | job(struct ctx *ctx, int idx) 19 | { 20 | int ret; 21 | while (!ctx->quit) { 22 | ret = pthread_mutex_trylock(&ctx->l); 23 | T_QUIET; T_ASSERT_TRUE(ret == EBUSY || ret == 0, "trylock"); 24 | 25 | if (ret == EBUSY) { 26 | T_QUIET; T_ASSERT_POSIX_ZERO(pthread_mutex_lock(&ctx->l), 27 | "pthread_mutex_lock"); 28 | // we know that the other thread was just holding the lock 29 | T_QUIET; T_ASSERT_EQ(ctx->last_holder, !idx, 30 | "expecting oppsosite last holder after failed trylock"); 31 | } 32 | 33 | ctx->last_holder = idx; 34 | ctx->iterations[idx]++; 35 | 36 | T_QUIET; T_ASSERT_POSIX_ZERO(pthread_mutex_unlock(&ctx->l), 37 | "pthread_mutex_unlock"); 38 | } 39 | return NULL; 40 | } 41 | 42 | static void * 43 | job1(void *ctx) 44 | { 45 | return job((struct ctx *)ctx, 0); 46 | } 47 | 48 | static void * 49 | job2(void *ctx) 50 | { 51 | return job((struct ctx *)ctx, 1); 52 | } 53 | 54 | T_DECL(mutex_trylock, "pthread_mutex_trylock", 55 | T_META_ALL_VALID_ARCHS(YES)) 56 | { 57 | // This testcase spins up two threads with identical jobs. They try-lock 58 | // the same mutex. If that fails, they check that the last holder of the 59 | // lock is the other thread. 60 | const int test_duration = 10; // sec 61 | struct ctx ctx = {0}; 62 | 63 | pthread_t t1, t2; 64 | 65 | T_ASSERT_POSIX_ZERO(pthread_mutex_init(&ctx.l, NULL), 66 | "pthread_mutex_init"); 67 | T_ASSERT_POSIX_ZERO(pthread_create(&t1, NULL, job1, &ctx), 68 | "pthread_create 1"); 69 | T_ASSERT_POSIX_ZERO(pthread_create(&t2, NULL, job2, &ctx), 70 | "pthread_create 2"); 71 | 72 | sleep(test_duration); 73 | 74 | ctx.quit = 1; 75 | T_ASSERT_POSIX_ZERO(pthread_join(t1, NULL), "pthread join 1"); 76 | T_ASSERT_POSIX_ZERO(pthread_join(t2, NULL), "pthread join 2"); 77 | 78 | T_LOG("after %d seconds iterations 0: %d, 1: %d. Exiting\n", 79 | test_duration, ctx.iterations[0], ctx.iterations[1]); 80 | } 81 | -------------------------------------------------------------------------------- /tests/once_cancel.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "darwintest_defaults.h" 4 | 5 | static volatile int once_invoked = 0; 6 | 7 | static void 8 | cancelation_handler(void * __unused arg) 9 | { 10 | T_LOG("cancelled"); 11 | } 12 | 13 | __attribute__((noreturn)) 14 | static void 15 | await_cancelation(void) 16 | { 17 | pthread_cleanup_push(cancelation_handler, NULL); 18 | T_LOG("waiting for cancellation"); 19 | 20 | // can't use darwintest once cancellation is enabled 21 | pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); 22 | 23 | while (true) { 24 | pthread_testcancel(); 25 | sched_yield(); 26 | } 27 | 28 | pthread_cleanup_pop(0); 29 | } 30 | 31 | static void * 32 | await_cancelation_in_once(void *arg) 33 | { 34 | // disable cancellation until pthread_once to protect darwintest 35 | pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); 36 | 37 | T_LOG("starting the thread"); 38 | pthread_once_t *once = (pthread_once_t *)arg; 39 | pthread_once(once, await_cancelation); 40 | return NULL; 41 | } 42 | 43 | static void 44 | oncef(void) 45 | { 46 | T_LOG("once invoked"); 47 | once_invoked++; 48 | } 49 | 50 | T_DECL(once_cancel, "pthread_once is re-executed if cancelled") 51 | { 52 | pthread_once_t once = PTHREAD_ONCE_INIT; 53 | pthread_t t; 54 | void *join_result = NULL; 55 | 56 | T_ASSERT_POSIX_ZERO( 57 | pthread_create(&t, NULL, await_cancelation_in_once, &once), NULL); 58 | T_ASSERT_POSIX_ZERO(pthread_cancel(t), NULL); 59 | T_ASSERT_POSIX_ZERO(pthread_join(t, &join_result), NULL); 60 | T_ASSERT_EQ(join_result, PTHREAD_CANCELED, NULL); 61 | 62 | T_ASSERT_POSIX_ZERO(pthread_once(&once, oncef), NULL); 63 | T_ASSERT_EQ(once_invoked, 1, NULL); 64 | } 65 | -------------------------------------------------------------------------------- /tests/pthread_attr_setstacksize.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "darwintest_defaults.h" 8 | 9 | #define STACK_ALLOWANCE (1024ULL * 6) 10 | 11 | static void * 12 | pthread_attr_setstacksize_func(void *arg) 13 | { 14 | if ((size_t)arg < 1024ULL * 32) { 15 | /* 16 | * We can't use darwintest because it requires a bigger stack than 17 | * this, so cheat and use the return value for the test. 18 | */ 19 | #ifndef __arm64__ 20 | if ((size_t)arg != pthread_get_stacksize_np(pthread_self())) { 21 | return NULL; 22 | } 23 | #endif 24 | return (void*)pthread_attr_setstacksize_func; 25 | } 26 | 27 | #if defined(__arm64__) 28 | // Because of , the kext adds additional size to the stack on arm64. 29 | T_EXPECTFAIL; 30 | #endif 31 | T_EXPECT_EQ((size_t)arg, pthread_get_stacksize_np(pthread_self()), "[stacksize=%zu] pthread_self stack size matches", (size_t)arg); 32 | 33 | size_t stacksize = (size_t)arg - STACK_ALLOWANCE; 34 | char *buf = alloca(stacksize); 35 | 36 | memset_s(buf, sizeof(buf), 0, sizeof(buf) - 1); 37 | 38 | return (void*)pthread_attr_setstacksize_func; 39 | } 40 | 41 | T_DECL(pthread_attr_setstacksize, "pthread_attr_setstacksize") 42 | { 43 | T_LOG("vm_page_size: %lld vm_kernel_page_size: %lld round_page(MIN): %lld", vm_page_size, vm_kernel_page_size, round_page(PTHREAD_STACK_MIN)); 44 | size_t stacksizes[] = {PTHREAD_STACK_MIN, 1024ULL * 16, 1024ULL * 32, 1024ULL * 1024}; 45 | for (int i = 0; (size_t)i < sizeof(stacksizes)/sizeof(stacksizes[0]); i++){ 46 | pthread_t t = NULL; 47 | pthread_attr_t attr; 48 | size_t stacksize = stacksizes[i]; 49 | 50 | T_ASSERT_POSIX_ZERO(pthread_attr_init(&attr), "[stacksize=%zu] pthread_attr_init", stacksize); 51 | T_ASSERT_POSIX_ZERO(pthread_attr_setstacksize(&attr, stacksize), "[stacksize=%zu] pthread_attr_stacksize", stacksize); 52 | 53 | T_ASSERT_POSIX_ZERO(pthread_create(&t, &attr, pthread_attr_setstacksize_func, (void*)stacksize), "[stacksize=%zu] pthread_create", stacksize); 54 | T_ASSERT_NOTNULL(t, "[stacksize=%zu] pthread pointer not null", stacksize); 55 | 56 | T_EXPECT_POSIX_ZERO(pthread_attr_destroy(&attr), "[stacksize=%zu] pthread_attr_destroy", stacksize); 57 | 58 | #if defined(__arm64__) 59 | // Because of , the kext adds additional size to the stack on arm64. 60 | T_EXPECTFAIL; 61 | #endif 62 | T_EXPECT_EQ(stacksize, pthread_get_stacksize_np(t), "[stacksize=%zu] pthread stack size matches", stacksize); 63 | 64 | void *out = NULL; 65 | T_ASSERT_POSIX_ZERO(pthread_join(t, &out), "[stacksize=%zu] pthread_join", stacksize); 66 | T_EXPECT_EQ_PTR(out, (void*)pthread_attr_setstacksize_func, "[stacksize=%zu] pthread_join returns correct value", stacksize); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /tests/pthread_bulk_create.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "darwintest_defaults.h" 4 | 5 | #define MAX_THREADS 512 6 | #define THREAD_DEPTH 32 7 | 8 | static void * 9 | thread(void * arg) 10 | { 11 | T_LOG("thread %lx here: %d", (uintptr_t)pthread_self(), (int)arg); 12 | return (arg); 13 | } 14 | 15 | T_DECL(pthread_bulk_create, "pthread_bulk_create") 16 | { 17 | void *thread_res; 18 | pthread_t t[THREAD_DEPTH]; 19 | 20 | for (int i = 0; i < MAX_THREADS; i += THREAD_DEPTH) { 21 | T_LOG("Creating threads %d..%d\n", i, i + THREAD_DEPTH - 1); 22 | for (int j = 0; j < THREAD_DEPTH; j++) { 23 | void *arg = (void *)(intptr_t)(i + j); 24 | T_QUIET; T_ASSERT_POSIX_ZERO( 25 | pthread_create(&t[j], NULL, thread, arg), NULL); 26 | } 27 | T_LOG("Waiting for threads"); 28 | for (int j = 0; j < THREAD_DEPTH; j++) { 29 | T_QUIET; T_ASSERT_POSIX_ZERO(pthread_join(t[j], &thread_res), NULL); 30 | T_QUIET; T_ASSERT_EQ(i + j, (int)thread_res, "thread return value"); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tests/pthread_cancel.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "darwintest_defaults.h" 4 | 5 | static void * 6 | run(void * __unused arg) 7 | { 8 | while (true) { 9 | pthread_testcancel(); 10 | sched_yield(); 11 | } 12 | } 13 | 14 | T_DECL(pthread_cancel, "pthread_cancel", 15 | T_META_ALL_VALID_ARCHS(YES)) 16 | { 17 | pthread_t thread; 18 | void *join_result = NULL; 19 | T_ASSERT_POSIX_ZERO(pthread_create(&thread, NULL, run, NULL), NULL); 20 | T_ASSERT_POSIX_ZERO(pthread_cancel(thread), NULL); 21 | T_ASSERT_POSIX_ZERO(pthread_join(thread, &join_result), NULL); 22 | T_ASSERT_EQ(join_result, PTHREAD_CANCELED, NULL); 23 | } 24 | -------------------------------------------------------------------------------- /tests/pthread_create_from_mach_thread.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "darwintest_defaults.h" 10 | 11 | #define CHILD_STACK_COUNT 1024 12 | static uint64_t child_stack[CHILD_STACK_COUNT]; 13 | 14 | static void* 15 | pthread_runner(void* __unused arg) 16 | { 17 | T_PASS("mach -> pthread conversion successful"); 18 | T_END; 19 | } 20 | 21 | static void * 22 | mach_bootstrap(void * __unused arg) 23 | { 24 | pthread_t thread; 25 | pthread_create_from_mach_thread(&thread, NULL, pthread_runner, NULL); 26 | while (1) { 27 | swtch_pri(0); // mach_yield 28 | } 29 | } 30 | 31 | T_DECL(pthread_create_from_mach_thread, "pthread_create_from_mach_thread", 32 | T_META_ALL_VALID_ARCHS(YES), 33 | // Having leaks running will suppress the behavior we are testing 34 | T_META_CHECK_LEAKS(false), 35 | T_META_ENVVAR("MallocStackLogging=1") 36 | ) 37 | { 38 | T_PASS("MallocStackLogging: %s", getenv("MallocStackLogging")); 39 | 40 | // Create a mach_thread to start with 41 | mach_port_t task = mach_task_self(); 42 | 43 | thread_state_flavor_t flavor; 44 | mach_msg_type_number_t count; 45 | 46 | uintptr_t start_addr = (uintptr_t)&mach_bootstrap; 47 | // Force alignment to 16-bytes 48 | uintptr_t stack_top = ((uintptr_t)&child_stack[CHILD_STACK_COUNT]) & ~0xf; 49 | 50 | #if defined(__x86_64__) 51 | T_PASS("x86_64"); 52 | flavor = x86_THREAD_STATE64; 53 | count = x86_THREAD_STATE64_COUNT; 54 | x86_thread_state64_t state = { 55 | .__rip = start_addr, 56 | // Must be 16-byte-off-by-8 aligned 57 | .__rsp = stack_top - 8, 58 | }; 59 | #elif defined(__arm64__) 60 | T_PASS("arm64"); 61 | flavor = ARM_THREAD_STATE64; 62 | count = ARM_THREAD_STATE64_COUNT; 63 | arm_thread_state64_t state = { }; 64 | arm_thread_state64_set_pc_fptr(state, &mach_bootstrap); 65 | arm_thread_state64_set_sp(state, stack_top); 66 | (void)start_addr; 67 | #elif defined(__arm__) 68 | T_PASS("arm (32)"); 69 | flavor = ARM_THREAD_STATE; 70 | count = ARM_THREAD_STATE_COUNT; 71 | arm_thread_state_t state = { 72 | .__pc = start_addr, 73 | .__sp = stack_top, 74 | .__cpsr = 0x20, 75 | }; 76 | #else 77 | #error Unknown architecture 78 | #endif 79 | 80 | thread_state_t state_ptr = (thread_state_t)&state; 81 | thread_t task_thread; 82 | T_PASS("Launching Thread"); 83 | 84 | kern_return_t ret = thread_create_running(task, flavor, state_ptr, count, &task_thread); 85 | T_ASSERT_MACH_SUCCESS(ret, "mach thread created"); 86 | // Wait forever 87 | sigset_t empty; 88 | T_QUIET; T_ASSERT_POSIX_ZERO(sigemptyset(&empty), NULL); 89 | while (sigsuspend(&empty)) { 90 | continue; 91 | } 92 | T_FAIL("Didn't wait forever?"); 93 | } 94 | -------------------------------------------------------------------------------- /tests/pthread_dependency.c: -------------------------------------------------------------------------------- 1 | #include "darwintest_defaults.h" 2 | #include 3 | #include 4 | 5 | static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; 6 | static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; 7 | 8 | static struct job { 9 | pthread_dependency_t *req; 10 | useconds_t usleep; 11 | int done; 12 | } job; 13 | 14 | static void * 15 | do_test(void *__unused arg) 16 | { 17 | pthread_mutex_lock(&mutex); 18 | 19 | while (!job.done) { 20 | while (job.req == 0) { 21 | pthread_cond_wait(&cond, &mutex); 22 | } 23 | if (job.usleep) usleep(job.usleep); 24 | pthread_dependency_fulfill_np(job.req, job.req); 25 | job.req = NULL; 26 | } 27 | 28 | pthread_mutex_unlock(&mutex); 29 | return NULL; 30 | } 31 | 32 | static void 33 | post_req(pthread_dependency_t *req, useconds_t delay, bool done) 34 | { 35 | pthread_mutex_lock(&mutex); 36 | job.req = req; 37 | job.usleep = delay; 38 | job.done = done; 39 | pthread_cond_signal(&cond); 40 | pthread_mutex_unlock(&mutex); 41 | } 42 | 43 | T_DECL(dependency, "dependency", T_META_ALL_VALID_ARCHS(YES)) 44 | { 45 | pthread_dependency_t req; 46 | pthread_t pth; 47 | void *v; 48 | int ret; 49 | 50 | T_ASSERT_POSIX_ZERO(pthread_create(&pth, NULL, do_test, NULL), NULL); 51 | 52 | T_LOG("Waiting on a pdependency that takes some time"); 53 | 54 | pthread_dependency_init_np(&req, pth, NULL); 55 | post_req(&req, 100000, false); 56 | v = pthread_dependency_wait_np(&req); 57 | T_EXPECT_EQ(v, &req, "pthread_dependency_wait worked"); 58 | 59 | T_LOG("Waiting on a pdependency that is already fulfilled"); 60 | 61 | pthread_dependency_init_np(&req, pth, NULL); 62 | post_req(&req, 0, false); 63 | usleep(100000); 64 | v = pthread_dependency_wait_np(&req); 65 | T_EXPECT_EQ(v, &req, "pthread_dependency_wait worked"); 66 | 67 | T_LOG("Waiting on a fulfilled pdependency with the other thread exiting"); 68 | 69 | pthread_dependency_init_np(&req, pth, NULL); 70 | post_req(&req, 0, true); 71 | ret = pthread_join(pth, NULL); 72 | T_EXPECT_POSIX_ZERO(ret, "pthread_join"); 73 | 74 | v = pthread_dependency_wait_np(&req); 75 | T_EXPECT_EQ(v, &req, "pthread_dependency_wait worked"); 76 | 77 | T_END; 78 | } 79 | -------------------------------------------------------------------------------- /tests/pthread_get_qos_class_np.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "darwintest_defaults.h" 11 | 12 | static void *sleep_thread(void __unused *arg){ 13 | sleep(1); 14 | return NULL; 15 | } 16 | 17 | /* Regression test for */ 18 | T_DECL(test_pthread_get_qos_class_np, "Test for pthread_get_qos_class_np()", T_META_CHECK_LEAKS(NO)) { 19 | pthread_t thread; 20 | pthread_attr_t attr; 21 | pthread_attr_init(&attr); 22 | pthread_attr_set_qos_class_np(&attr, QOS_CLASS_BACKGROUND, 0); 23 | pthread_create(&thread, &attr, sleep_thread, NULL); 24 | 25 | qos_class_t qos; 26 | pthread_get_qos_class_np(thread, &qos, NULL); 27 | 28 | T_EXPECT_EQ(qos, (qos_class_t)QOS_CLASS_BACKGROUND, NULL); 29 | } 30 | -------------------------------------------------------------------------------- /tests/pthread_introspection.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "darwintest_defaults.h" 7 | 8 | static pthread_introspection_hook_t prev_pthread_introspection_hook; 9 | static pthread_key_t key; 10 | static atomic_int keys_set; 11 | static atomic_int keys_cleared; 12 | static const char value_for_key[] = "used as a TSD value"; 13 | 14 | static void 15 | key_destructor(void *ctx) 16 | { 17 | T_EXPECT_EQ(ctx, (void *)value_for_key, "check value"); 18 | keys_cleared++; 19 | } 20 | 21 | #define THREAD_COUNT 3 22 | 23 | static void my_pthread_introspection_hook(unsigned int event, pthread_t thread, 24 | void *addr, size_t size) 25 | { 26 | static atomic_int create_count; 27 | static atomic_int terminate_count; 28 | static atomic_int destroy_count; 29 | 30 | uint64_t tid; 31 | pthread_threadid_np(NULL, &tid); 32 | 33 | switch (event) { 34 | case PTHREAD_INTROSPECTION_THREAD_CREATE: 35 | atomic_fetch_add(&keys_set, 1); 36 | pthread_introspection_setspecific_np(thread, key, value_for_key); 37 | T_LOG("event = PTHREAD_INTROSPECTION_THREAD_CREATE, thread = %p:%lld, addr = %p, size = 0x%zx", thread, tid, addr, size); 38 | create_count++; 39 | break; 40 | case PTHREAD_INTROSPECTION_THREAD_TERMINATE: 41 | T_LOG("event = PTHREAD_INTROSPECTION_THREAD_TERMINATE, thread = %p:%lld, addr = %p, size = 0x%zx", thread, tid, addr, size); 42 | terminate_count++; 43 | T_ASSERT_GE(create_count, THREAD_COUNT, NULL); 44 | T_PASS("Got termination events"); 45 | break; 46 | case PTHREAD_INTROSPECTION_THREAD_DESTROY: 47 | T_LOG("event = PTHREAD_INTROSPECTION_THREAD_DESTROY, thread = %p:%lld, addr = %p, size = 0x%zx", thread, tid, addr, size); 48 | destroy_count++; 49 | T_ASSERT_NULL(pthread_introspection_getspecific_np(thread, key), "should have cleared"); 50 | T_ASSERT_NE(keys_cleared, 0, "should have cleared a key"); 51 | T_PASS("Got destruction events"); 52 | T_END; 53 | } 54 | 55 | if (prev_pthread_introspection_hook != NULL){ 56 | prev_pthread_introspection_hook(event, thread, addr, size); 57 | } 58 | } 59 | 60 | T_DECL(pthread_introspection, "PR-25679871", 61 | T_META_TIMEOUT(30), T_META_ALL_VALID_ARCHS(YES)) 62 | { 63 | prev_pthread_introspection_hook = pthread_introspection_hook_install(&my_pthread_introspection_hook); 64 | pthread_key_create(&key, key_destructor); 65 | 66 | // minus one that comes after this block 67 | for (int i = 0; i < THREAD_COUNT - 1; i++) { 68 | T_LOG("Creating dispatch_async thread %d.", i); 69 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 70 | T_LOG("Started dispatch_async thread %d.", i); 71 | sleep(3); 72 | }); 73 | } 74 | dispatch_queue_t serial_queue = dispatch_queue_create("test queue", NULL); 75 | __block dispatch_block_t looping_block = ^{ 76 | static int count; 77 | if (count++ < 20) { 78 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 50 * NSEC_PER_MSEC), serial_queue, looping_block); 79 | } else { 80 | T_LOG("Looping block complete"); 81 | } 82 | }; 83 | T_LOG("Starting looping block"); 84 | dispatch_async(serial_queue, looping_block); 85 | 86 | sleep(30); 87 | 88 | T_FAIL("Why are we still alive?"); 89 | } 90 | -------------------------------------------------------------------------------- /tests/pthread_jit_write_freeze_callbacks-ios-entitlements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.cs.jit-write-allowlist 6 | 7 | com.apple.security.cs.jit-write-allowlist-freeze-late 8 | 9 | dynamic-codesigning 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/pthread_jit_write_freeze_callbacks-macos-entitlements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.cs.jit-write-allowlist 6 | 7 | com.apple.security.cs.jit-write-allowlist-freeze-late 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/pthread_jit_write_freeze_callbacks.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | static int 8 | dylib_callback_callback(void *ctx) 9 | { 10 | return 2424; 11 | } 12 | 13 | #define HELPER_LIBRARY_PATH "/AppleInternal/Tests/libpthread/assets/libpthreadjittest.notdylib" 14 | 15 | T_DECL(pthread_jit_write_freeze_callbacks_correct, 16 | "Verify pthread_jit_write_freeze_callbacks_np(3) works correctly when used correctly") 17 | { 18 | void *handle = dlopen(HELPER_LIBRARY_PATH, RTLD_NOW); 19 | T_ASSERT_NOTNULL(handle, "dlopen()"); 20 | 21 | pthread_jit_write_freeze_callbacks_np(); 22 | 23 | pthread_jit_write_callback_t cb = dlsym(handle, 24 | "test_dylib_jit_write_callback"); 25 | T_ASSERT_NOTNULL(cb, "dlsym()"); 26 | 27 | int rc = pthread_jit_write_with_callback_np(cb, dylib_callback_callback); 28 | T_EXPECT_EQ(rc, 2424, "Callback callback returned expected result"); 29 | } 30 | 31 | #if TARGET_CPU_ARM64 // should effectively match _PTHREAD_CONFIG_JIT_WRITE_PROTECT 32 | 33 | #define HELPER_TOOL_PATH "/AppleInternal/Tests/libpthread/assets/pthread_jit_write_freeze_callbacks_tool" 34 | 35 | T_DECL(pthread_jit_write_freeze_callbacks_incorrect, 36 | "Verify pthread_jit_write_protect_np prohibited by allowlist", 37 | T_META_IGNORECRASHES(".*pthread_jit_write_freeze_callbacks_tool.*")) 38 | { 39 | char *cmd[] = { HELPER_TOOL_PATH, "pthread_jit_write_freeze_callbacks_np", 40 | NULL }; 41 | dt_spawn_t spawn = dt_spawn_create(NULL); 42 | dt_spawn(spawn, cmd, 43 | ^(char *line, __unused size_t size){ 44 | T_LOG("+ %s", line); 45 | }, 46 | ^(char *line, __unused size_t size){ 47 | T_LOG("stderr: %s\n", line); 48 | }); 49 | 50 | bool exited, signaled; 51 | int status, signal; 52 | dt_spawn_wait(spawn, &exited, &signaled, &status, &signal); 53 | T_EXPECT_FALSE(exited, "helper tool should not have exited"); 54 | T_EXPECT_TRUE(signaled, "helper tool should have been signaled"); 55 | } 56 | 57 | #endif // TARGET_CPU_ARM64 58 | -------------------------------------------------------------------------------- /tests/pthread_jit_write_lockdown-entitlements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | dynamic-codesigning 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/pthread_jit_write_lockdown.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | static int 7 | test_jit_write_callback(void *ctx) 8 | { 9 | (void)ctx; 10 | return 42; 11 | } 12 | 13 | // PTHREAD_JIT_WRITE_ALLOW_CALLBACKS_NP deliberately omitted 14 | 15 | T_DECL(pthread_jit_write_with_callback_no_allowlist, 16 | "pthread_jit_write_with_callback_np() without allowlist entitlement", 17 | T_META_IGNORECRASHES(".*pthread_jit_lockdown.*")) 18 | { 19 | if (!pthread_jit_write_protect_supported_np()) { 20 | T_SKIP("JIT write protection not supported on this device"); 21 | } 22 | 23 | #if TARGET_OS_OSX 24 | int rc = pthread_jit_write_with_callback_np(test_jit_write_callback, NULL); 25 | T_EXPECT_EQ(rc, 42, "pthread_jit_write_with_callback_np"); 26 | #else 27 | pid_t pid = fork(); 28 | if (pid == 0) { 29 | int rc = pthread_jit_write_with_callback_np( 30 | test_jit_write_callback, NULL); 31 | T_ASSERT_FAIL("should not have made it here: %d", rc); 32 | } else { 33 | T_ASSERT_POSIX_SUCCESS(pid, "fork()"); 34 | 35 | int status; 36 | pid_t wait_pid = waitpid(pid, &status, 0); 37 | T_LOG("waitpid(): %d, %d", wait_pid, status); 38 | T_ASSERT_EQ(wait_pid, pid, "Got child status"); 39 | T_ASSERT_TRUE(WIFSIGNALED(status), "Child terminated by signal"); 40 | } 41 | #endif 42 | } 43 | -------------------------------------------------------------------------------- /tests/pthread_jit_write_protection-entitlements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | dynamic-codesigning 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/pthread_jit_write_protection.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "pthread_jit_write_test_inline.h" 5 | 6 | T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true)); 7 | 8 | static void * 9 | expect_write_fail_thread(__unused void * arg) 10 | { 11 | fault_state_create(); 12 | 13 | if (does_access_fault(ACCESS_WRITE, rwx_addr)) { 14 | pthread_exit((void *)0); 15 | } else { 16 | pthread_exit((void *)1); 17 | } 18 | } 19 | 20 | T_DECL(pthread_jit_write_protect, 21 | "Verify that the pthread_jit_write_protect interfaces work correctly") 22 | { 23 | void * join_value = NULL; 24 | pthread_t pthread; 25 | bool expect_fault = pthread_jit_write_protect_supported_np(); 26 | 27 | pthread_jit_test_setup(); 28 | 29 | /* 30 | * Validate that we fault when we should, and that we do not fault when 31 | * we should not fault. 32 | */ 33 | pthread_jit_write_protect_np(FALSE); 34 | 35 | T_EXPECT_EQ(does_access_fault(ACCESS_WRITE, rwx_addr), 0, "Write with RWX->RW"); 36 | 37 | pthread_jit_write_protect_np(TRUE); 38 | 39 | T_EXPECT_EQ(does_access_fault(ACCESS_EXECUTE, rwx_addr), 0, "Execute with RWX->RX"); 40 | 41 | pthread_jit_write_protect_np(TRUE); 42 | 43 | T_EXPECT_EQ(does_access_fault(ACCESS_WRITE, rwx_addr), expect_fault, "Write with RWX->RX"); 44 | 45 | // Only attempt to catch the ACCESS_EXECUTE fault when the code signing monitor is 46 | // disabled. When the monitor is enabled, any execute faults which can't be resolved 47 | // result in a SIGKILL to the target process. 48 | if (code_signing_monitor_enabled() == false) { 49 | pthread_jit_write_protect_np(FALSE); 50 | T_EXPECT_EQ(does_access_fault(ACCESS_EXECUTE, rwx_addr), expect_fault, "Execute with RWX->RW"); 51 | } 52 | 53 | pthread_jit_write_protect_np(FALSE); 54 | 55 | if (expect_fault) { 56 | /* 57 | * Create another thread for testing multithreading; mark this as setup 58 | * as this test is not targeted towards the pthread create/join APIs. 59 | */ 60 | T_SETUPBEGIN; 61 | 62 | T_ASSERT_POSIX_ZERO(pthread_create(&pthread, NULL, expect_write_fail_thread, NULL), "pthread_create expect_write_fail_thread"); 63 | 64 | T_ASSERT_POSIX_ZERO(pthread_join(pthread, &join_value), "pthread_join expect_write_fail_thread"); 65 | 66 | T_SETUPEND; 67 | 68 | /* 69 | * Validate that the other thread was unable to write to the JIT region 70 | * without independently using the pthread_jit_write_protect code. 71 | */ 72 | T_ASSERT_NULL((join_value), "Write on other thread with RWX->RX, " 73 | "RWX->RW on parent thread"); 74 | } 75 | 76 | /* We're done with the test; tear down our extra state. */ 77 | pthread_jit_test_teardown(); 78 | } 79 | 80 | T_DECL(thread_self_restrict_rwx_perf, 81 | "Test the performance of the thread_self_restrict_rwx interfaces", 82 | T_META_TAG_PERF, T_META_CHECK_LEAKS(false)) 83 | { 84 | dt_stat_time_t dt_stat_time; 85 | 86 | dt_stat_time = dt_stat_time_create("rx->rw->rx time"); 87 | 88 | T_STAT_MEASURE_LOOP(dt_stat_time) { 89 | pthread_jit_write_protect_np(FALSE); 90 | pthread_jit_write_protect_np(TRUE); 91 | } 92 | 93 | dt_stat_finalize(dt_stat_time); 94 | } 95 | -------------------------------------------------------------------------------- /tests/pthread_jit_write_with_callback-ios-entitlements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.cs.jit-write-allowlist 6 | 7 | dynamic-codesigning 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/pthread_jit_write_with_callback-macos-entitlements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.cs.jit-write-allowlist 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/pthread_setspecific.c: -------------------------------------------------------------------------------- 1 | /* 2 | * @OSF_COPYRIGHT@ 3 | * 4 | */ 5 | /* 6 | * HISTORY 7 | * $Log: pthread_test3.c,v $ 8 | * Revision 1.1.4.2 1996/10/03 17:53:38 emcmanus 9 | * Changed fprintf(stderr...) to printf(...) to allow building with 10 | * PURE_MACH includes. 11 | * [1996/10/03 16:17:34 emcmanus] 12 | * 13 | * Revision 1.1.4.1 1996/10/01 07:36:02 emcmanus 14 | * Copied from rt3_merge. 15 | * Include for malloc() prototype. 16 | * [1996/10/01 07:35:53 emcmanus] 17 | * 18 | * Revision 1.1.2.1 1996/09/27 13:12:15 gdt 19 | * Add support for thread specific data 20 | * [1996/09/27 13:11:17 gdt] 21 | * 22 | * $EndLog$ 23 | */ 24 | 25 | /* 26 | * Test POSIX Thread Specific Data 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "darwintest_defaults.h" 35 | 36 | static pthread_key_t key; 37 | 38 | static void * 39 | thread(void * arg) 40 | { 41 | char * msg; 42 | T_LOG("thread %lx here: %s\n", (uintptr_t)pthread_self(), (char *)arg); 43 | msg = malloc(256); 44 | sprintf(msg, "This is thread specific data for %lx\n", (uintptr_t)pthread_self()); 45 | T_ASSERT_POSIX_ZERO(pthread_setspecific(key, msg), NULL); 46 | return (arg); 47 | } 48 | 49 | static void 50 | grim_reaper(void * param) 51 | { 52 | T_LOG("grim_reaper - self: %lx, param: %lx value: %s", (uintptr_t)pthread_self(), (uintptr_t)param, (char *)param); 53 | free(param); 54 | } 55 | 56 | T_DECL(pthread_setspecific, "pthread_setspecific", 57 | T_META_ALL_VALID_ARCHS(YES)) 58 | { 59 | void * thread_res; 60 | pthread_t t1, t2; 61 | T_ASSERT_POSIX_ZERO(pthread_key_create(&key, grim_reaper), NULL); 62 | T_ASSERT_POSIX_ZERO(pthread_create(&t1, (pthread_attr_t *)NULL, thread, "thread #1 arg"), NULL); 63 | T_ASSERT_POSIX_ZERO(pthread_create(&t2, (pthread_attr_t *)NULL, thread, "thread #2 arg"), NULL); 64 | T_ASSERT_POSIX_ZERO(pthread_join(t1, &thread_res), NULL); 65 | T_ASSERT_POSIX_ZERO(pthread_join(t2, &thread_res), NULL); 66 | } 67 | -------------------------------------------------------------------------------- /tests/pthread_threadid_np.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "darwintest_defaults.h" 8 | 9 | extern __uint64_t __thread_selfid( void ); 10 | 11 | static void *do_test(void * arg) 12 | { 13 | uint64_t threadid = __thread_selfid(); 14 | T_ASSERT_NE(threadid, (uint64_t)0, "__thread_selfid()"); 15 | 16 | uint64_t pth_threadid = 0; 17 | T_ASSERT_POSIX_ZERO(pthread_threadid_np(NULL, &pth_threadid), NULL); 18 | T_ASSERT_POSIX_ZERO(pthread_threadid_np(pthread_self(), &pth_threadid), NULL); 19 | T_EXPECT_EQ(threadid, pth_threadid, "pthread_threadid_np()"); 20 | 21 | pth_threadid = _pthread_threadid_self_np_direct(); 22 | T_EXPECT_EQ(threadid, pth_threadid, "pthread_threadid_np_direct()"); 23 | 24 | if (arg) { 25 | *(uint64_t *)arg = pth_threadid; 26 | } 27 | return NULL; 28 | } 29 | 30 | T_DECL(pthread_threadid_np, "pthread_threadid_np", 31 | T_META_ALL_VALID_ARCHS(YES)) 32 | { 33 | T_LOG("Main Thread"); 34 | do_test(NULL); 35 | 36 | T_LOG("Pthread"); 37 | for (int i = 0; i < 100; i++) { 38 | uint64_t tid1 = 0, tid2 = 0; 39 | pthread_t pth; 40 | T_ASSERT_POSIX_ZERO(pthread_create(&pth, NULL, do_test, &tid1), NULL); 41 | T_EXPECT_POSIX_ZERO(pthread_threadid_np(pth, &tid2), NULL); 42 | T_ASSERT_POSIX_ZERO(pthread_join(pth, NULL), NULL); 43 | T_EXPECT_EQ(tid1, tid2, "parent and child agree"); 44 | } 45 | 46 | T_LOG("Workqueue Thread"); 47 | dispatch_queue_t dq = dispatch_queue_create("myqueue", NULL); 48 | dispatch_async(dq, ^{ do_test(NULL); }); 49 | dispatch_sync(dq, ^{}); 50 | 51 | T_LOG("Workqueue Thread Reuse"); 52 | dispatch_async(dq, ^{ do_test(NULL); }); 53 | dispatch_sync(dq, ^{}); 54 | } 55 | 56 | T_DECL(pthread_threadid_fork, "pthread_threadid_np post-fork test") 57 | { 58 | uint64_t tid = __thread_selfid(); 59 | T_ASSERT_NE(tid, (uint64_t)0, "__thread_selfid()"); 60 | 61 | uint64_t ptid = 0; 62 | T_ASSERT_POSIX_ZERO(pthread_threadid_np(NULL, &ptid), NULL); 63 | T_ASSERT_EQ(ptid, tid, NULL); 64 | 65 | pid_t pid = fork(); 66 | if (pid == 0) { 67 | // child 68 | uint64_t ntid = __thread_selfid(); 69 | if (ntid == tid) { 70 | T_LOG("FAIL: forked child tid is equal to parent tid"); 71 | exit(1); 72 | } 73 | 74 | uint64_t nptid = 0; 75 | if (pthread_threadid_np(NULL, &nptid) != 0) { 76 | T_LOG("FAIL: pthread_threadid_np: %d", errno); 77 | exit(1); 78 | } 79 | 80 | if (nptid != ntid) { 81 | T_LOG("FAIL: pthread_threadid_np == tid (expected: %lld == %lld)", 82 | nptid, ntid); 83 | exit(1); 84 | } 85 | exit(0); 86 | } else { 87 | int status; 88 | T_ASSERT_EQ(waitpid(pid, &status, 0), pid, NULL); 89 | int exitstatus = WEXITSTATUS(status); 90 | T_ASSERT_EQ(exitstatus, 0, NULL); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /tests/rwlock-22244050.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | pthread_t thr; 9 | pthread_rwlock_t lock; 10 | OSSpinLock slock = 0; 11 | int i = 0; 12 | 13 | void sighandler(int sig) 14 | { 15 | if (sig == SIGUSR1) { 16 | OSSpinLockLock(&slock); 17 | OSSpinLockUnlock(&slock); 18 | } else { 19 | // ALARM 20 | fprintf(stderr, "FAIL (%d)\n", i); 21 | exit(1); 22 | } 23 | } 24 | 25 | void* thread(void *arg) 26 | { 27 | pthread_rwlock_rdlock(&lock); 28 | pthread_rwlock_unlock(&lock); 29 | return NULL; 30 | } 31 | 32 | int main(int argc, const char *argv[]) 33 | { 34 | pthread_rwlock_init(&lock, NULL); 35 | signal(SIGUSR1, sighandler); 36 | signal(SIGALRM, sighandler); 37 | 38 | alarm(30); 39 | 40 | while (i++ < 10000) { 41 | pthread_rwlock_wrlock(&lock); 42 | pthread_create(&thr, NULL, thread, NULL); 43 | OSSpinLockLock(&slock); 44 | pthread_kill(thr, SIGUSR1); 45 | pthread_rwlock_unlock(&lock); 46 | OSSpinLockUnlock(&slock); 47 | } 48 | 49 | fprintf(stderr, "PASS\n"); 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /tests/rwlock.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | struct context { 11 | pthread_rwlock_t rwlock; 12 | long value; 13 | long count; 14 | }; 15 | 16 | void *test_thread(void *ptr) { 17 | int res; 18 | long old; 19 | struct context *context = ptr; 20 | 21 | int i = 0; 22 | char *str; 23 | 24 | do { 25 | bool try = i & 1; 26 | bool exclusive = i & 2; 27 | switch (i++ & 3) { 28 | case 0: 29 | str = "pthread_rwlock_rdlock"; 30 | res = pthread_rwlock_rdlock(&context->rwlock); 31 | break; 32 | case 1: 33 | str = "pthread_rwlock_tryrdlock"; 34 | res = pthread_rwlock_tryrdlock(&context->rwlock); 35 | break; 36 | case 2: 37 | str = "pthread_rwlock_wrlock"; 38 | res = pthread_rwlock_wrlock(&context->rwlock); 39 | break; 40 | case 3: 41 | str = "pthread_rwlock_trywrlock"; 42 | res = pthread_rwlock_trywrlock(&context->rwlock); 43 | break; 44 | } 45 | if (res != 0) { 46 | if (try && res == EBUSY) { 47 | continue; 48 | } 49 | fprintf(stderr, "[%ld] %s: %s\n", context->count, str, strerror(res)); 50 | abort(); 51 | } 52 | 53 | if (exclusive) { 54 | old = __sync_fetch_and_or(&context->value, 1); 55 | if ((old & 1) != 0) { 56 | fprintf(stderr, "[%ld] OR %lx\n", context->count, old); 57 | abort(); 58 | } 59 | } 60 | 61 | old = __sync_fetch_and_and(&context->value, 0); 62 | if ((old & 1) != (exclusive ? 1 : 0)) { 63 | fprintf(stderr, "[%ld] AND %lx\n", context->count, old); 64 | abort(); 65 | } 66 | 67 | res = pthread_rwlock_unlock(&context->rwlock); 68 | if (res) { 69 | fprintf(stderr, "[%ld] pthread_rwlock_unlock: %s\n", context->count, strerror(res)); 70 | abort(); 71 | } 72 | } while (__sync_fetch_and_sub(&context->count, 1) > 0); 73 | 74 | return NULL; 75 | } 76 | 77 | int main(int argc, char *argv[]) 78 | { 79 | struct context context = { 80 | .rwlock = PTHREAD_RWLOCK_INITIALIZER, 81 | .value = 0, 82 | .count = 5000000, 83 | }; 84 | int i; 85 | int res; 86 | int threads = 16; 87 | pthread_t p[threads]; 88 | for (i = 0; i < threads; ++i) { 89 | res = pthread_create(&p[i], NULL, test_thread, &context); 90 | assert(res == 0); 91 | } 92 | for (i = 0; i < threads; ++i) { 93 | res = pthread_join(p[i], NULL); 94 | assert(res == 0); 95 | } 96 | 97 | return 0; 98 | } 99 | -------------------------------------------------------------------------------- /tests/setrlimit_sigsegv.c: -------------------------------------------------------------------------------- 1 | #include "darwintest_defaults.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | extern char **environ; 9 | 10 | T_DECL(setrlimit_overflow_segfault, 11 | "sigsegv is sent when stack(limit set with setrlimit) is fully used.", 12 | T_META_IGNORECRASHES(".*stackoverflow_crash.*"), 13 | T_META_CHECK_LEAKS(NO), 14 | T_META_ALL_VALID_ARCHS(YES), 15 | T_META_ASROOT(YES)) 16 | { 17 | pid_t child_pid = 0; 18 | int rv = 0; 19 | 20 | struct rlimit lim, save; 21 | T_ASSERT_POSIX_SUCCESS(getrlimit(RLIMIT_STACK, &save), NULL); 22 | T_ASSERT_POSIX_SUCCESS(getrlimit(RLIMIT_STACK, &lim), NULL); 23 | T_LOG("parent: stack limits cur=%llx max=%llx", lim.rlim_cur, lim.rlim_max); 24 | lim.rlim_cur = lim.rlim_cur/8; 25 | T_ASSERT_POSIX_SUCCESS(setrlimit(RLIMIT_STACK, &lim), NULL); 26 | int status = 0; 27 | int exit_signal = 0; 28 | 29 | char *crash_cmd[] = { "./assets/stackoverflow_crash", NULL }; 30 | posix_spawn_file_actions_t fact; 31 | posix_spawn_file_actions_init(&fact); 32 | T_ASSERT_POSIX_SUCCESS(posix_spawn_file_actions_addinherit_np(&fact, STDIN_FILENO), NULL); 33 | T_ASSERT_POSIX_SUCCESS(posix_spawn_file_actions_addinherit_np(&fact, STDOUT_FILENO), NULL); 34 | T_ASSERT_POSIX_SUCCESS(posix_spawn_file_actions_addinherit_np(&fact, STDERR_FILENO), NULL); 35 | T_LOG("spawning %s", crash_cmd[0]); 36 | rv = posix_spawn(&child_pid, crash_cmd[0], &fact, NULL, crash_cmd, environ); 37 | T_ASSERT_POSIX_SUCCESS(rv, "spawning the stackoverflow program"); 38 | 39 | T_LOG("parent: waiting for child process with pid %d", child_pid); 40 | wait(&status); 41 | T_LOG("parent: child process exited. status=%d", WEXITSTATUS(status)); 42 | 43 | 44 | T_ASSERT_POSIX_SUCCESS(setrlimit(RLIMIT_STACK, &save), "Restore original limtis"); 45 | posix_spawn_file_actions_destroy(&fact); 46 | 47 | T_ASSERT_TRUE(WIFSIGNALED(status), "child exit with a signal"); 48 | exit_signal = WTERMSIG(status); 49 | T_ASSERT_EQ(exit_signal, SIGSEGV, "child should receive SIGSEGV"); 50 | 51 | return; 52 | } 53 | -------------------------------------------------------------------------------- /tests/stack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "darwintest_defaults.h" 5 | #include 6 | 7 | #if defined(__arm64__) 8 | #define call_chkstk(value) \ 9 | __asm__ volatile("orr x9, xzr, %0\t\n" \ 10 | "bl _thread_chkstk_darwin" : : "i"(value) : "x9") 11 | #elif defined(__x86_64__) 12 | #define call_chkstk(value) \ 13 | __asm__ volatile("movq %0, %%rax\t\n" \ 14 | "callq _thread_chkstk_darwin" : : "i"(value) : "rax") 15 | #elif defined(__i386__) 16 | #define call_chkstk(value) \ 17 | __asm__ volatile("movl %0, %%eax\t\n" \ 18 | "calll _thread_chkstk_darwin" : : "i"(value) : "eax") 19 | #endif 20 | 21 | static void 22 | got_signal(int signo __unused) 23 | { 24 | T_PASS("calling with 1 << 24 crashed"); 25 | T_END; 26 | } 27 | 28 | T_DECL(chkstk, "chkstk", 29 | T_META_ALL_VALID_ARCHS(YES), T_META_CHECK_LEAKS(NO)) 30 | { 31 | #if defined(__arm__) 32 | T_SKIP("not on armv7"); 33 | #else 34 | 35 | call_chkstk(1 << 8); 36 | T_PASS("calling with 1 << 8"); 37 | 38 | call_chkstk(1 << 16); 39 | T_PASS("calling with 1 << 16"); 40 | 41 | stack_t ss = { 42 | .ss_sp = malloc(MINSIGSTKSZ), 43 | .ss_size = MINSIGSTKSZ, 44 | }; 45 | T_ASSERT_POSIX_SUCCESS(sigaltstack(&ss, NULL), "sigaltstack"); 46 | 47 | struct sigaction sa = { 48 | .sa_handler = got_signal, 49 | .sa_flags = SA_ONSTACK, 50 | }; 51 | T_ASSERT_POSIX_SUCCESS(sigaction(SIGSEGV, &sa, NULL), "sigaction"); 52 | 53 | #ifdef __LP64__ 54 | call_chkstk(1ul << 32); 55 | #else 56 | call_chkstk(1ul << 24); 57 | #endif 58 | T_FAIL("should have crashed"); 59 | #endif 60 | } 61 | 62 | struct frame { 63 | uintptr_t frame; 64 | uintptr_t ret; 65 | }; 66 | 67 | OS_NOINLINE OS_NOT_TAIL_CALLED 68 | static void 69 | do_stack_frame_decode_test(struct frame frames[], size_t n, size_t count) 70 | { 71 | if (n < count) { 72 | frames[n].frame = (uintptr_t)__builtin_frame_address(1); 73 | frames[n].ret = (uintptr_t)__builtin_return_address(0); 74 | do_stack_frame_decode_test(frames, n + 1, count); 75 | } else { 76 | uintptr_t frame = (uintptr_t)__builtin_frame_address(1); 77 | uintptr_t ret; 78 | while (count-- > 0) { 79 | frame = pthread_stack_frame_decode_np(frame, &ret); 80 | T_EXPECT_EQ(frames[count].frame, frame, "Frame %zd", count); 81 | T_EXPECT_EQ(frames[count].ret, ret, "Retaddr %zd", count); 82 | } 83 | } 84 | } 85 | 86 | T_DECL(pthread_stack_frame_decode_np, "pthread_stack_frame_decode_np", 87 | T_META_ALL_VALID_ARCHS(YES), T_META_CHECK_LEAKS(NO)) 88 | { 89 | struct frame frames[10]; 90 | frames[0].frame = (uintptr_t)__builtin_frame_address(1); 91 | frames[0].ret = (uintptr_t)__builtin_return_address(0); 92 | do_stack_frame_decode_test(frames, 1, 10); 93 | } 94 | -------------------------------------------------------------------------------- /tests/stack_size.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "darwintest_defaults.h" 5 | 6 | #if defined(__arm64__) 7 | #define PTHREAD_T_OFFSET (12*1024) 8 | #else 9 | #define PTHREAD_T_OFFSET (0) 10 | #endif 11 | 12 | static void * 13 | function(void *arg) 14 | { 15 | size_t expected_size = (size_t)(uintptr_t)arg; 16 | T_ASSERT_EQ(pthread_get_stacksize_np(pthread_self()), expected_size, 17 | "saw expected pthread_get_stacksize_np"); 18 | return NULL; 19 | } 20 | 21 | T_DECL(stack_size_default, "stack size of default pthread", 22 | T_META_ALL_VALID_ARCHS(YES)) 23 | { 24 | static const size_t dflsize = 512 * 1024; 25 | pthread_t thread; 26 | pthread_attr_t attr; 27 | 28 | T_ASSERT_POSIX_ZERO(pthread_attr_init(&attr), NULL); 29 | T_ASSERT_POSIX_ZERO(pthread_create(&thread, &attr, function, 30 | (void *)(dflsize + PTHREAD_T_OFFSET)), NULL); 31 | T_ASSERT_POSIX_ZERO(pthread_join(thread, NULL), NULL); 32 | } 33 | 34 | T_DECL(stack_size_customsize, "stack size of thread with custom stack size", 35 | T_META_ALL_VALID_ARCHS(YES)) 36 | { 37 | static const size_t stksize = 768 * 1024; 38 | pthread_t thread; 39 | pthread_attr_t attr; 40 | 41 | T_ASSERT_POSIX_ZERO(pthread_attr_init(&attr), NULL); 42 | T_ASSERT_POSIX_ZERO(pthread_attr_setstacksize(&attr, stksize), NULL); 43 | T_ASSERT_POSIX_ZERO(pthread_create(&thread, &attr, function, 44 | (void *)(stksize + PTHREAD_T_OFFSET)), NULL); 45 | T_ASSERT_POSIX_ZERO(pthread_join(thread, NULL), NULL); 46 | } 47 | 48 | T_DECL(stack_size_customaddr, "stack size of thread with custom stack addr", 49 | T_META_ALL_VALID_ARCHS(YES)) 50 | { 51 | static const size_t stksize = 512 * 1024; 52 | pthread_t thread; 53 | pthread_attr_t attr; 54 | 55 | uintptr_t stackaddr = (uintptr_t)valloc(stksize); 56 | stackaddr += stksize; // address is top of stack 57 | 58 | T_ASSERT_POSIX_ZERO(pthread_attr_init(&attr), NULL); 59 | T_ASSERT_POSIX_ZERO(pthread_attr_setstackaddr(&attr, (void *)stackaddr), 60 | NULL); 61 | T_ASSERT_POSIX_ZERO(pthread_create(&thread, &attr, function, 62 | (void *)stksize), NULL); 63 | T_ASSERT_POSIX_ZERO(pthread_join(thread, NULL), NULL); 64 | free((void *)(stackaddr - stksize)); 65 | } 66 | 67 | T_DECL(stack_size_custom, "stack size of thread with custom stack addr+size", 68 | T_META_ALL_VALID_ARCHS(YES)) 69 | { 70 | static const size_t stksize = 768 * 1024; 71 | pthread_t thread; 72 | pthread_attr_t attr; 73 | 74 | uintptr_t stackaddr = (uintptr_t)valloc(stksize); 75 | stackaddr += stksize; // address is top of stack 76 | 77 | T_ASSERT_POSIX_ZERO(pthread_attr_init(&attr), NULL); 78 | T_ASSERT_POSIX_ZERO(pthread_attr_setstackaddr(&attr, (void *)stackaddr), 79 | NULL); 80 | T_ASSERT_POSIX_ZERO(pthread_attr_setstacksize(&attr, stksize), NULL); 81 | T_ASSERT_POSIX_ZERO(pthread_create(&thread, &attr, function, 82 | (void *)stksize), NULL); 83 | T_ASSERT_POSIX_ZERO(pthread_join(thread, NULL), NULL); 84 | free((void *)(stackaddr - stksize)); 85 | } 86 | -------------------------------------------------------------------------------- /tests/tsd.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "darwintest_defaults.h" 6 | 7 | static void *ptr = NULL; 8 | 9 | static void destructor(void *value) 10 | { 11 | ptr = value; 12 | } 13 | 14 | static void *thread(void *param) 15 | { 16 | pthread_key_t key = *(pthread_key_t *)param; 17 | T_ASSERT_POSIX_ZERO(pthread_setspecific(key, (void *)0x12345678), NULL); 18 | void *value = pthread_getspecific(key); 19 | 20 | T_ASSERT_POSIX_ZERO(pthread_key_create(&key, NULL), NULL); 21 | T_ASSERT_POSIX_ZERO(pthread_setspecific(key, (void *)0x55555555), NULL); 22 | 23 | return value; 24 | } 25 | 26 | T_DECL(tsd, "tsd", 27 | T_META_ALL_VALID_ARCHS(YES)) 28 | { 29 | pthread_key_t key; 30 | 31 | T_ASSERT_POSIX_ZERO(pthread_key_create(&key, destructor), NULL); 32 | T_LOG("key = %ld", key); 33 | 34 | pthread_t p = NULL; 35 | T_ASSERT_POSIX_ZERO(pthread_create(&p, NULL, thread, &key), NULL); 36 | 37 | void *value = NULL; 38 | T_ASSERT_POSIX_ZERO(pthread_join(p, &value), NULL); 39 | T_LOG("value = %p; ptr = %p\n", value, ptr); 40 | 41 | T_EXPECT_EQ(ptr, value, NULL); 42 | 43 | T_ASSERT_POSIX_ZERO(pthread_key_delete(key), NULL); 44 | } 45 | 46 | static uint32_t 47 | get_ncpu(void) 48 | { 49 | static uint32_t activecpu; 50 | if (!activecpu) { 51 | uint32_t n; 52 | size_t s = sizeof(activecpu); 53 | sysctlbyname("hw.activecpu", &n, &s, NULL, 0); 54 | activecpu = n; 55 | } 56 | return activecpu; 57 | } 58 | 59 | T_DECL(cpuid, "cpu id", T_META_ALL_VALID_ARCHS(YES)) 60 | { 61 | pthread_t child; 62 | 63 | size_t cpu_id; 64 | if (pthread_cpu_number_np(&cpu_id)) { 65 | T_FAIL("Should not fail to get CPU id"); 66 | } 67 | 68 | T_ASSERT_LE(cpu_id, get_ncpu(), "Got a valid CPU id"); 69 | } 70 | -------------------------------------------------------------------------------- /tests/wq_block_handoff.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | static int x = 0; 6 | static int y = 0; 7 | 8 | int main(void) 9 | { 10 | /* found in 12A216: Spotlight takes a long time to show results */ 11 | 12 | /* we need to start up NCPU-1 threads in a given bucket, then fire up one more at a separate 13 | * priority. 14 | * 15 | * each of these waiters needs to be non-blocked until the point where dispatch wants to 16 | * request a new thread. 17 | * 18 | * if dispatch ever fixes sync_barrier -> sync handoff to not require an extra thread, 19 | * then this test will never fail and will be invalid. 20 | */ 21 | 22 | printf("[TEST] barrier_sync -> async @ ncpu threads\n"); 23 | 24 | dispatch_semaphore_t sema = dispatch_semaphore_create(0); 25 | 26 | int ncpu = 1; 27 | size_t sz = sizeof(ncpu); 28 | sysctlbyname("hw.ncpu", &ncpu, &sz, NULL, 0); 29 | printf("starting up %d waiters.\n", ncpu); 30 | 31 | dispatch_queue_t q = dispatch_queue_create("moo", DISPATCH_QUEUE_CONCURRENT); 32 | dispatch_barrier_sync(q, ^{ 33 | dispatch_async(q, ^{ 34 | printf("async.\n"); 35 | dispatch_semaphore_signal(sema); 36 | }); 37 | for (int i=0; i async completed\n", rv == 0 ? "PASS" : "FAIL"); 58 | 59 | return rv; 60 | } 61 | -------------------------------------------------------------------------------- /tests/wq_event_manager.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #include "../private/pthread/workqueue_private.h" 14 | #include "../private/pthread/qos_private.h" 15 | 16 | #include "wq_kevent.h" 17 | 18 | static dispatch_semaphore_t sema; 19 | static dispatch_time_t timeout; 20 | 21 | static int do_wait(int threads){ 22 | for (int i = 0; i < threads; i++){ 23 | int ret = dispatch_semaphore_wait(sema, timeout); 24 | if (ret){ 25 | fprintf(stderr, "timout waiting for thread %d.\n", i); 26 | return 1; 27 | } 28 | } 29 | fprintf(stderr, "\tsuccessfully signaled by %d threads.\n", threads); 30 | return 0; 31 | } 32 | 33 | static void workqueue_func(pthread_priority_t priority){ 34 | fprintf(stderr, "WARNING: workqueue_func called.\n"); 35 | dispatch_semaphore_signal(sema); 36 | } 37 | 38 | void (^cb)(void) = NULL; 39 | static void workqueue_func_kevent(void **buf, int *count){ 40 | pthread_priority_t p = (pthread_priority_t)pthread_getspecific(4); 41 | fprintf(stderr, "\tthread with qos %s spawned.\n", describe_pri(p)); 42 | 43 | if (cb){ 44 | cb(); 45 | } 46 | 47 | dispatch_semaphore_signal(sema); 48 | } 49 | 50 | int main(int argc, char *argv[]){ 51 | int ret = 0; 52 | int exit_status = 0; 53 | 54 | ret = _pthread_workqueue_init_with_kevent(workqueue_func, workqueue_func_kevent, 0, 0); 55 | assert(ret == 0); 56 | 57 | sema = dispatch_semaphore_create(0); 58 | assert(sema != NULL); 59 | timeout = dispatch_time(DISPATCH_TIME_NOW, 5LL * NSEC_PER_SEC); 60 | 61 | // one event manager 62 | requests[0].priority = _pthread_qos_class_encode(QOS_CLASS_UNSPECIFIED, 0, _PTHREAD_PRIORITY_EVENT_MANAGER_FLAG); 63 | requests[0].count = 1; 64 | 65 | if ((ret = do_req()) < 0) return ret; 66 | if ((ret = do_wait(1)) < 0) return ret; 67 | 68 | fprintf(stderr, "event_manager_priority -> USER_INITIATED\n"); 69 | _pthread_workqueue_set_event_manager_priority(_pthread_qos_class_encode(QOS_CLASS_USER_INITIATED, 0, 0)); 70 | 71 | if ((ret = do_req()) < 0) return ret; 72 | if ((ret = do_wait(1)) < 0) return ret; 73 | 74 | fprintf(stderr, "event_manager_priority -> UTILITY\n"); 75 | _pthread_workqueue_set_event_manager_priority(_pthread_qos_class_encode(QOS_CLASS_UTILITY, 0, 0)); 76 | 77 | if ((ret = do_req()) < 0) return ret; 78 | if ((ret = do_wait(1)) < 0) return ret; 79 | 80 | fprintf(stderr, "event_manager_priority -> 60\n"); 81 | _pthread_workqueue_set_event_manager_priority(_PTHREAD_PRIORITY_SCHED_PRI_FLAG | 60);; 82 | 83 | cb = ^(void){sleep(2);}; 84 | 85 | if ((ret = do_req()) < 0) return ret; 86 | if ((ret = do_wait(1)) < 0) return ret; 87 | 88 | requests[0].priority = _pthread_qos_class_encode(QOS_CLASS_USER_INITIATED, 0, 0); 89 | requests[0].count = 1; 90 | 91 | if ((ret = do_req()) < 0) return ret; 92 | if ((ret = do_wait(1)) < 0) return ret; 93 | 94 | return 0; 95 | } 96 | -------------------------------------------------------------------------------- /tests/wq_kevent.h: -------------------------------------------------------------------------------- 1 | #define REQUESTS_LEN 4 2 | static struct workq_reqthreads_req_s {unsigned long priority; int count;} requests[REQUESTS_LEN]; 3 | 4 | #define QOS_STR(q) (q == QOS_CLASS_USER_INTERACTIVE ? "UI" : (q == QOS_CLASS_USER_INITIATED ? "IN" : (q == QOS_CLASS_DEFAULT ? "DEF" : (q == QOS_CLASS_UTILITY ? "UT" : (q == QOS_CLASS_BACKGROUND ? "BG" : "UN" ) ) ) ) ) 5 | static char* describe_pri(pthread_priority_t pri){ 6 | qos_class_t qos; 7 | unsigned long flags; 8 | 9 | qos = _pthread_qos_class_decode(pri, NULL, &flags); 10 | 11 | static char desc[32]; 12 | if (flags & _PTHREAD_PRIORITY_EVENT_MANAGER_FLAG){ 13 | sprintf(desc, "E:%s", QOS_STR(qos)); 14 | } else if (flags & _PTHREAD_PRIORITY_OVERCOMMIT_FLAG){ 15 | sprintf(desc, "O:%s", QOS_STR(qos)); 16 | } else { 17 | sprintf(desc, "%s", QOS_STR(qos)); 18 | } 19 | 20 | return desc; 21 | } 22 | 23 | static char* describe_req(void){ 24 | static char desc[256]; 25 | char *c = desc; 26 | 27 | *c++ = '['; 28 | for (int i = 0; i < REQUESTS_LEN; i++){ 29 | if (i) *c++ = ','; 30 | c += sprintf(c, "{%s,%d}", describe_pri(requests[i].priority), requests[i].count); 31 | } 32 | *c++ = ']'; 33 | *c++ = '\0'; 34 | 35 | return desc; 36 | } 37 | 38 | static char *dummy_text = "Four score and seven years ago our fathers brought forth on this continent a new nation, conceived in liberty, and dedicated to the"; 39 | // takes about 1us on my machine 40 | static void burn_cpu(void){ 41 | char key[64]; char txt[64]; 42 | strncpy(txt, dummy_text, 64); 43 | for (int i = 0; i < 64; i++) 44 | key[i] = rand() % 1; 45 | setkey(key); 46 | encrypt(txt, 0); 47 | encrypt(txt, 1); 48 | } 49 | 50 | static int do_req(void){ 51 | int ret = sysctlbyname("debug.wq_kevent_test", NULL, NULL, requests, sizeof(requests)); 52 | if (ret >= 0){ 53 | fprintf(stderr, "wq_kevent_test(%s) -> %d\n", describe_req(), ret); 54 | } else { 55 | perror("debug.wk_kevent_test"); 56 | return errno; 57 | } 58 | return ret; 59 | } 60 | -------------------------------------------------------------------------------- /tests/wq_limits.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "darwintest_defaults.h" 5 | 6 | T_DECL(wq_pool_limits, "test overcommit limit") 7 | { 8 | dispatch_semaphore_t sema = dispatch_semaphore_create(0); 9 | dispatch_group_t g = dispatch_group_create(); 10 | dispatch_time_t t; 11 | uint32_t wq_max_threads, wq_max_constrained_threads; 12 | 13 | dispatch_block_t b = ^{ 14 | dispatch_group_leave(g); 15 | dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER); 16 | }; 17 | 18 | size_t s = sizeof(uint32_t); 19 | sysctlbyname("kern.wq_max_threads", &wq_max_threads, &s, NULL, 0); 20 | sysctlbyname("kern.wq_max_constrained_threads", &wq_max_constrained_threads, 21 | &s, NULL, 0); 22 | 23 | for (uint32_t i = 0; i < wq_max_constrained_threads; i++) { 24 | dispatch_group_enter(g); 25 | dispatch_async(dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), b); 26 | } 27 | 28 | t = dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC); 29 | T_ASSERT_EQ(dispatch_group_wait(g, t), 0L, 30 | "%d constrained threads bringup", wq_max_constrained_threads); 31 | 32 | dispatch_async(dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), ^{ 33 | T_ASSERT_FAIL("Should never run"); 34 | }); 35 | 36 | sleep(5); 37 | T_PASS("constrained limit looks fine"); 38 | 39 | for (uint32_t i = wq_max_constrained_threads; i < wq_max_threads; i++) { 40 | dispatch_group_enter(g); 41 | dispatch_async(dispatch_get_global_queue(QOS_CLASS_DEFAULT, 42 | DISPATCH_QUEUE_OVERCOMMIT), b); 43 | } 44 | t = dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC); 45 | T_ASSERT_EQ(dispatch_group_wait(g, t), 0L, 46 | "%d threads bringup", wq_max_threads); 47 | 48 | 49 | dispatch_async(dispatch_get_global_queue(QOS_CLASS_DEFAULT, 50 | DISPATCH_QUEUE_OVERCOMMIT), ^{ 51 | T_ASSERT_FAIL("Should never run"); 52 | }); 53 | 54 | sleep(5); 55 | T_PASS("thread limit looks fine"); 56 | T_END; 57 | } 58 | -------------------------------------------------------------------------------- /tools/pthtrace.lua: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/luatrace -s 2 | 3 | trace_codename = function(codename, callback) 4 | local debugid = trace.debugid(codename) 5 | if debugid ~= 0 then 6 | trace.single(debugid,callback) 7 | else 8 | printf("WARNING: Cannot locate debugid for '%s'\n", codename) 9 | end 10 | end 11 | 12 | initial_timestamp = 0 13 | workqueue_ptr_map = {}; 14 | get_prefix = function(buf) 15 | if initial_timestamp == 0 then 16 | initial_timestamp = buf.timestamp 17 | end 18 | local secs = trace.convert_timestamp_to_nanoseconds(buf.timestamp - initial_timestamp) / 1000000000 19 | 20 | local prefix 21 | if trace.debugid_is_start(buf.debugid) then 22 | prefix = "→" 23 | elseif trace.debugid_is_end(buf.debugid) then 24 | prefix = "←" 25 | else 26 | prefix = "↔" 27 | end 28 | 29 | local proc 30 | if buf.command ~= "kernel_task" then 31 | proc = buf.command 32 | workqueue_ptr_map[buf[1]] = buf.command 33 | elseif workqueue_ptr_map[buf[1]] ~= nil then 34 | proc = workqueue_ptr_map[buf[1]] 35 | else 36 | proc = "UNKNOWN" 37 | end 38 | 39 | return string.format("%s %6.9f %-17s [%05d.%06x] %-24s", 40 | prefix, secs, proc, buf.pid, buf.threadid, buf.debugname) 41 | end 42 | 43 | trace_codename("pthread_thread_create", function(buf) 44 | local prefix = get_prefix(buf) 45 | if trace.debugid_is_start(buf.debugid) then 46 | printf("%s\tthread creation request: 0x%x\n", prefix, buf[1]) 47 | elseif trace.debugid_is_end(buf.debugid) then 48 | printf("%s\t thread creation complete: pthread 0x%x (error: %d)\n", prefix, buf[2], buf[1]) 49 | elseif buf[4] == 2 then 50 | printf("%s\t thread stack created: 0x%x + 0x%x\n", prefix, buf[2], buf[1]) 51 | elseif buf[4] == 3 then 52 | printf("%s\t thread using custom stack") 53 | end 54 | end) 55 | 56 | trace_codename("pthread_thread_terminate", function(buf) 57 | local prefix = get_prefix(buf) 58 | if trace.debugid_is_start(buf.debugid) then 59 | printf("%s\tthread terminate: stack 0x%x + 0x%x, kthport 0x%x\n", prefix, buf[1], buf[2], buf[3]) 60 | elseif trace.debugid_is_end(buf.debugid) then 61 | printf("%s\t thread terminate: ret %d\n", prefix, buf[1]) 62 | end 63 | end) 64 | 65 | -- The trace codes we need aren't enabled by default 66 | darwin.sysctlbyname("kern.pthread_debug_tracing", 1) 67 | completion_handler = function() 68 | darwin.sysctlbyname("kern.pthread_debug_tracing", 0) 69 | end 70 | trace.set_completion_handler(completion_handler) 71 | -------------------------------------------------------------------------------- /xcodescripts/eos.xcconfig: -------------------------------------------------------------------------------- 1 | #include "pthread.xcconfig" 2 | 3 | BUILD_VARIANTS = normal 4 | INSTALL_PATH = /usr/local/lib/eOS 5 | EXECUTABLE_PREFIX = lib 6 | PRODUCT_NAME = pthread_eOS 7 | GCC_PREPROCESSOR_DEFINITIONS = $(BASE_PREPROCESSOR_MACROS) $(UP_PREPROCESSOR_DEFINITIONS) PTHREAD_TARGET_EOS=1 VARIANT_STATIC=1 8 | OTHER_LDFLAGS = 9 | -------------------------------------------------------------------------------- /xcodescripts/install-codes.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | if [ "${DRIVERKIT}" = 1 ]; then exit 0; fi 4 | 5 | # install kdebug trace files based on the input file 6 | INPUT=${SCRIPT_INPUT_FILE_0} 7 | OUTPUT=${SCRIPT_OUTPUT_FILE_0} 8 | 9 | # pre-process the source and pass through perl it 10 | xcrun cc -E -I${SDKROOT}/System/Library/Frameworks/System.framework/PrivateHeaders -D_PTHREAD_BUILDING_CODES_ "${INPUT}" | perl > "${OUTPUT}" 11 | -------------------------------------------------------------------------------- /xcodescripts/install-lldbmacros.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | # install the pthread lldbmacros into the module 3 | 4 | mkdir -p "$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME/Contents/Resources/Python" || true 5 | rsync -aq "$SRCROOT/lldbmacros/"* "$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME/Contents/Resources/Python" 6 | 7 | for variant in $BUILD_VARIANTS; do 8 | case $variant in 9 | normal) 10 | SUFFIX="" 11 | ;; 12 | *) 13 | SUFFIX="_$variant" 14 | ;; 15 | esac 16 | 17 | ln -sf init.py "$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME/Contents/Resources/Python/$EXECUTABLE_NAME$SUFFIX.py" 18 | done 19 | 20 | if test "$PLATFORM_NAME" != macosx; then 21 | mkdir -p "$DSTROOT/AppleInternal/KextObjects/Python/$MODULE_NAME" || true 22 | rsync -aq "$SRCROOT/lldbmacros/"* "$DSTROOT/AppleInternal/KextObjects/Python/$MODULE_NAME" 23 | ln -sf init.py "$DSTROOT/AppleInternal/KextObjects/Python/$MODULE_NAME/$EXECUTABLE_NAME.py" 24 | fi 25 | -------------------------------------------------------------------------------- /xcodescripts/install-symlinks.sh: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2012 Apple Inc. All rights reserved. 3 | # 4 | # @APPLE_LICENSE_HEADER_START@ 5 | # 6 | # This file contains Original Code and/or Modifications of Original Code 7 | # as defined in and that are subject to the Apple Public Source License 8 | # Version 2.0 (the 'License'). You may not use this file except in 9 | # compliance with the License. Please obtain a copy of the License at 10 | # http://www.opensource.apple.com/apsl/ and read it before using this 11 | # file. 12 | # 13 | # The Original Code and all software distributed under the License are 14 | # distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | # EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | # INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | # Please see the License for the specific language governing rights and 19 | # limitations under the License. 20 | # 21 | # @APPLE_LICENSE_HEADER_END@ 22 | # 23 | 24 | if [ "$ACTION" = build ]; then exit 0; fi 25 | 26 | # 27 | # Symlink old header locations. 28 | # 29 | 30 | DSTROOT="${DSTROOT}/${SDK_INSTALL_HEADERS_ROOT}" 31 | 32 | ln -sf "pthread/pthread.h" "$DSTROOT/usr/include/pthread.h" 33 | ln -sf "pthread/pthread_impl.h" "$DSTROOT/usr/include/pthread_impl.h" 34 | ln -sf "pthread/pthread_spis.h" "$DSTROOT/usr/include/pthread_spis.h" 35 | ln -sf "pthread/sched.h" "$DSTROOT/usr/include/sched.h" 36 | 37 | ln -sf "pthread/posix_sched.h" "$DSTROOT/usr/local/include/posix_sched.h" 38 | ln -sf "pthread/spinlock_private.h" "$DSTROOT/usr/local/include/pthread_spinlock.h" 39 | ln -sf "pthread/workqueue_private.h" "$DSTROOT/usr/local/include/pthread_workqueue.h" 40 | mkdir -p "$DSTROOT/System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders/" 41 | ln -sf "../../../../../../../usr/local/include/pthread/tsd_private.h" \ 42 | "$DSTROOT/System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders/pthread_machdep.h" 43 | -------------------------------------------------------------------------------- /xcodescripts/install-sys-headers.sh: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2013-2014 Apple Inc. All rights reserved. 3 | # 4 | # @APPLE_LICENSE_HEADER_START@ 5 | # 6 | # This file contains Original Code and/or Modifications of Original Code 7 | # as defined in and that are subject to the Apple Public Source License 8 | # Version 2.0 (the 'License'). You may not use this file except in 9 | # compliance with the License. Please obtain a copy of the License at 10 | # http://www.opensource.apple.com/apsl/ and read it before using this 11 | # file. 12 | # 13 | # The Original Code and all software distributed under the License are 14 | # distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | # EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | # INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | # Please see the License for the specific language governing rights and 19 | # limitations under the License. 20 | # 21 | # @APPLE_LICENSE_HEADER_END@ 22 | # 23 | 24 | set -e 25 | 26 | if [ "$ACTION" = build ]; then exit 0; fi 27 | 28 | install_headers() 29 | { 30 | mkdir -p "${DSTROOT}/${SDK_INSTALL_HEADERS_ROOT}$2" 31 | cp -r "${SRCROOT}/$1" "${DSTROOT}/${SDK_INSTALL_HEADERS_ROOT}$2" 32 | 33 | find "${DSTROOT}/${SDK_INSTALL_HEADERS_ROOT}$2" -type f -name *.h -print0 | \ 34 | xargs -0I % unifdef -t ${COPY_HEADERS_UNIFDEF_FLAGS} -o "%" "%" 35 | } 36 | 37 | install_headers "include/sys" "/usr/include" 38 | install_headers "private/sys" "/usr/local/include" 39 | -------------------------------------------------------------------------------- /xcodescripts/kext.xcconfig: -------------------------------------------------------------------------------- 1 | // pthread kext build options 2 | 3 | SDKROOT = macosx.internal 4 | SUPPORTED_PLATFORMS = macosx iphoneos appletvos watchos 5 | BUILD_VARIANTS = normal development kasan 6 | 7 | PTHREAD_VARIANT_ = $(CURRENT_VARIANT) 8 | PTHREAD_VARIANT_YES = development 9 | PTHREAD_VARIANT = $(PTHREAD_VARIANT_$(DEBUG)) 10 | 11 | INSTALL_PATH = $(SYSTEM_LIBRARY_DIR)/Extensions 12 | PRODUCT_NAME = pthread 13 | WRAPPER_EXTENSION = kext 14 | MODULE_NAME = com.apple.kec.pthread 15 | MODULE_START = pthread_start 16 | MODULE_STOP = pthread_stop 17 | MODULE_VERSION = 1.0.0d1 18 | PRODUCT_BUNDLE_IDENTIFIER = ${MODULE_NAME} 19 | INFOPLIST_FILE = kern/pthread-Info.plist 20 | 21 | ALWAYS_SEARCH_USER_PATHS = NO 22 | SRCROOT_SEARCH_PATHS = $(SRCROOT)/private $(SRCROOT)/include $(SRCROOT) 23 | HEADER_SEARCH_PATHS = $(SRCROOT_SEARCH_PATHS) 24 | GCC_C_LANGUAGE_STANDARD = gnu11 25 | CLANG_CXX_LANGUAGE_STANDARD = gnu++0x 26 | CLANG_CXX_LIBRARY = libc++ 27 | GCC_PRECOMPILE_PREFIX_HEADER = YES 28 | CODE_SIGN_IDENTITY = - 29 | DEBUG_INFORMATION_FORMAT = dwarf-with-dsym 30 | 31 | GCC_OPTIMIZATION_LEVEL_normal = s 32 | GCC_OPTIMIZATION_LEVEL_development = s 33 | GCC_OPTIMIZATION_LEVEL = $(GCC_OPTIMIZATION_LEVEL_$(PTHREAD_VARIANT)) 34 | 35 | DEAD_CODE_STRIPPING = NO 36 | LLVM_LTO_normal = YES 37 | LLVM_LTO_development = NO 38 | LLVM_LTO_kasan = NO 39 | LLVM_LTO = $(LLVM_LTO_$(PTHREAD_VARIANT)) 40 | 41 | GCC_PREPROCESSOR_DEFINITIONS_kext = XNU_KERNEL_PRIVATE MACH_KERNEL_PRIVATE ABSOLUTETIME_SCALAR_TYPE NEEDS_SCHED_CALL_T __PTHREAD_EXPOSE_INTERNALS__ 42 | GCC_PREPROCESSOR_DEFINITIONS_kext_development = MACH_ASSERT DEBUG 43 | GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS_kext) $(GCC_PREPROCESSOR_DEFINITIONS_kext_$(PTHREAD_VARIANT)) 44 | 45 | OTHER_CFLAGS_kasan = -fno-inline $(KASAN_DEFAULT_CFLAGS) 46 | 47 | GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES 48 | GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES 49 | 50 | // Warnings 51 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES 52 | CLANG_WARN_EMPTY_BODY = YES 53 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES 54 | GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES 55 | GCC_WARN_ABOUT_MISSING_NEWLINE = YES 56 | GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES 57 | GCC_WARN_ABOUT_RETURN_TYPE = YES 58 | GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES 59 | GCC_WARN_SHADOW = YES 60 | GCC_WARN_SIGN_COMPARE = YES 61 | GCC_WARN_UNINITIALIZED_AUTOS = YES 62 | GCC_WARN_UNUSED_FUNCTION = YES 63 | GCC_WARN_UNUSED_LABEL = YES 64 | GCC_WARN_UNUSED_PARAMETER = YES 65 | GCC_WARN_UNUSED_VARIABLE = YES 66 | -------------------------------------------------------------------------------- /xcodescripts/kext_development.xcconfig: -------------------------------------------------------------------------------- 1 | DEBUG = YES 2 | 3 | #include "kext.xcconfig" 4 | -------------------------------------------------------------------------------- /xcodescripts/pthread-i386.aliases: -------------------------------------------------------------------------------- 1 | # aliases file for pthread old-symbol aliases 2 | # 3 | 4 | _pthread_cancel$UNIX2003 _pthread_cancel 5 | _pthread_cond_init$UNIX2003 _pthread_cond_init 6 | _pthread_cond_timedwait$UNIX2003 _pthread_cond_timedwait 7 | _pthread_cond_wait$UNIX2003 _pthread_cond_wait 8 | _pthread_join$UNIX2003 _pthread_join 9 | _pthread_mutexattr_destroy$UNIX2003 _pthread_mutexattr_destroy 10 | _pthread_rwlock_destroy$UNIX2003 _pthread_rwlock_destroy 11 | _pthread_rwlock_init$UNIX2003 _pthread_rwlock_init 12 | _pthread_rwlock_rdlock$UNIX2003 _pthread_rwlock_rdlock 13 | _pthread_rwlock_tryrdlock$UNIX2003 _pthread_rwlock_tryrdlock 14 | _pthread_rwlock_trywrlock$UNIX2003 _pthread_rwlock_trywrlock 15 | _pthread_rwlock_unlock$UNIX2003 _pthread_rwlock_unlock 16 | _pthread_rwlock_wrlock$UNIX2003 _pthread_rwlock_wrlock 17 | _pthread_setcancelstate$UNIX2003 _pthread_setcancelstate 18 | _pthread_setcanceltype$UNIX2003 _pthread_setcanceltype 19 | _pthread_sigmask$UNIX2003 _pthread_sigmask 20 | _pthread_testcancel$UNIX2003 _pthread_testcancel 21 | _sigwait$UNIX2003 _sigwait 22 | -------------------------------------------------------------------------------- /xcodescripts/pthread-tapi.xcconfig: -------------------------------------------------------------------------------- 1 | // TAPI 2 | SUPPORTS_TEXT_BASED_API = YES 3 | SUPPORTS_TEXT_BASED_API[sdk=iphonesimulator*] = NO 4 | TAPI_VERIFY_MODE = Pedantic 5 | 6 | TAPI_PREPROCESSOR = -DPTHREAD_LAYOUT_SPI=1 -DPTHREAD_WORKGROUP_SPI=1 -Dposix_spawnattr_t="void *" 7 | TAPI_EXTRA_PUBLIC_HEADERS = $(DSTROOT)$(SDK_INSTALL_HEADERS_ROOT)/usr/include/pthread/sched.h $(DSTROOT)$(SDK_INSTALL_HEADERS_ROOT)/usr/include/sys/qos.h 8 | TAPI_EXTRA_PRIVATE_HEADERS = $(PROJECT_DIR)/src/exports_internal.h 9 | TAPI_EXCLUDE_PRIVATE_HEADERS = $(DSTROOT)$(SDK_INSTALL_HEADERS_ROOT)/usr/local/include/pthread/spinlock_private.h 10 | TAPI_ADD_ALIASES = -alias_list $(PROJECT_DIR)/xcodescripts/pthread.aliases 11 | OTHER_TAPI_FLAGS = -umbrella System $(TAPI_ADD_ALIASES) $(TAPI_PREPROCESSOR) 12 | -------------------------------------------------------------------------------- /xcodescripts/pthread.aliases: -------------------------------------------------------------------------------- 1 | # aliases file for pthread old-symbol aliases 2 | # 3 | 4 | _pthread_is_threaded_np __pthread_is_threaded 5 | _sched_yield _cthread_yield 6 | _sched_yield _pthread_yield_np 7 | -------------------------------------------------------------------------------- /xcodescripts/pthread.dirty: -------------------------------------------------------------------------------- 1 | # cacheline-aligned 2 | 3 | # uint64_t sized 4 | ___pthread_stack_hint 5 | 6 | # pointer-sized 7 | ___libdispatch_keventfunction 8 | ___libdispatch_workerfunction 9 | ___libdispatch_workloopfunction 10 | ___pthread_head 11 | __main_thread_ptr 12 | __pthread_free 13 | __pthread_keys 14 | __pthread_malloc 15 | __pthread_ptr_munge_token 16 | __pthread_workgroup_functions 17 | _exitf 18 | 19 | # int-sized 20 | ___is_threaded 21 | ___pthread_supported_features 22 | ___pthread_tsd_lock 23 | ___pthread_tsd_max 24 | __main_qos 25 | __pthread_count 26 | __pthread_list_lock 27 | 28 | # byte-sized 29 | ___workq_newapi 30 | _default_priority 31 | _max_priority 32 | _min_priority 33 | -------------------------------------------------------------------------------- /xcodescripts/pthread_driverkit.xcconfig: -------------------------------------------------------------------------------- 1 | #include "pthread.xcconfig" 2 | #include "pthread-tapi.xcconfig" 3 | -------------------------------------------------------------------------------- /xcodescripts/pthread_introspection.xcconfig: -------------------------------------------------------------------------------- 1 | #include "pthread.xcconfig" 2 | 3 | BUILD_VARIANTS = normal 4 | INSTALL_PATH = /usr/lib/system/introspection 5 | 6 | GCC_PREPROCESSOR_DEFINITIONS = $(BASE_PREPROCESSOR_MACROS) PLOCKSTAT=1 7 | CONFIGURATION_BUILD_DIR = $(BUILD_DIR)/introspection 8 | system_pthread_CFLAGS = -mno-omit-leaf-frame-pointer 9 | -------------------------------------------------------------------------------- /xcodescripts/resolved.xcconfig: -------------------------------------------------------------------------------- 1 | #include "pthread.xcconfig" 2 | 3 | SUPPORTED_PLATFORMS = iphoneos 4 | PRODUCT_NAME = pthread_$(RESOLVED_VARIANT) 5 | OTHER_LDFLAGS = 6 | SKIP_INSTALL = YES 7 | VERSIONING_SYSTEM = 8 | EXCLUDED_SOURCE_FILE_NAMES = * 9 | -------------------------------------------------------------------------------- /xcodescripts/resolver.xcconfig: -------------------------------------------------------------------------------- 1 | #include "pthread.xcconfig" 2 | #include "pthread-tapi.xcconfig" 3 | 4 | -------------------------------------------------------------------------------- /xcodescripts/run-on-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ "x${ACTION}" == "xinstall" && "x${SKIP_INSTALL}" == "xNO" ]]; then 4 | $@ 5 | else 6 | exit 0 7 | fi 8 | -------------------------------------------------------------------------------- /xcodescripts/static.xcconfig: -------------------------------------------------------------------------------- 1 | #include "pthread.xcconfig" 2 | 3 | INSTALL_PATH = /usr/local/lib/system 4 | EXECUTABLE_PREFIX = lib 5 | PRODUCT_NAME = pthread 6 | GCC_PREPROCESSOR_DEFINITIONS = $(BASE_PREPROCESSOR_MACROS) VARIANT_STATIC=1 7 | OTHER_LDFLAGS = 8 | INSTALLHDRS_SCRIPT_PHASE = NO 9 | --------------------------------------------------------------------------------