117ea2221SMatthew Dillon /* 217ea2221SMatthew Dillon * Copyright (c) 2001 Daniel Eischen <deischen@FreeBSD.org>. 317ea2221SMatthew Dillon * All rights reserved. 417ea2221SMatthew Dillon * 517ea2221SMatthew Dillon * Redistribution and use in source and binary forms, with or without 617ea2221SMatthew Dillon * modification, are permitted provided that the following conditions 717ea2221SMatthew Dillon * are met: 817ea2221SMatthew Dillon * 1. Redistributions of source code must retain the above copyright 917ea2221SMatthew Dillon * notice, this list of conditions and the following disclaimer. 1017ea2221SMatthew Dillon * 2. Redistributions in binary form must reproduce the above copyright 1117ea2221SMatthew Dillon * notice, this list of conditions and the following disclaimer in the 1217ea2221SMatthew Dillon * documentation and/or other materials provided with the distribution. 1317ea2221SMatthew Dillon * 1417ea2221SMatthew Dillon * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' 1517ea2221SMatthew Dillon * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1617ea2221SMatthew Dillon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1717ea2221SMatthew Dillon * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1817ea2221SMatthew Dillon * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1917ea2221SMatthew Dillon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2017ea2221SMatthew Dillon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2117ea2221SMatthew Dillon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2217ea2221SMatthew Dillon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2317ea2221SMatthew Dillon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2417ea2221SMatthew Dillon * SUCH DAMAGE. 2517ea2221SMatthew Dillon * 26ce0e08e2SPeter Avalos * $FreeBSD: src/lib/libc/gen/_pthread_stubs.c,v 1.5 2001/06/11 23:18:22 iedowse Exp $ 2717ea2221SMatthew Dillon */ 2817ea2221SMatthew Dillon 2982205bfbSSimon Schubert #include <stdlib.h> 306692f0a1SAlex Hornung #include <pthread.h> 3119c7a913SDavid Xu 3217ea2221SMatthew Dillon /* 3317ea2221SMatthew Dillon * Weak symbols: All libc internal usage of these functions should 3417ea2221SMatthew Dillon * use the weak symbol versions (_pthread_XXX). If libpthread is 3517ea2221SMatthew Dillon * linked, it will override these functions with (non-weak) routines. 3617ea2221SMatthew Dillon * The _pthread_XXX functions are provided solely for internal libc 3717ea2221SMatthew Dillon * usage to avoid unwanted cancellation points and to differentiate 3817ea2221SMatthew Dillon * between application locks and libc locks (threads holding the 3917ea2221SMatthew Dillon * latter can't be allowed to exit/terminate). 4017ea2221SMatthew Dillon */ 41ce0e08e2SPeter Avalos 4282205bfbSSimon Schubert #define WR(f, n) \ 4382205bfbSSimon Schubert __weak_reference(f, _ ## n); \ 4482205bfbSSimon Schubert __weak_reference(f, n) 4582205bfbSSimon Schubert 46*82657471SMarkus Pfeiffer WR(__atfork, pthread_atfork); 4782205bfbSSimon Schubert WR(stub_zero, pthread_attr_destroy); 4882205bfbSSimon Schubert WR(stub_zero, pthread_attr_get_np); 4982205bfbSSimon Schubert WR(stub_zero, pthread_attr_getdetachstate); 500490f058SHasso Tepper WR(stub_zero, pthread_attr_getguardsize); 5182205bfbSSimon Schubert WR(stub_zero, pthread_attr_getinheritsched); 5282205bfbSSimon Schubert WR(stub_zero, pthread_attr_getschedparam); 5382205bfbSSimon Schubert WR(stub_zero, pthread_attr_getschedpolicy); 5482205bfbSSimon Schubert WR(stub_zero, pthread_attr_getscope); 5582205bfbSSimon Schubert WR(stub_zero, pthread_attr_getstack); 5682205bfbSSimon Schubert WR(stub_zero, pthread_attr_getstackaddr); 5782205bfbSSimon Schubert WR(stub_zero, pthread_attr_getstacksize); 5882205bfbSSimon Schubert WR(stub_zero, pthread_attr_init); 5982205bfbSSimon Schubert WR(stub_zero, pthread_attr_setcreatesuspend_np); 6082205bfbSSimon Schubert WR(stub_zero, pthread_attr_setdetachstate); 610490f058SHasso Tepper WR(stub_zero, pthread_attr_setguardsize); 6282205bfbSSimon Schubert WR(stub_zero, pthread_attr_setinheritsched); 6382205bfbSSimon Schubert WR(stub_zero, pthread_attr_setschedparam); 6482205bfbSSimon Schubert WR(stub_zero, pthread_attr_setschedpolicy); 6582205bfbSSimon Schubert WR(stub_zero, pthread_attr_setscope); 6682205bfbSSimon Schubert WR(stub_zero, pthread_attr_setstack); 6782205bfbSSimon Schubert WR(stub_zero, pthread_attr_setstackaddr); 6882205bfbSSimon Schubert WR(stub_zero, pthread_attr_setstacksize); 690490f058SHasso Tepper WR(stub_zero, pthread_barrier_destroy); 700490f058SHasso Tepper WR(stub_zero, pthread_barrier_init); 710490f058SHasso Tepper WR(stub_zero, pthread_barrier_wait); 720490f058SHasso Tepper WR(stub_zero, pthread_barrierattr_destroy); 730490f058SHasso Tepper WR(stub_zero, pthread_barrierattr_getpshared); 740490f058SHasso Tepper WR(stub_zero, pthread_barrierattr_init); 750490f058SHasso Tepper WR(stub_zero, pthread_barrierattr_setpshared); 7682205bfbSSimon Schubert WR(stub_zero, pthread_cancel); 7782205bfbSSimon Schubert WR(stub_zero, pthread_cleanup_pop); 7882205bfbSSimon Schubert WR(stub_zero, pthread_cleanup_push); 7982205bfbSSimon Schubert WR(stub_zero, pthread_cond_broadcast); 8082205bfbSSimon Schubert WR(stub_zero, pthread_cond_destroy); 8182205bfbSSimon Schubert WR(stub_zero, pthread_cond_init); 8282205bfbSSimon Schubert WR(stub_zero, pthread_cond_signal); 8382205bfbSSimon Schubert WR(stub_zero, pthread_cond_timedwait); 8482205bfbSSimon Schubert WR(stub_zero, pthread_cond_wait); 8582205bfbSSimon Schubert WR(stub_zero, pthread_condattr_destroy); 860490f058SHasso Tepper WR(stub_zero, pthread_condattr_getclock); 870490f058SHasso Tepper WR(stub_zero, pthread_condattr_getpshared); 8882205bfbSSimon Schubert WR(stub_zero, pthread_condattr_init); 890490f058SHasso Tepper WR(stub_zero, pthread_condattr_setclock); 900490f058SHasso Tepper WR(stub_zero, pthread_condattr_setpshared); 9182205bfbSSimon Schubert WR(stub_zero, pthread_detach); 9282205bfbSSimon Schubert WR(stub_true, pthread_equal); 9382205bfbSSimon Schubert WR(stub_exit, pthread_exit); 9482205bfbSSimon Schubert WR(stub_zero, pthread_getconcurrency); 9582205bfbSSimon Schubert WR(stub_zero, pthread_getprio); 9682205bfbSSimon Schubert WR(stub_zero, pthread_getschedparam); 9782205bfbSSimon Schubert WR(stub_null, pthread_getspecific); 98a809fd39SMarkus Pfeiffer WR(stub_empty, pthread_init_early); 9982205bfbSSimon Schubert WR(stub_zero, pthread_join); 10082205bfbSSimon Schubert WR(stub_zero, pthread_key_create); 10182205bfbSSimon Schubert WR(stub_zero, pthread_key_delete); 10282205bfbSSimon Schubert WR(stub_zero, pthread_kill); 10382205bfbSSimon Schubert WR(stub_main, pthread_main_np); 10482205bfbSSimon Schubert WR(stub_zero, pthread_multi_np); 10582205bfbSSimon Schubert WR(stub_zero, pthread_mutex_destroy); 10682205bfbSSimon Schubert WR(stub_zero, pthread_mutex_getprioceiling); 10782205bfbSSimon Schubert WR(stub_zero, pthread_mutex_init); 10882205bfbSSimon Schubert WR(stub_zero, pthread_mutex_lock); 10982205bfbSSimon Schubert WR(stub_zero, pthread_mutex_setprioceiling); 1100490f058SHasso Tepper WR(stub_zero, pthread_mutex_timedlock); 11182205bfbSSimon Schubert WR(stub_zero, pthread_mutex_trylock); 11282205bfbSSimon Schubert WR(stub_zero, pthread_mutex_unlock); 11382205bfbSSimon Schubert WR(stub_zero, pthread_mutexattr_destroy); 11482205bfbSSimon Schubert WR(stub_zero, pthread_mutexattr_getkind_np); 11582205bfbSSimon Schubert WR(stub_zero, pthread_mutexattr_getprioceiling); 11682205bfbSSimon Schubert WR(stub_zero, pthread_mutexattr_getprotocol); 11782205bfbSSimon Schubert WR(stub_zero, pthread_mutexattr_getpshared); 11882205bfbSSimon Schubert WR(stub_zero, pthread_mutexattr_gettype); 11982205bfbSSimon Schubert WR(stub_zero, pthread_mutexattr_init); 12082205bfbSSimon Schubert WR(stub_zero, pthread_mutexattr_setkind_np); 12182205bfbSSimon Schubert WR(stub_zero, pthread_mutexattr_setprioceiling); 12282205bfbSSimon Schubert WR(stub_zero, pthread_mutexattr_setprotocol); 12382205bfbSSimon Schubert WR(stub_zero, pthread_mutexattr_setpshared); 12482205bfbSSimon Schubert WR(stub_zero, pthread_mutexattr_settype); 1256692f0a1SAlex Hornung WR(stub_once, pthread_once); 12682205bfbSSimon Schubert WR(stub_zero, pthread_resume_all_np); 12782205bfbSSimon Schubert WR(stub_zero, pthread_resume_np); 12882205bfbSSimon Schubert WR(stub_zero, pthread_rwlock_destroy); 12982205bfbSSimon Schubert WR(stub_zero, pthread_rwlock_init); 13082205bfbSSimon Schubert WR(stub_zero, pthread_rwlock_rdlock); 1310490f058SHasso Tepper WR(stub_zero, pthread_rwlock_timedrdlock); 1320490f058SHasso Tepper WR(stub_zero, pthread_rwlock_timedwrlock); 13382205bfbSSimon Schubert WR(stub_zero, pthread_rwlock_tryrdlock); 13482205bfbSSimon Schubert WR(stub_zero, pthread_rwlock_trywrlock); 13582205bfbSSimon Schubert WR(stub_zero, pthread_rwlock_unlock); 13682205bfbSSimon Schubert WR(stub_zero, pthread_rwlock_wrlock); 13782205bfbSSimon Schubert WR(stub_zero, pthread_rwlockattr_destroy); 13882205bfbSSimon Schubert WR(stub_zero, pthread_rwlockattr_getpshared); 13982205bfbSSimon Schubert WR(stub_zero, pthread_rwlockattr_init); 14082205bfbSSimon Schubert WR(stub_zero, pthread_rwlockattr_setpshared); 14182205bfbSSimon Schubert WR(stub_self, pthread_self); 14282205bfbSSimon Schubert WR(stub_zero, pthread_set_name_np); 14382205bfbSSimon Schubert WR(stub_zero, pthread_setcancelstate); 14482205bfbSSimon Schubert WR(stub_zero, pthread_setcanceltype); 14582205bfbSSimon Schubert WR(stub_zero, pthread_setconcurrency); 14682205bfbSSimon Schubert WR(stub_zero, pthread_setprio); 14782205bfbSSimon Schubert WR(stub_zero, pthread_setschedparam); 14882205bfbSSimon Schubert WR(stub_zero, pthread_setspecific); 14982205bfbSSimon Schubert WR(stub_zero, pthread_sigmask); 15082205bfbSSimon Schubert WR(stub_zero, pthread_single_np); 1510490f058SHasso Tepper WR(stub_zero, pthread_spin_destroy); 1520490f058SHasso Tepper WR(stub_zero, pthread_spin_init); 1530490f058SHasso Tepper WR(stub_zero, pthread_spin_lock); 1540490f058SHasso Tepper WR(stub_zero, pthread_spin_trylock); 1550490f058SHasso Tepper WR(stub_zero, pthread_spin_unlock); 15682205bfbSSimon Schubert WR(stub_zero, pthread_suspend_all_np); 15782205bfbSSimon Schubert WR(stub_zero, pthread_suspend_np); 15882205bfbSSimon Schubert WR(stub_zero, pthread_switch_add_np); 15982205bfbSSimon Schubert WR(stub_zero, pthread_switch_delete_np); 16082205bfbSSimon Schubert WR(stub_zero, pthread_testcancel); 1610490f058SHasso Tepper WR(stub_zero, pthread_timedjoin_np); 16282205bfbSSimon Schubert WR(stub_zero, pthread_yield); 16382205bfbSSimon Schubert WR(stub_zero, sched_yield); 16482205bfbSSimon Schubert WR(stub_zero, sem_close); 16582205bfbSSimon Schubert WR(stub_zero, sem_destroy); 16682205bfbSSimon Schubert WR(stub_zero, sem_getvalue); 16782205bfbSSimon Schubert WR(stub_zero, sem_init); 16882205bfbSSimon Schubert WR(stub_zero, sem_open); 16982205bfbSSimon Schubert WR(stub_zero, sem_post); 17082205bfbSSimon Schubert WR(stub_zero, sem_trywait); 171775923a8SSascha Wildner WR(stub_zero, sem_timedwait); 17282205bfbSSimon Schubert WR(stub_zero, sem_unlink); 17382205bfbSSimon Schubert WR(stub_zero, sem_wait); 17482205bfbSSimon Schubert 17582205bfbSSimon Schubert 17682205bfbSSimon Schubert static int __used 17782205bfbSSimon Schubert stub_zero(void) 178ce0e08e2SPeter Avalos { 179ce0e08e2SPeter Avalos return (0); 180ce0e08e2SPeter Avalos } 181ce0e08e2SPeter Avalos 1826692f0a1SAlex Hornung static int __used 1836692f0a1SAlex Hornung stub_once(pthread_once_t *o, void (*r)(void)) 1846692f0a1SAlex Hornung { 1856692f0a1SAlex Hornung if (o->state != PTHREAD_DONE_INIT) { 1866692f0a1SAlex Hornung (*r)(); 1876692f0a1SAlex Hornung o->state = PTHREAD_DONE_INIT; 1886692f0a1SAlex Hornung } 1896692f0a1SAlex Hornung 1906692f0a1SAlex Hornung return (0); 1916692f0a1SAlex Hornung } 1926692f0a1SAlex Hornung 19382205bfbSSimon Schubert static void * __used 19482205bfbSSimon Schubert stub_null(void) 19517ea2221SMatthew Dillon { 19617ea2221SMatthew Dillon return (NULL); 19717ea2221SMatthew Dillon } 19817ea2221SMatthew Dillon 19982205bfbSSimon Schubert static void * __used 20082205bfbSSimon Schubert stub_self(void) 20117ea2221SMatthew Dillon { 20282205bfbSSimon Schubert static struct {} main_thread; 20382205bfbSSimon Schubert 20482205bfbSSimon Schubert return (&main_thread); 20517ea2221SMatthew Dillon } 20617ea2221SMatthew Dillon 20782205bfbSSimon Schubert static int __used 20882205bfbSSimon Schubert stub_main(void) 209ce0e08e2SPeter Avalos { 210ce0e08e2SPeter Avalos return (-1); 211ce0e08e2SPeter Avalos } 212ce0e08e2SPeter Avalos 21382205bfbSSimon Schubert static int __used 21482205bfbSSimon Schubert stub_true(void) 21517ea2221SMatthew Dillon { 21682205bfbSSimon Schubert return (1); 21717ea2221SMatthew Dillon } 21817ea2221SMatthew Dillon 21982205bfbSSimon Schubert static void __used 220a809fd39SMarkus Pfeiffer stub_empty(void) 221a809fd39SMarkus Pfeiffer { 222a809fd39SMarkus Pfeiffer } 223a809fd39SMarkus Pfeiffer 224a809fd39SMarkus Pfeiffer static void __used 22582205bfbSSimon Schubert stub_exit(void) 22617ea2221SMatthew Dillon { 22782205bfbSSimon Schubert exit(0); 228ce0e08e2SPeter Avalos } 229a809fd39SMarkus Pfeiffer 230a809fd39SMarkus Pfeiffer /* 231a809fd39SMarkus Pfeiffer * If libpthread is loaded, make sure it is initialised before 232a809fd39SMarkus Pfeiffer * other libraries call pthread functions 233a809fd39SMarkus Pfeiffer */ 234450f08dbSSascha Wildner void _pthread_init(void) __constructor(101); 235450f08dbSSascha Wildner void _pthread_init_early(void); 236a809fd39SMarkus Pfeiffer void 237a809fd39SMarkus Pfeiffer _pthread_init(void) 238a809fd39SMarkus Pfeiffer { 239a809fd39SMarkus Pfeiffer _pthread_init_early(); 240a809fd39SMarkus Pfeiffer } 241*82657471SMarkus Pfeiffer 242*82657471SMarkus Pfeiffer extern void (*cb_prepare)(void); 243*82657471SMarkus Pfeiffer extern void (*cb_parent)(void); 244*82657471SMarkus Pfeiffer extern void (*cb_child)(void); 245*82657471SMarkus Pfeiffer extern int __isthreaded; 246*82657471SMarkus Pfeiffer 247*82657471SMarkus Pfeiffer int 248*82657471SMarkus Pfeiffer __atfork(void (*prepare)(void), void (*parent)(void), 249*82657471SMarkus Pfeiffer void (*child)(void)) 250*82657471SMarkus Pfeiffer { 251*82657471SMarkus Pfeiffer if (__isthreaded) 252*82657471SMarkus Pfeiffer return (-1); 253*82657471SMarkus Pfeiffer cb_prepare = prepare; 254*82657471SMarkus Pfeiffer cb_parent = parent; 255*82657471SMarkus Pfeiffer cb_child = child; 256*82657471SMarkus Pfeiffer return (0); 257*82657471SMarkus Pfeiffer } 258