tls.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "lint.h"
#include "thr_uberdata.h"
#define MIN_MOD_SLOTS 16
/*
* To inform libc_init that we are on the primary link map.
*/
int primary_link_map;
#if defined(_LP64)
#define ALIGN 16
#else
#define ALIGN 8
#endif
/*
* Grow the TLS module information array as necessary to include the
* specified module-id. tls_modinfo->tls_size must be a power of two.
* Return a pointer to the (possibly reallocated) module information array.
*/
static TLS_modinfo *
{
mod_slots *= 2;
}
}
return (modinfo);
}
/*
* This is called from the dynamic linker, before libc_init() is called,
* to setup all of the TLS blocks that are available at process startup
* and hence must be included as part of the static TLS block.
* No locks are needed because we are single-threaded at this point.
* We must be careful not to call any function that could possibly
* invoke the dynamic linker. That is, we must only call functions
* that are wholly private to libc.
*/
void
{
TLS_modinfo **tlspp;
int max_modid;
if (statictlssize == 0)
return;
/*
* Retrieve whatever dynamic TLS metadata was generated by code
* running on alternate link maps prior to now (we must be running
* on the primary link map now since __tls_static_mods() is only
* called on the primary link map).
*/
}
/*
* We call lmalloc() to allocate the template even though libc_init()
* has not yet been called. lmalloc() must and does deal with this.
*/
/*
* Initialize the static TLS template.
* We make no assumptions about the order in memory of the TLS
* modules we are processing, only that they fit within the
* total size we are given and that they are self-consistent.
* We do not assume any order for the moduleid's; we only assume
* that they are reasonably small integers.
*/
}
/*
* Record the static TLS_modinfo information.
*/
/*
* Copy the new tls_metadata back to the old, if any,
* since it will be copied up again in libc_init().
*/
}
/*
* This is called from the dynamic linker for each module not included
* in the static TLS mod list, after the module has been loaded but
* before any of the module's init code has been executed.
*/
void
{
}
/*
* Called for each module as it is unloaded from memory by dlclose().
*/
void
{
}
extern int _preexec_exit_handlers();
extern void libc_init();
const Lc_interface tls_rtldinfo[] = {
{CI_VERSION, (int(*)())CI_V_CURRENT},
{CI_ATEXIT, (int(*)())_preexec_exit_handlers},
{CI_TLS_MODADD, (int(*)())__tls_mod_add},
{CI_TLS_MODREM, (int(*)())__tls_mod_remove},
{CI_TLS_STATMOD, (int(*)())__tls_static_mods},
{CI_THRINIT, (int(*)())libc_init},
};
/*
* Return the address of a TLS variable for the current thread.
* Run the constructors for newly-allocated dynamic TLS.
*/
void *
{
void (**initarray)(void);
/*
* Defer signals until we have finished calling
* all of the constructors.
*/
else {
}
}
/* static TLS is already allocated/initialized */
} else {
/* allocate/initialize the dynamic TLS */
/* remember the constructors */
}
}
/*
* Call constructors, if any, in ascending order.
* We have to do this after dropping tls_lock because
* we have no idea what the constructors will do.
* At least we have signals deferred until they are done.
*/
if (arraycnt) {
do {
(**initarray++)();
} while (--arraycnt != 0);
}
}
/*
* For speed, we do not make reference to any static data in this function.
* If necessary to do so, we do a tail call to slow_tls_get_addr().
*/
void *
{
return (slow_tls_get_addr(tls_index));
}
#endif /* TLS_GET_ADDR_IS_WRITTEN_IN_ASSEMBLER */
/*
* This is called by _thr_setup() to initialize the thread's static TLS.
* Constructors for initially allocated static TLS are called here.
*/
void
{
long moduleid;
return;
/* static TLS initialization */
/* call TLS constructors for the static TLS just initialized */
/*
* Resume where we left off in the module array.
* tls_modinfo.tls_data may have changed since we
* dropped and reacquired tls_lock, but TLS modules
* retain their positions in the new array.
*/
/*
* Call constructors for this module if there are any
* to be called and if it is part of the static TLS.
*/
if (tlsp->tm_tlsinitarraycnt != 0 &&
/*
* Call the constructors in ascending order.
* We must drop tls_lock while doing this because
* we have no idea what the constructors will do.
*/
do {
(**initarray++)();
} while (--arraycnt != 0);
}
}
}
/*
* This is called by _thrp_exit() to deallocate the thread's TLS.
* Destructors for all allocated TLS are called here.
*/
void
tls_exit()
{
long moduleid;
return; /* no TLS */
/*
* Call TLS destructors for all TLS allocated for this thread.
*/
/*
* Resume where we left off in the module array.
* tls_modinfo.tls_data may have changed since we
* dropped and reacquired tls_lock, but TLS modules
* retain their positions in the new array.
*/
/*
* Call destructors for this module if there are any
* to be called and if it is part of the static TLS or
* if the dynamic TLS for the module has been allocated.
*/
if (tlsp->tm_tlsfiniarraycnt != 0 &&
/*
* Call the destructors in descending order.
* We must drop tls_lock while doing this because
* we have no idea what the destructors will do.
*/
do {
(**--finiarray)();
} while (--arraycnt != 0);
}
}
}
/*
* We only free the dynamically allocated TLS; the statically
* allocated TLS is reused when the ulwp_t is reallocated.
*/
void
{
void *base;
return;
}
ulwp->ul_ntlsent = 0;
}