110a4fa49Srie /* 210a4fa49Srie * CDDL HEADER START 310a4fa49Srie * 410a4fa49Srie * The contents of this file are subject to the terms of the 510a4fa49Srie * Common Development and Distribution License (the "License"). 610a4fa49Srie * You may not use this file except in compliance with the License. 710a4fa49Srie * 810a4fa49Srie * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 910a4fa49Srie * or http://www.opensolaris.org/os/licensing. 1010a4fa49Srie * See the License for the specific language governing permissions 1110a4fa49Srie * and limitations under the License. 1210a4fa49Srie * 1310a4fa49Srie * When distributing Covered Code, include this CDDL HEADER in each 1410a4fa49Srie * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 1510a4fa49Srie * If applicable, add the following below this CDDL HEADER, with the 1610a4fa49Srie * fields enclosed by brackets "[]" replaced with your own identifying 1710a4fa49Srie * information: Portions Copyright [yyyy] [name of copyright owner] 1810a4fa49Srie * 1910a4fa49Srie * CDDL HEADER END 2010a4fa49Srie */ 2110a4fa49Srie 2210a4fa49Srie /* 23a574db85Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 2410a4fa49Srie * Use is subject to license terms. 2510a4fa49Srie */ 26a574db85Sraf 2710a4fa49Srie #pragma ident "%Z%%M% %I% %E% SMI" 2810a4fa49Srie 2910a4fa49Srie /* 3010a4fa49Srie * Implementation of all external interfaces between ld.so.1 and libc. 3110a4fa49Srie * 3210a4fa49Srie * This file started as a set of routines that provided synchronization and 3310a4fa49Srie * locking operations using calls to libthread. libthread has merged with libc, 3410a4fa49Srie * and things have gotten a little simpler. This file continues to establish 3510a4fa49Srie * and redirect various events within ld.so.1 to interfaces within libc. 3610a4fa49Srie * 3710a4fa49Srie * Until libc is loaded and relocated, any external interfaces are captured 3810a4fa49Srie * locally. Each link-map list maintains its own set of external vectors, as 3910a4fa49Srie * each link-map list typically provides its own libc. Although this per-link- 4010a4fa49Srie * map list vectoring provides a degree of flexibility, there is a protocol 4110a4fa49Srie * expected when calling various libc interfaces. 4210a4fa49Srie * 4310a4fa49Srie * i. Any new alternative link-map list should call CI_THRINIT, and then call 4410a4fa49Srie * CI_TLS_MODADD to register any TLS for each object of that link-map list 4510a4fa49Srie * (this item is labeled i. as auditors can be the first objects loaded, 4610a4fa49Srie * and they exist on their own lik-map list). 4710a4fa49Srie * 4810a4fa49Srie * ii. For the primary link-map list, CI_TLS_STATMOD must be called first to 4910a4fa49Srie * register any static TLS. This routine is called regardless of there 5010a4fa49Srie * being any TLS, as this routine also establishes the link-map list as the 5110a4fa49Srie * primary list and fixes the association of uberdata). CI_THRINIT should 5210a4fa49Srie * then be called. 5310a4fa49Srie * 5410a4fa49Srie * iii. Any objects added to an existing link-map list (primary or alternative) 5510a4fa49Srie * should call CI_TLS_MODADD to register any additional TLS. 5610a4fa49Srie * 5710a4fa49Srie * These events are established by: 5810a4fa49Srie * 5910a4fa49Srie * i. Typically, libc is loaded as part of the primary dependencies of any 6010a4fa49Srie * link-map list (since the Unified Process Model (UPM), libc can't be 6110a4fa49Srie * lazily loaded). To minimize the possibility of loading and registering 6210a4fa49Srie * objects, and then tearing them down (because of a relocation error), 6310a4fa49Srie * external vectors are established as part of load_completion(). This 6410a4fa49Srie * routine is called on completion of any operation that can cause objects 6510a4fa49Srie * to be loaded. This point of control insures the objects have been fully 6610a4fa49Srie * analyzed and relocated, and moved to their controlling link-map list. 6710a4fa49Srie * The external vectors are established prior to any .inits being fired. 6810a4fa49Srie * 6910a4fa49Srie * ii. Calls to CI_THRINIT, and CI_TLS_MODADD also occur as part of 7010a4fa49Srie * load_completion(). CI_THRINIT is only called once for each link-map 7110a4fa49Srie * control list. 7210a4fa49Srie * 7310a4fa49Srie * iii. Calls to CI_TLS_STATMOD, and CI_THRINIT occur for the primary link-map 7410a4fa49Srie * list in the final stages of setup(). 7510a4fa49Srie * 7610a4fa49Srie * The interfaces provide by libc can be divided into two families. The first 7710a4fa49Srie * family consists of those interfaces that should be called from the link-map 7810a4fa49Srie * list. It's possible that these interfaces convey state concerning the 7910a4fa49Srie * link-map list they are part of: 8010a4fa49Srie * 8110a4fa49Srie * CI_ATEXIT 8210a4fa49Srie * CI TLS_MODADD 8310a4fa49Srie * CI_TLS_MODREM 8410a4fa49Srie * CI_TLS_STATMOD 8510a4fa49Srie * CI_THRINIT 8610a4fa49Srie * 8710a4fa49Srie * The second family are global in nature, that is, the link-map list from 8810a4fa49Srie * which they are called provides no state information. In fact, for 8910a4fa49Srie * CI_BIND_GUARD, the calling link-map isn't even known. The link-map can only 9010a4fa49Srie * be deduced after ld.so.1's global lock has been obtained. Therefore, the 9110a4fa49Srie * following interfaces are also maintained as global: 9210a4fa49Srie * 9310a4fa49Srie * CI_LCMESSAGES 9410a4fa49Srie * CI_BIND_GUARD 9510a4fa49Srie * CI_BIND_CLEAR 9610a4fa49Srie * CI_THR_SELF 9710a4fa49Srie * 9810a4fa49Srie * Note, it is possible that these global interfaces are obtained from an 9910a4fa49Srie * alternative link-map list that gets torn down because of a processing 10010a4fa49Srie * failure (unlikely, because the link-map list components must be analyzed 10110a4fa49Srie * and relocated prior to load_completion(), but perhaps the tear down is still 10210a4fa49Srie * a possibility). Thus the global interfaces may have to be replaced. Once 10310a4fa49Srie * the interfaces have been obtained from the primary link-map, they can 10410a4fa49Srie * remain fixed, as the primary link-map isn't going to go anywhere. 10510a4fa49Srie * 10610a4fa49Srie * The last wrinkle in the puzzle is what happens if an alternative link-map 10710a4fa49Srie * is loaded with no libc dependency? In this case, the alternative objects 10810a4fa49Srie * can not call CI_THRINIT, can not be allowed to use TLS, and will not receive 10910a4fa49Srie * any atexit processing. 11010a4fa49Srie * 11110a4fa49Srie * The history of these external interfaces is defined by their version: 11210a4fa49Srie * 11310a4fa49Srie * TI_VERSION == 1 11410a4fa49Srie * Under this model libthread provided rw_rwlock/rw_unlock, through which 11510a4fa49Srie * all rt_mutex_lock/rt_mutex_unlock calls were vectored. 11610a4fa49Srie * Under libc/libthread these interfaces provided _sigon/_sigoff (unlike 11710a4fa49Srie * lwp/libthread that provided signal blocking via bind_guard/bind_clear). 11810a4fa49Srie * 11910a4fa49Srie * TI_VERSION == 2 12010a4fa49Srie * Under this model only libthreads bind_guard/bind_clear and thr_self 12110a4fa49Srie * interfaces were used. Both libthreads blocked signals under the 12210a4fa49Srie * bind_guard/bind_clear interfaces. Lower level locking is derived 12310a4fa49Srie * from internally bound _lwp_ interfaces. This removes recursive 12410a4fa49Srie * problems encountered when obtaining locking interfaces from libthread. 12510a4fa49Srie * The use of mutexes over reader/writer locks also enables the use of 12610a4fa49Srie * condition variables for controlling thread concurrency (allows access 12710a4fa49Srie * to objects only after their .init has completed). 12810a4fa49Srie * 12910a4fa49Srie * NOTE, the TI_VERSION indicated the ti_interface version number, where the 13010a4fa49Srie * ti_interface was a large vector of functions passed to both libc (to override 13110a4fa49Srie * the thread stub interfaces) and ld.so.1. ld.so.1 used only a small subset of 13210a4fa49Srie * these interfaces. 13310a4fa49Srie * 13410a4fa49Srie * CI_VERSION == 1 13510a4fa49Srie * Introduced with CI_VERSION & CI_ATEXIT 13610a4fa49Srie * 13710a4fa49Srie * CI_VERSION == 2 (Solaris 8 update 2). 13810a4fa49Srie * Added support for CI_LCMESSAGES 13910a4fa49Srie * 14010a4fa49Srie * CI_VERSION == 3 (Solaris 9). 14110a4fa49Srie * Added the following versions to the CI table: 14210a4fa49Srie * 14310a4fa49Srie * CI_BIND_GUARD, CI_BIND_CLEAR, CI_THR_SELF 14410a4fa49Srie * CI_TLS_MODADD, CI_TLS_MOD_REMOVE, CI_TLS_STATMOD 14510a4fa49Srie * 14610a4fa49Srie * This version introduced the DT_SUNW_RTLDINFO structure as a mechanism 14710a4fa49Srie * to handshake with ld.so.1. 14810a4fa49Srie * 14910a4fa49Srie * CI_VERSION == 4 (Solaris 10). 15010a4fa49Srie * Added the CI_THRINIT handshake as part of the libc/libthread unified 15110a4fa49Srie * process model. libc now initializes the current thread pointer from 15210a4fa49Srie * this interface (and no longer relies on the INITFIRST flag - which 15310a4fa49Srie * others have started to camp out on). 15410a4fa49Srie * 15510a4fa49Srie * Release summary: 15610a4fa49Srie * 15710a4fa49Srie * Solaris 8 CI_ATEXIT via _ld_libc() 15810a4fa49Srie * TI_* via _ld_concurrency() 15910a4fa49Srie * 16010a4fa49Srie * Solaris 9 CI_ATEXIT and CI_LCMESSAGES via _ld_libc() 16110a4fa49Srie * CI_* via RTLDINFO and _ld_libc() - new libthread 16210a4fa49Srie * TI_* via _ld_concurrency() - old libthread 16310a4fa49Srie * 16410a4fa49Srie * Solaris 10 CI_ATEXIT and CI_LCMESSAGES via _ld_libc() 16510a4fa49Srie * CI_* via RTLDINFO and _ld_libc() - new libthread 16610a4fa49Srie */ 167a574db85Sraf 168a574db85Sraf #include "_synonyms.h" 169a574db85Sraf #include <sys/debug.h> 170a574db85Sraf #include <synch.h> 171a574db85Sraf #include <signal.h> 172a574db85Sraf #include <thread.h> 173a574db85Sraf #include <synch.h> 174a574db85Sraf #include <strings.h> 175a574db85Sraf #include <stdio.h> 176a574db85Sraf #include <debug.h> 177a574db85Sraf #include <libc_int.h> 178a574db85Sraf #include "_elf.h" 179a574db85Sraf #include "_rtld.h" 18010a4fa49Srie 18110a4fa49Srie /* 18210a4fa49Srie * This interface provides the unified process model communication between 18310a4fa49Srie * ld.so.1 and libc. This interface is supplied through RTLDINFO. 18410a4fa49Srie */ 18510a4fa49Srie void 18610a4fa49Srie get_lcinterface(Rt_map *lmp, Lc_interface *funcs) 18710a4fa49Srie { 18810a4fa49Srie int tag, threaded = 0; 18910a4fa49Srie Lm_list *lml; 19010a4fa49Srie Lc_desc *lcp; 19110a4fa49Srie 19210a4fa49Srie if ((lmp == 0) || (funcs == 0)) 19310a4fa49Srie return; 19410a4fa49Srie 19510a4fa49Srie lml = LIST(lmp); 19610a4fa49Srie lcp = &lml->lm_lcs[0]; 19710a4fa49Srie 19810a4fa49Srie DBG_CALL(Dbg_util_nl(lml, DBG_NL_STD)); 19910a4fa49Srie 20010a4fa49Srie for (tag = funcs->ci_tag; tag; tag = (++funcs)->ci_tag) { 20110a4fa49Srie char *gptr; 20210a4fa49Srie char *lptr = funcs->ci_un.ci_ptr; 20310a4fa49Srie 20410a4fa49Srie DBG_CALL(Dbg_util_lcinterface(lmp, tag, lptr)); 20510a4fa49Srie 20610a4fa49Srie if (tag >= CI_MAX) 20710a4fa49Srie continue; 20810a4fa49Srie 20910a4fa49Srie /* 21010a4fa49Srie * Maintain all interfaces on a per-link-map basis. Note, for 21110a4fa49Srie * most interfaces, only the first interface is used for any 21210a4fa49Srie * link-map list. This prevents accidents with developers who 21310a4fa49Srie * manage to load two different versions of libc. 21410a4fa49Srie */ 21510a4fa49Srie if ((lcp[tag].lc_lmp) && 21610a4fa49Srie (tag != CI_LCMESSAGES) && (tag != CI_VERSION)) { 21710a4fa49Srie DBG_CALL(Dbg_unused_lcinterface(lmp, 21810a4fa49Srie lcp[tag].lc_lmp, tag)); 21910a4fa49Srie continue; 22010a4fa49Srie } 22110a4fa49Srie 22210a4fa49Srie lcp[tag].lc_un.lc_ptr = lptr; 22310a4fa49Srie lcp[tag].lc_lmp = lmp; 22410a4fa49Srie 22510a4fa49Srie gptr = glcs[tag].lc_un.lc_ptr; 22610a4fa49Srie 22710a4fa49Srie /* 22810a4fa49Srie * Process any interfaces that must be maintained on a global 22910a4fa49Srie * basis. 23010a4fa49Srie */ 23110a4fa49Srie switch (tag) { 23210a4fa49Srie case CI_ATEXIT: 23310a4fa49Srie break; 23410a4fa49Srie 23510a4fa49Srie case CI_LCMESSAGES: 23610a4fa49Srie /* 23710a4fa49Srie * At startup, ld.so.1 can establish a locale from one 23810a4fa49Srie * of the locale family of environment variables (see 23910a4fa49Srie * ld_str_env() and readenv_user()). During process 24010a4fa49Srie * execution the locale can also be changed by the user. 24110a4fa49Srie * This interface is called from libc should the locale 24210a4fa49Srie * be modified. Presently, only one global locale is 24310a4fa49Srie * maintained for all link-map lists, and only objects 24410a4fa49Srie * on the primrary link-map may change this locale. 24510a4fa49Srie */ 24610a4fa49Srie if ((lml->lm_flags & LML_FLG_BASELM) && 24710a4fa49Srie ((gptr == 0) || (strcmp(gptr, lptr) != 0))) { 24810a4fa49Srie /* 24910a4fa49Srie * If we've obtained a message locale (typically 25010a4fa49Srie * supplied via libc's setlocale()), then 25110a4fa49Srie * register the locale for use in dgettext() so 25210a4fa49Srie * as to reestablish the locale for ld.so.1's 25310a4fa49Srie * messages. 25410a4fa49Srie */ 25510a4fa49Srie if (gptr) { 25610a4fa49Srie free((void *)gptr); 25710a4fa49Srie rtld_flags |= RT_FL_NEWLOCALE; 25810a4fa49Srie } 25910a4fa49Srie glcs[tag].lc_un.lc_ptr = strdup(lptr); 26010a4fa49Srie 26110a4fa49Srie /* 26210a4fa49Srie * Clear any cached messages. 26310a4fa49Srie */ 26410a4fa49Srie err_strs[ERR_NONE] = 0; 26510a4fa49Srie err_strs[ERR_WARNING] = 0; 26610a4fa49Srie err_strs[ERR_FATAL] = 0; 26710a4fa49Srie err_strs[ERR_ELF] = 0; 26810a4fa49Srie 26910a4fa49Srie nosym_str = 0; 27010a4fa49Srie } 27110a4fa49Srie break; 27210a4fa49Srie 27310a4fa49Srie case CI_BIND_GUARD: 27410a4fa49Srie case CI_BIND_CLEAR: 27510a4fa49Srie case CI_THR_SELF: 27610a4fa49Srie /* 27710a4fa49Srie * If the global vector is unset, or this is the primary 27810a4fa49Srie * link-map, set the global vector. 27910a4fa49Srie */ 28010a4fa49Srie if ((gptr == 0) || (lml->lm_flags & LML_FLG_BASELM)) 28110a4fa49Srie glcs[tag].lc_un.lc_ptr = lptr; 28210a4fa49Srie 28310a4fa49Srie /* FALLTHROUGH */ 28410a4fa49Srie 28510a4fa49Srie case CI_TLS_MODADD: 28610a4fa49Srie case CI_TLS_MODREM: 28710a4fa49Srie case CI_TLS_STATMOD: 28810a4fa49Srie case CI_THRINIT: 28910a4fa49Srie threaded++; 29010a4fa49Srie break; 29110a4fa49Srie 29210a4fa49Srie case CI_VERSION: 29310a4fa49Srie if ((rtld_flags2 & RT_FL2_RTLDSEEN) == 0) { 29410a4fa49Srie rtld_flags2 |= RT_FL2_RTLDSEEN; 29510a4fa49Srie 29610a4fa49Srie if (funcs->ci_un.ci_val >= CI_V_FOUR) { 29710a4fa49Srie Listnode *lnp; 29810a4fa49Srie Lm_list *lml2; 29910a4fa49Srie 30010a4fa49Srie rtld_flags2 |= RT_FL2_UNIFPROC; 30110a4fa49Srie 30210a4fa49Srie /* 30310a4fa49Srie * We might have seen auditor which is 30410a4fa49Srie * not dependent on libc. Such an 30510a4fa49Srie * auditor's link map list has 30610a4fa49Srie * LML_FLG_HOLDLOCK set. This lock 30710a4fa49Srie * needs to be dropped. Refer to 30810a4fa49Srie * audit_setup() in audit.c. 30910a4fa49Srie */ 31010a4fa49Srie if ((rtld_flags2 & RT_FL2_HASAUDIT) == 31110a4fa49Srie 0) 31210a4fa49Srie break; 31310a4fa49Srie 31410a4fa49Srie /* 31510a4fa49Srie * Yes, we did. Take care of them. 31610a4fa49Srie */ 31710a4fa49Srie for (LIST_TRAVERSE(&dynlm_list, lnp, 31810a4fa49Srie lml2)) { 31910a4fa49Srie Rt_map *map = 32010a4fa49Srie (Rt_map *)lml2->lm_head; 32110a4fa49Srie 32210a4fa49Srie if (FLAGS(map) & FLG_RT_AUDIT) { 32310a4fa49Srie lml2->lm_flags &= 32410a4fa49Srie ~LML_FLG_HOLDLOCK; 32510a4fa49Srie } 32610a4fa49Srie } 32710a4fa49Srie } 32810a4fa49Srie } 32910a4fa49Srie break; 33010a4fa49Srie 33110a4fa49Srie default: 33210a4fa49Srie break; 33310a4fa49Srie } 33410a4fa49Srie } 33510a4fa49Srie 33610a4fa49Srie if (threaded == 0) 33710a4fa49Srie return; 33810a4fa49Srie 33910a4fa49Srie /* 34010a4fa49Srie * If a version of libc gives us only a subset of the TLS interfaces - 34110a4fa49Srie * it's confused and we discard the whole lot. 34210a4fa49Srie */ 34310a4fa49Srie if ((lcp[CI_TLS_MODADD].lc_un.lc_func && 34410a4fa49Srie lcp[CI_TLS_MODREM].lc_un.lc_func && 34510a4fa49Srie lcp[CI_TLS_STATMOD].lc_un.lc_func) == 0) { 34610a4fa49Srie lcp[CI_TLS_MODADD].lc_un.lc_func = 0; 34710a4fa49Srie lcp[CI_TLS_MODREM].lc_un.lc_func = 0; 34810a4fa49Srie lcp[CI_TLS_STATMOD].lc_un.lc_func = 0; 34910a4fa49Srie } 35010a4fa49Srie 35110a4fa49Srie /* 35210a4fa49Srie * Indicate that we're now thread capable, and enable concurrency if 35310a4fa49Srie * requested. 35410a4fa49Srie */ 35510a4fa49Srie if ((rtld_flags & RT_FL_NOCONCUR) == 0) 35610a4fa49Srie rtld_flags |= RT_FL_CONCUR; 35710a4fa49Srie if ((lml->lm_flags & LML_FLG_RTLDLM) == 0) 35810a4fa49Srie rtld_flags |= RT_FL_THREADS; 35910a4fa49Srie } 36010a4fa49Srie 36110a4fa49Srie /* 36210a4fa49Srie * At this point we know we have a set of objects that have been fully analyzed 36310a4fa49Srie * and relocated. Prior to the next major step of running .init sections (ie. 36410a4fa49Srie * running user code), retrieve any RTLDINFO interfaces. 36510a4fa49Srie */ 36610a4fa49Srie int 36710a4fa49Srie rt_get_extern(Lm_list *lml, Rt_map *lmp) 36810a4fa49Srie { 36910a4fa49Srie if (lml->lm_rti) { 370*cce0e03bSab Aliste idx; 37110a4fa49Srie Rti_desc *rti; 37210a4fa49Srie 373*cce0e03bSab for (ALIST_TRAVERSE(lml->lm_rti, idx, rti)) 37410a4fa49Srie get_lcinterface(rti->rti_lmp, rti->rti_info); 37510a4fa49Srie 37610a4fa49Srie free(lml->lm_rti); 37710a4fa49Srie lml->lm_rti = 0; 37810a4fa49Srie } 37910a4fa49Srie 38010a4fa49Srie /* 38110a4fa49Srie * Perform some sanity checks. If we have TLS requirements we better 38210a4fa49Srie * have the associated external interfaces. 38310a4fa49Srie */ 38410a4fa49Srie if (lml->lm_tls && (lml->lm_lcs[CI_TLS_STATMOD].lc_un.lc_func == 0)) { 385d326b23bSrie eprintf(lml, ERR_FATAL, MSG_INTL(MSG_TLS_NOSUPPORT), 38610a4fa49Srie NAME(lmp)); 38710a4fa49Srie return (0); 38810a4fa49Srie } 38910a4fa49Srie return (1); 39010a4fa49Srie } 39110a4fa49Srie 39210a4fa49Srie static int bindmask = 0; 39310a4fa49Srie 39410a4fa49Srie int 39510a4fa49Srie rt_bind_guard(int bindflag) 39610a4fa49Srie { 39710a4fa49Srie int (*fptr)(int); 39810a4fa49Srie 39910a4fa49Srie if ((fptr = glcs[CI_BIND_GUARD].lc_un.lc_func) != NULL) { 40010a4fa49Srie return ((*fptr)(bindflag)); 40110a4fa49Srie } else { 40210a4fa49Srie if ((bindflag & bindmask) == 0) { 40310a4fa49Srie bindmask |= bindflag; 40410a4fa49Srie return (1); 40510a4fa49Srie } 40610a4fa49Srie return (0); 40710a4fa49Srie } 40810a4fa49Srie } 40910a4fa49Srie 41010a4fa49Srie int 41110a4fa49Srie rt_bind_clear(int bindflag) 41210a4fa49Srie { 41310a4fa49Srie int (*fptr)(int); 41410a4fa49Srie 41510a4fa49Srie if ((fptr = glcs[CI_BIND_CLEAR].lc_un.lc_func) != NULL) { 41610a4fa49Srie return ((*fptr)(bindflag)); 41710a4fa49Srie } else { 41810a4fa49Srie if (bindflag == 0) 41910a4fa49Srie return (bindmask); 42010a4fa49Srie else { 42110a4fa49Srie bindmask &= ~bindflag; 42210a4fa49Srie return (0); 42310a4fa49Srie } 42410a4fa49Srie } 42510a4fa49Srie } 42610a4fa49Srie 42710a4fa49Srie /* 42810a4fa49Srie * Make sure threads have been initialized. This interface is called once for 42910a4fa49Srie * each link-map list. 43010a4fa49Srie */ 43110a4fa49Srie void 43210a4fa49Srie rt_thr_init(Lm_list *lml) 43310a4fa49Srie { 43410a4fa49Srie void (*fptr)(void); 43510a4fa49Srie 43610a4fa49Srie if ((fptr = (void (*)())lml->lm_lcs[CI_THRINIT].lc_un.lc_func) != 0) { 43710a4fa49Srie lml->lm_lcs[CI_THRINIT].lc_un.lc_func = 0; 43810a4fa49Srie leave((Lm_list *)0); 43910a4fa49Srie (*fptr)(); 44010a4fa49Srie (void) enter(); 44110a4fa49Srie } 44210a4fa49Srie } 44310a4fa49Srie 44410a4fa49Srie thread_t 44510a4fa49Srie rt_thr_self() 44610a4fa49Srie { 44710a4fa49Srie thread_t (*fptr)(void); 44810a4fa49Srie 44910a4fa49Srie if ((fptr = (thread_t (*)())glcs[CI_THR_SELF].lc_un.lc_func) != NULL) 45010a4fa49Srie return ((*fptr)()); 45110a4fa49Srie 45210a4fa49Srie return (1); 45310a4fa49Srie } 45410a4fa49Srie 45510a4fa49Srie int 45610a4fa49Srie rt_mutex_lock(Rt_lock * mp) 45710a4fa49Srie { 45810a4fa49Srie return (_lwp_mutex_lock((lwp_mutex_t *)mp)); 45910a4fa49Srie } 46010a4fa49Srie 46110a4fa49Srie int 46210a4fa49Srie rt_mutex_unlock(Rt_lock * mp) 46310a4fa49Srie { 46410a4fa49Srie return (_lwp_mutex_unlock((lwp_mutex_t *)mp)); 46510a4fa49Srie } 46610a4fa49Srie 46710a4fa49Srie Rt_cond * 46810a4fa49Srie rt_cond_create() 46910a4fa49Srie { 47010a4fa49Srie return (calloc(1, sizeof (Rt_cond))); 47110a4fa49Srie } 47210a4fa49Srie 47310a4fa49Srie int 47410a4fa49Srie rt_cond_wait(Rt_cond * cvp, Rt_lock * mp) 47510a4fa49Srie { 47610a4fa49Srie return (_lwp_cond_wait(cvp, (lwp_mutex_t *)mp)); 47710a4fa49Srie } 47810a4fa49Srie 47910a4fa49Srie int 48010a4fa49Srie rt_cond_broadcast(Rt_cond * cvp) 48110a4fa49Srie { 48210a4fa49Srie return (_lwp_cond_broadcast(cvp)); 48310a4fa49Srie } 48410a4fa49Srie 48510a4fa49Srie #ifdef EXPAND_RELATIVE 48610a4fa49Srie 48710a4fa49Srie /* 48810a4fa49Srie * Mutex interfaces to resolve references from any objects extracted from 48910a4fa49Srie * libc_pic.a. Note, as ld.so.1 is essentially single threaded these can be 49010a4fa49Srie * noops. 49110a4fa49Srie */ 49210a4fa49Srie #pragma weak lmutex_lock = __mutex_lock 49310a4fa49Srie #pragma weak _private_mutex_lock = __mutex_lock 49410a4fa49Srie #pragma weak mutex_lock = __mutex_lock 49510a4fa49Srie #pragma weak _mutex_lock = __mutex_lock 49610a4fa49Srie /* ARGSUSED */ 49710a4fa49Srie int 49810a4fa49Srie __mutex_lock(mutex_t *mp) 49910a4fa49Srie { 50010a4fa49Srie return (0); 50110a4fa49Srie } 50210a4fa49Srie 50310a4fa49Srie #pragma weak lmutex_unlock = __mutex_unlock 50410a4fa49Srie #pragma weak _private_mutex_unlock = __mutex_unlock 50510a4fa49Srie #pragma weak mutex_unlock = __mutex_unlock 50610a4fa49Srie #pragma weak _mutex_unlock = __mutex_unlock 50710a4fa49Srie /* ARGSUSED */ 50810a4fa49Srie int 50910a4fa49Srie __mutex_unlock(mutex_t *mp) 51010a4fa49Srie { 51110a4fa49Srie return (0); 51210a4fa49Srie } 51310a4fa49Srie 514494a4c51Sraf #pragma weak _private_mutex_init = __mutex_init 515494a4c51Sraf #pragma weak mutex_init = __mutex_init 516494a4c51Sraf #pragma weak _mutex_init = __mutex_init 517494a4c51Sraf /* ARGSUSED */ 518494a4c51Sraf int 519494a4c51Sraf __mutex_init(mutex_t *mp, int type, void *arg) 520494a4c51Sraf { 521494a4c51Sraf return (0); 522494a4c51Sraf } 523494a4c51Sraf 524494a4c51Sraf #pragma weak _private_mutex_destroy = __mutex_destroy 525494a4c51Sraf #pragma weak mutex_destroy = __mutex_destroy 526494a4c51Sraf #pragma weak _mutex_destroy = __mutex_destroy 527494a4c51Sraf /* ARGSUSED */ 528494a4c51Sraf int 529494a4c51Sraf __mutex_destroy(mutex_t *mp) 530494a4c51Sraf { 531494a4c51Sraf return (0); 532494a4c51Sraf } 533494a4c51Sraf 53410a4fa49Srie /* 53510a4fa49Srie * This is needed to satisfy sysconf() (case _SC_THREAD_STACK_MIN) 53610a4fa49Srie */ 53710a4fa49Srie #pragma weak thr_min_stack = _thr_min_stack 53810a4fa49Srie size_t 53910a4fa49Srie _thr_min_stack() 54010a4fa49Srie { 54110a4fa49Srie #ifdef _LP64 54210a4fa49Srie return (8 * 1024); 54310a4fa49Srie #else 54410a4fa49Srie return (4 * 1024); 54510a4fa49Srie #endif 54610a4fa49Srie } 54710a4fa49Srie 548a574db85Sraf /* 549a574db85Sraf * The following functions are cancellation points in libc. 550a574db85Sraf * They are called from other functions in libc that we extract 551a574db85Sraf * and use directly. We don't do cancellation while we are in 552a574db85Sraf * the dynamic linker, so we redefine these to call the primitive, 553a574db85Sraf * non-cancellation interfaces. 554a574db85Sraf */ 555a574db85Sraf 556a574db85Sraf #pragma weak close = _close 557a574db85Sraf int 558a574db85Sraf _close(int fildes) 559a574db85Sraf { 560a574db85Sraf extern int __close(int); 561a574db85Sraf 562a574db85Sraf return (__close(fildes)); 563a574db85Sraf } 564a574db85Sraf 565a574db85Sraf #pragma weak fcntl = _fcntl 566a574db85Sraf int 567a574db85Sraf _fcntl(int fildes, int cmd, ...) 568a574db85Sraf { 569a574db85Sraf extern int __fcntl(int, int, ...); 570a574db85Sraf intptr_t arg; 571a574db85Sraf va_list ap; 572a574db85Sraf 573a574db85Sraf va_start(ap, cmd); 574a574db85Sraf arg = va_arg(ap, intptr_t); 575a574db85Sraf va_end(ap); 576a574db85Sraf return (__fcntl(fildes, cmd, arg)); 577a574db85Sraf } 578a574db85Sraf 579a574db85Sraf #pragma weak open = _open 580a574db85Sraf int 581a574db85Sraf _open(const char *path, int oflag, ...) 582a574db85Sraf { 583a574db85Sraf extern int __open(const char *, int, ...); 584a574db85Sraf mode_t mode; 585a574db85Sraf va_list ap; 586a574db85Sraf 587a574db85Sraf va_start(ap, oflag); 588a574db85Sraf mode = va_arg(ap, mode_t); 589a574db85Sraf va_end(ap); 590a574db85Sraf return (__open(path, oflag, mode)); 591a574db85Sraf } 592a574db85Sraf 593a574db85Sraf #pragma weak openat = _openat 594a574db85Sraf int 595a574db85Sraf _openat(int fd, const char *path, int oflag, ...) 596a574db85Sraf { 597a574db85Sraf extern int __openat(int, const char *, int, ...); 598a574db85Sraf mode_t mode; 599a574db85Sraf va_list ap; 600a574db85Sraf 601a574db85Sraf va_start(ap, oflag); 602a574db85Sraf mode = va_arg(ap, mode_t); 603a574db85Sraf va_end(ap); 604a574db85Sraf return (__openat(fd, path, oflag, mode)); 605a574db85Sraf } 606a574db85Sraf 607a574db85Sraf #pragma weak read = _read 608a574db85Sraf ssize_t 609a574db85Sraf _read(int fd, void *buf, size_t size) 610a574db85Sraf { 611a574db85Sraf extern ssize_t __read(int, void *, size_t); 612a574db85Sraf return (__read(fd, buf, size)); 613a574db85Sraf } 614a574db85Sraf 615a574db85Sraf #pragma weak write = _write 616a574db85Sraf ssize_t 617a574db85Sraf _write(int fd, const void *buf, size_t size) 618a574db85Sraf { 619a574db85Sraf extern ssize_t __write(int, const void *, size_t); 620a574db85Sraf return (__write(fd, buf, size)); 621a574db85Sraf } 622a574db85Sraf 62310a4fa49Srie #endif /* EXPAND_RELATIVE */ 624