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 * 2617ea2221SMatthew Dillon * $FreeBSD: /repoman/r/ncvs/src/lib/libc/gen/_pthread_stubs.c,v 1.1 2001/01/24 12:59:20 deischen Exp $ 27*19c7a913SDavid Xu * $DragonFly: src/lib/libc/gen/_pthread_stubs.c,v 1.4 2005/05/09 12:43:40 davidxu Exp $ 2817ea2221SMatthew Dillon */ 2917ea2221SMatthew Dillon 3017ea2221SMatthew Dillon #include <pthread.h> 3117ea2221SMatthew Dillon 32cd73ef72SJoerg Sonnenberger void *_pthread_getspecific_stub(pthread_key_t); 33cd73ef72SJoerg Sonnenberger int _pthread_key_create_stub(pthread_key_t *, void (*)(void *)); 34cd73ef72SJoerg Sonnenberger int _pthread_key_delete_stub(pthread_key_t); 35cd73ef72SJoerg Sonnenberger int _pthread_mutex_destroy_stub(pthread_mutex_t *); 36cd73ef72SJoerg Sonnenberger int _pthread_mutex_init_stub(pthread_mutex_t *, 37cd73ef72SJoerg Sonnenberger const pthread_mutexattr_t *); 38cd73ef72SJoerg Sonnenberger int _pthread_mutex_lock_stub(pthread_mutex_t *); 39cd73ef72SJoerg Sonnenberger int _pthread_mutex_trylock_stub(pthread_mutex_t *); 40cd73ef72SJoerg Sonnenberger int _pthread_mutex_unlock_stub(pthread_mutex_t *); 41cd73ef72SJoerg Sonnenberger int _pthread_mutexattr_init_stub(pthread_mutexattr_t *); 42cd73ef72SJoerg Sonnenberger int _pthread_mutexattr_destroy_stub(pthread_mutexattr_t *); 43cd73ef72SJoerg Sonnenberger int _pthread_mutexattr_settype_stub(pthread_mutexattr_t *, int); 44cd73ef72SJoerg Sonnenberger int _pthread_once_stub(pthread_once_t *, void (*)(void)); 45cd73ef72SJoerg Sonnenberger int _pthread_setspecific_stub(pthread_key_t, const void *); 46cd73ef72SJoerg Sonnenberger 47*19c7a913SDavid Xu /* define a null pthread structure just to satisfy _pthread_self */ 48*19c7a913SDavid Xu struct pthread { 49*19c7a913SDavid Xu }; 50*19c7a913SDavid Xu 51*19c7a913SDavid Xu static struct pthread main_thread; 52*19c7a913SDavid Xu 5317ea2221SMatthew Dillon /* 5417ea2221SMatthew Dillon * Weak symbols: All libc internal usage of these functions should 5517ea2221SMatthew Dillon * use the weak symbol versions (_pthread_XXX). If libpthread is 5617ea2221SMatthew Dillon * linked, it will override these functions with (non-weak) routines. 5717ea2221SMatthew Dillon * The _pthread_XXX functions are provided solely for internal libc 5817ea2221SMatthew Dillon * usage to avoid unwanted cancellation points and to differentiate 5917ea2221SMatthew Dillon * between application locks and libc locks (threads holding the 6017ea2221SMatthew Dillon * latter can't be allowed to exit/terminate). 6117ea2221SMatthew Dillon */ 625dd49d16SJoerg Sonnenberger __weak_reference(_pthread_getspecific_stub,_pthread_getspecific); 635dd49d16SJoerg Sonnenberger __weak_reference(_pthread_key_create_stub,_pthread_key_create); 645dd49d16SJoerg Sonnenberger __weak_reference(_pthread_key_delete_stub,_pthread_key_delete); 655dd49d16SJoerg Sonnenberger __weak_reference(_pthread_mutex_destroy_stub,_pthread_mutex_destroy); 665dd49d16SJoerg Sonnenberger __weak_reference(_pthread_mutex_init_stub,_pthread_mutex_init); 675dd49d16SJoerg Sonnenberger __weak_reference(_pthread_mutex_lock_stub,_pthread_mutex_lock); 685dd49d16SJoerg Sonnenberger __weak_reference(_pthread_mutex_trylock_stub,_pthread_mutex_trylock); 695dd49d16SJoerg Sonnenberger __weak_reference(_pthread_mutex_unlock_stub,_pthread_mutex_unlock); 705dd49d16SJoerg Sonnenberger __weak_reference(_pthread_mutexattr_init_stub,_pthread_mutexattr_init); 715dd49d16SJoerg Sonnenberger __weak_reference(_pthread_mutexattr_destroy_stub,_pthread_mutexattr_destroy); 725dd49d16SJoerg Sonnenberger __weak_reference(_pthread_mutexattr_settype_stub,_pthread_mutexattr_settype); 735dd49d16SJoerg Sonnenberger __weak_reference(_pthread_once_stub,_pthread_once); 745dd49d16SJoerg Sonnenberger __weak_reference(_pthread_setspecific_stub,_pthread_setspecific); 75*19c7a913SDavid Xu __weak_reference(_pthread_self_stub,_pthread_self); 7617ea2221SMatthew Dillon 7717ea2221SMatthew Dillon void * 78cd73ef72SJoerg Sonnenberger _pthread_getspecific_stub(pthread_key_t key __unused) 7917ea2221SMatthew Dillon { 8017ea2221SMatthew Dillon return (NULL); 8117ea2221SMatthew Dillon } 8217ea2221SMatthew Dillon 8317ea2221SMatthew Dillon int 84cd73ef72SJoerg Sonnenberger _pthread_key_create_stub(pthread_key_t *key __unused, 85cd73ef72SJoerg Sonnenberger void (*destructor) (void *) __unused) 8617ea2221SMatthew Dillon { 8717ea2221SMatthew Dillon return (0); 8817ea2221SMatthew Dillon } 8917ea2221SMatthew Dillon 9017ea2221SMatthew Dillon int 91cd73ef72SJoerg Sonnenberger _pthread_key_delete_stub(pthread_key_t key __unused) 9217ea2221SMatthew Dillon { 9317ea2221SMatthew Dillon return (0); 9417ea2221SMatthew Dillon } 9517ea2221SMatthew Dillon 9617ea2221SMatthew Dillon int 97cd73ef72SJoerg Sonnenberger _pthread_mutex_destroy_stub(pthread_mutex_t *mattr __unused) 9817ea2221SMatthew Dillon { 9917ea2221SMatthew Dillon return (0); 10017ea2221SMatthew Dillon } 10117ea2221SMatthew Dillon 10217ea2221SMatthew Dillon int 103cd73ef72SJoerg Sonnenberger _pthread_mutex_init_stub(pthread_mutex_t *mutex __unused, 104cd73ef72SJoerg Sonnenberger const pthread_mutexattr_t *mattr __unused) 10517ea2221SMatthew Dillon { 10617ea2221SMatthew Dillon return (0); 10717ea2221SMatthew Dillon } 10817ea2221SMatthew Dillon 10917ea2221SMatthew Dillon int 110cd73ef72SJoerg Sonnenberger _pthread_mutex_lock_stub(pthread_mutex_t *mutex __unused) 11117ea2221SMatthew Dillon { 11217ea2221SMatthew Dillon return (0); 11317ea2221SMatthew Dillon } 11417ea2221SMatthew Dillon 11517ea2221SMatthew Dillon int 116cd73ef72SJoerg Sonnenberger _pthread_mutex_trylock_stub(pthread_mutex_t *mutex __unused) 11717ea2221SMatthew Dillon { 11817ea2221SMatthew Dillon return (0); 11917ea2221SMatthew Dillon } 12017ea2221SMatthew Dillon 12117ea2221SMatthew Dillon int 122cd73ef72SJoerg Sonnenberger _pthread_mutex_unlock_stub(pthread_mutex_t *mutex __unused) 12317ea2221SMatthew Dillon { 12417ea2221SMatthew Dillon return (0); 12517ea2221SMatthew Dillon } 12617ea2221SMatthew Dillon 12717ea2221SMatthew Dillon int 128cd73ef72SJoerg Sonnenberger _pthread_mutexattr_init_stub(pthread_mutexattr_t *mattr __unused) 12917ea2221SMatthew Dillon { 13017ea2221SMatthew Dillon return (0); 13117ea2221SMatthew Dillon } 13217ea2221SMatthew Dillon 13317ea2221SMatthew Dillon int 134cd73ef72SJoerg Sonnenberger _pthread_mutexattr_destroy_stub(pthread_mutexattr_t *mattr __unused) 13517ea2221SMatthew Dillon { 13617ea2221SMatthew Dillon return (0); 13717ea2221SMatthew Dillon } 13817ea2221SMatthew Dillon 13917ea2221SMatthew Dillon int 140cd73ef72SJoerg Sonnenberger _pthread_mutexattr_settype_stub(pthread_mutexattr_t *mattr __unused, 141cd73ef72SJoerg Sonnenberger int type __unused) 14217ea2221SMatthew Dillon { 14317ea2221SMatthew Dillon return (0); 14417ea2221SMatthew Dillon } 14517ea2221SMatthew Dillon 14617ea2221SMatthew Dillon int 147cd73ef72SJoerg Sonnenberger _pthread_once_stub(pthread_once_t *once_control __unused, 148cd73ef72SJoerg Sonnenberger void (*init_routine) (void) __unused) 14917ea2221SMatthew Dillon { 15017ea2221SMatthew Dillon return (0); 15117ea2221SMatthew Dillon } 15217ea2221SMatthew Dillon 153*19c7a913SDavid Xu struct pthread * 154*19c7a913SDavid Xu _pthread_self_stub(void) 155*19c7a913SDavid Xu { 156*19c7a913SDavid Xu return (&main_thread); 157*19c7a913SDavid Xu } 15817ea2221SMatthew Dillon int 159cd73ef72SJoerg Sonnenberger _pthread_setspecific_stub(pthread_key_t key __unused, 160cd73ef72SJoerg Sonnenberger const void *value __unused) 16117ea2221SMatthew Dillon { 16217ea2221SMatthew Dillon return (0); 16317ea2221SMatthew Dillon } 16417ea2221SMatthew Dillon 165