util.c revision efb9e8b87f7179cbe8dcdd56f4584d5bcdf7fbd2
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 (c) 1988 AT&T
* All Rights Reserved
*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Utility routines for run-time linker. some are duplicated here from libc
* (with different names) to avoid name space collisions.
*/
#include "_synonyms.h"
#include <stdio.h>
#include <stdarg.h>
#include <fcntl.h>
#include <string.h>
#include <ctype.h>
#include <dlfcn.h>
#include <unistd.h>
#include <stdlib.h>
#include <debug.h>
#include <conv.h>
#include "_rtld.h"
#include "_audit.h"
#include "_elf.h"
#include "msg.h"
/*
* All error messages go through eprintf(). During process initialization these
* messages should be directed to the standard error, however once control has
* been passed to the applications code these messages should be stored in an
* internal buffer for use with dlerror(). Note, fatal error conditions that
* may occur while running the application will still cause a standard error
* message, see rtldexit() in this file for details.
* The `application' flag serves to indicate the transition between process
* initialization and when the applications code is running.
*/
/*
* Null function used as place where a debugger can set a breakpoint.
*/
void
{
}
/*
* Null function used as place where debugger can set a pre .init
* processing breakpoint.
*/
void
{
}
/*
* Null function used as place where debugger can set a post .init
* processing breakpoint.
*/
void
{
}
/*
* Debugger Event Notification
*
* This function centralizes all debugger event notification (ala rtld_db).
*
* There's a simple intent, focused on insuring the primary link-map control
* list (or each link-map list) is consistent, and the indication that objects
* have been added or deleted from this list. Although an RD_ADD and RD_DELETE
* event are posted for each of these, most debuggers don't care, as their
* view is that these events simply convey an "inconsistent" state.
*
* enter ld.so.1.
*
* With auditors, we may be in the process of relocating a collection of
* objects, and will leave() ld.so.1 to call the auditor. At this point we
* must indicate an RD_CONSISTENT event, but librtld_db will not report an
* object to the debuggers until relocation processing has been completed on it.
* To allow for the collection of these objects that are pending relocation, an
* RD_ADD event is set after completing a series of relocations on the primary
* link-map control list.
*
* required later (LML_FLG_DBNOTIF):
*
* i the first time we add or delete an object to the primary link-map
* control list.
* ii the first time we move a secondary link-map control list to the primary
* link-map control list (effectively, this is like adding a group of
* objects to the primary link-map control list).
*
* Set an RD_CONSISTENT event when it is required (LML_FLG_DBNOTIF is set) and
*
* i each time we leave the runtime linker.
*/
void
{
switch (event) {
case RD_PREINIT:
break;
case RD_POSTINIT:
break;
case RD_DLACTIVITY:
switch (state) {
case RT_CONSISTENT:
/*
* Do we need to send a notification?
*/
if ((rtld_flags & RT_FL_DBNOTIF) == 0)
return;
rtld_flags &= ~RT_FL_DBNOTIF;
break;
case RT_ADD:
case RT_DELETE:
/*
* If we are already in an inconsistent state, no
* notification is required.
*/
if (rtld_flags & RT_FL_DBNOTIF)
return;
break;
};
break;
default:
/*
* RD_NONE - do nothing
*/
break;
};
/*
* Set event state and call 'notification' function.
*
* The debugging clients have previously been told about these
* notification functions and have set breakpoints on them if they
* are interested in the notification.
*/
}
/*
* Stack Cleanup.
*
* This function is invoked to 'remove' arguments that were passed in on the
* stack. This is most likely if ld.so.1 was invoked directly. In that case
* we want to remove ld.so.1 as well as it's arguments from the argv[] array.
* Which means we then need to slide everything above it on the stack down
* accordingly.
*
* While the stack layout is platform specific - it just so happens that __x86,
* and __sparc platforms share the following initial stack layout.
*
* !_______________________! high addresses
* ! !
* ! Information !
* ! Block !
* ! (size varies) !
* !_______________________!
* ! 0 word !
* !_______________________!
* ! Auxiliary !
* ! vector !
* ! 2 word entries !
* ! !
* !_______________________!
* ! 0 word !
* !_______________________!
* ! Environment !
* ! pointers !
* ! ... !
* ! (one word each) !
* !_______________________!
* ! 0 word !
* !_______________________!
* ! Argument ! low addresses
* ! pointers !
* ! Argc words !
* !_______________________!
* ! !
* ! Argc !
* !_______________________!
* ! ... !
*
*/
static void
{
int ndx;
long *argc;
/*
* Slide ARGV[] and update argc. The argv pointer remains the same,
* however slide the applications arguments over the arguments to
* ld.so.1.
*/
/*
* Slide ENVP[], and update the environment array pointer.
*/
ndx++;
/*
* Slide AUXV[], and update the aux vector pointer.
*/
ndx++;
}
#else
/*
* Verify that the above routine is appropriate for any new platforms.
*/
#endif
/*
* The only command line argument recognized is -e, followed by a runtime
* linker environment variable.
*/
int
{
int ndx;
char *str;
break;
ndx++;
break;
}
return (1);
ndx++;
return (1);
} else
/*
* If the environment variable starts with LD_, strip the LD_.
* Otherwise, take things as is.
*/
str += 3;
return (1);
}
/*
* Make sure an object file has been specified.
*/
return (1);
/*
* Having gotten the arguments, clean ourselves off of the stack.
*/
return (0);
}
/*
* Compare function for FullpathNode AVL tree.
*/
static int
{
int rc;
return (1);
return (-1);
if (rc > 0)
return (1);
if (rc < 0)
return (-1);
return (0);
}
/*
* Determine if a given pathname has already been loaded in the AVL tree.
* If the pathname does not exist in the AVL tree, the next insertion point
* is deposited in "where". This value can be used by fpavl_insert() to
* expedite the insertion.
*/
Rt_map *
{
/*
* Create the avl tree if required.
*/
return (0);
}
return (NULL);
}
/*
* Insert a name into the FullpathNode AVL tree for the link-map list. The
* objects NAME() is the path that would have originally been searched for, and
* is therefore the name to associate with any "where" value. If the object has
* a different PATHNAME(), perhaps because it has resolved to a different file
* (see fullpath), then this name is recorded also. See load_file().
*/
int
{
if (where == 0) {
/* LINTED */
/*
* We better not get a hit now, we do not want duplicates in
* the tree.
*/
}
/*
* Insert new node in tree
*/
return (0);
AL_CNT_FPNODE) == 0) {
return (0);
}
return (1);
}
/*
* Remove an object from the Fullpath AVL tree. Note, this is called *before*
* the objects link-map is torn down (remove_so), which is where any NAME() and
* PATHNAME() strings will be deallocated.
*/
void
{
}
}
/*
* Prior to calling an object, either via a .plt or through dlsym(), make sure
* its .init has fired. Through topological sorting, ld.so.1 attempts to fire
* init's in the correct order, however, this order is typically based on needed
* dependencies and non-lazy relocation bindings. Lazy relocations (.plts) can
* still occur and result in bindings that were not captured during topological
* sorting. This routine compensates for this lack of binding information, and
* provides for dynamic .init firing.
*/
void
{
/*
* If the caller is an auditor, and the destination isn't, then don't
* run any .inits (see comments in load_completion()).
*/
return;
return;
return;
(FLG_RT_RELOCED | FLG_RT_INITCALL)) {
return;
}
}
}
/*
* In a threaded environment insure the thread responsible for loading an object
* has completed .init processing for that object before any new thread is
* allowed to access the object. This check is only valid with libthread
* TI_VERSION 2, where ld.so.1 implements locking through low level mutexes.
*
* When a new link-map is created, the thread that causes it to be loaded is
* identified by THREADID(dlmp). Compare this with the current thread to
* determine if it must be blocked.
*
* NOTE, there are a number of instances (typically only for .plt processing)
* where we must skip this test:
*
* . any thread id of 0 - threads that call thr_exit() may be in this state
* thus we can't deduce what tid they used to be. Also some of the
* or libc) for libthread to function.
*
* . libthread itself binds to libc, and as libthread is INITFIRST
* libc's .init can't have fired yet. Luckly libc's .init is not required
* by libthreads binding.
*
* . if the caller is an auditor, and the destination isn't, then don't
* block (see comments in load_completion()).
*/
void
{
return;
if ((rtld_flags & RT_FL_CONCUR) &&
}
}
}
/*
* Execute .{preinit|init|fini}array sections
*/
void
{
return;
/*
* initarray & preinitarray are walked from beginning to end - while
* finiarray is walked from end to beginning.
*/
if (shtype == SHT_FINI_ARRAY) {
} else {
start = 0;
incr = 1;
}
/*
* Call the .*array[] entries
*/
(*fptr)();
(void) enter();
}
}
/*
* Execute any .init sections. These are passed to us in an lmp array which
* (by default) will have been sorted.
*/
void
{
/*
* If we're in the middle of an INITFIRST, this must complete before
* any new init's are fired. In this case add the object list to the
* pending queue and return. We'll pick up the queue after any
* INITFIRST objects have their init's fired.
*/
if (rtld_flags & RT_FL_INITFIRST) {
return;
}
/*
* Traverse the tobj array firing each objects init.
*/
continue;
/*
* Establish an initfirst state if necessary - no other inits
* will be fired (because of additional relocation bindings)
* when in this state.
*/
/*
* Make sure that all dependencies that have been
* relocated to are initialized before this objects
* .init is executed. This insures that a dependency
* on an external item that must first be initialized
* by its associated object is satisfied.
*/
continue;
}
}
if (iptr) {
(*iptr)();
(void) enter();
}
/*
* Set the initdone flag regardless of whether this object
* actually contains an .init section. This flag prevents us
* from processing this section again for an .init and also
* signifies that a .fini must be called should it exist.
* Clear the sort field for use in later .fini processing.
*/
/*
* Wake anyone up who might be waiting on this .init.
*/
}
/*
* If we're firing an INITFIRST object, and other objects must
* be fired which are not INITFIRST, make sure we grab any
* pending objects that might have been delayed as this
* INITFIRST was processed.
*/
if ((rtld_flags & RT_FL_INITFIRST) &&
}
}
}
}
/*
* Function called by atexit(3C). Calls all .fini sections related with the
* mains dependent shared libraries in the order in which the shared libraries
* have been loaded. Skip any .fini defined in the main executable, as this
* will be called by crt0 (main was never marked as initdone).
*/
void
{
/*
* If concurrency checking isn't enabled only fire .fini if
* .init has completed. We collect all .fini sections of
* objects that had their .init collected, but that doesn't
* mean at the time that the .init had completed.
*/
if ((rtld_flags & RT_FL_CONCUR) ||
/*
* If concurrency checking is enabled make sure
* this object's .init is completed before
* calling any .fini.
*/
}
if (fptr) {
(*fptr)();
(void) enter();
}
}
/*
* Skip main, this is explicitly called last in atexit_fini().
*/
continue;
/*
* Audit `close' operations at this point. The library has
* exercised its last instructions (regardless of whether it
* will be unmapped or not).
*
* First call any global auditing.
*/
/*
* Finally determine whether this object has local auditing
* requirements by inspecting itself and then its dependencies.
*/
continue;
lmp);
break;
}
}
}
}
void
{
(void) enter();
/*
* Display any objects that haven't been referenced so far.
*/
/*
* Reverse topologically sort the main link-map for .fini execution.
*/
/*
* Add an explicit close to main and ld.so.1. Although main's .fini is
* collected in call_fini() to provide for FINITARRAY processing, its
* audit_objclose is explicitly skipped. This provides for it to be
* called last, here. This is the reverse of the explicit calls to
* audit_objopen() made in setup().
*/
}
/*
* Now that all .fini code has been run, see what unreferenced objects
* remain. Any difference between this and the above unused() would
* indicate an object is only being used for .fini processing, which
* might be fine, but might also indicate an overhead whose removal
* would be worth considering.
*/
/*
* Traverse any alternative link-map lists.
*/
/*
* Ignore the base-link-map list, which has already been
* processed, and the runtime linkers link-map list, which is
* typically processed last.
*/
continue;
continue;
/*
* Reverse topologically sort the link-map for .fini execution.
*/
}
/*
* Finally reverse topologically sort the runtime linkers link-map for
* .fini execution.
*/
}
/*
* This routine is called to complete any runtime linker activity which may have
* resulted in objects being loaded. This is called from all user entry points
* and from any internal dl*() requests.
*/
void
{
/*
* Establish any .init processing. Note, in a world of lazy loading,
* objects may have been loaded regardless of whether the users request
* was fulfilled (i.e., a dlsym() request may have failed to find a
* symbol but objects might have been loaded during its search). Thus,
* any tsorting starts from the nlmp (new link-maps) pointer and not
* necessarily from the link-map that may have satisfied the request.
*
* Note, the primary link-map has an initialization phase where dynamic
* .init firing is suppressed. This provides for a simple and clean
* handshake with the primary link-maps libc, which is important for
* establishing uberdata. In addition, auditors often obtain handles
* to primary link-map objects as the objects are loaded, so as to
* inspect the link-map for symbols. This inspection is allowed without
* running any code on the primary link-map, as running this code may
* reenter the auditor, who may not yet have finished its own
* initialization.
*/
if (nlmp)
tobj = 0;
}
/*
* Make sure any alternative link-map retrieves any external interfaces
* and initializes threads.
*/
}
/*
* Traverse the list of new link-maps and register any dynamic TLS.
* This storage is established for any objects not on the primary
* link-map, and for any objects added to the primary link-map after
* static TLS has been registered.
*/
}
}
/*
* Fire any .init's.
*/
if (tobj)
}
/*
* Append an item to the specified list, and return a pointer to the list
* node created.
*/
Listnode *
{
return (0);
else {
}
return (_lnp);
}
/*
* Add an item after specified listnode, and return a pointer to the list
* node created.
*/
Listnode *
{
return (0);
return (_lnp);
}
/*
* Prepend an item to the specified list, and return a pointer to the
* list node created.
*/
Listnode *
{
return (0);
} else {
}
return (_lnp);
}
/*
* Delete a 'listnode' from a list.
*/
void
{
break;
}
if (clnp == 0)
return;
if (plnp)
}
/*
* Append an item to the specified link map control list.
*/
void
{
int add = 1;
/*
* Indicate that this link-map list has a new object.
*/
/*
* If we're about to add a new object to the main link-map control list,
* alert the debuggers that we are about to mess with this list.
* Additions of individual objects to the main link-map control list
* occur during initial setup as the applications immediate dependencies
* are loaded. Individual objects are also loaded on the main link-map
* control list of new alternative link-map control lists.
*/
/* LINTED */
/*
* A link-map list header points to one of more link-map control lists
* the list of relocated objects. Other lists maintain objects that
* are still being analyzed or relocated. This list provides the core
* link-map list information used by all ld.so.1 routines.
*/
/*
* If this is the first link-map for the given control list,
* initialize the list.
*/
add = 0;
/*
* If this is an interposer then append the link-map following
* any other interposers (these are objects that have been
* previously preloaded, or were identified with -z interpose).
* Interposers can only be inserted on the first link-map
* control list, as once relocation has started, interposition
* from new interposers can't be guaranteed.
*
* NOTE: We do not interpose on the head of a list. This model
* evolved because dynamic executables have already been fully
* relocated within themselves and thus can't be interposed on.
* Nowadays it's possible to have shared objects at the head of
* a list, which conceptually means they could be interposed on.
* But, shared objects can be created via dldump() and may only
* be partially relocated (just relatives), in which case they
* are interposable, but are marked as fixed (ET_EXEC).
*
* Thus we really don't have a clear method of deciding when the
* head of a link-map is interposable. So, to be consistent,
* for now only add interposers after the link-map lists head
* object.
*/
continue;
/*
* Insert the new link-map before this non-interposer,
* and indicate an interposer is found.
*/
add = 0;
break;
}
}
/*
* Fall through to appending the new link map to the tail of the list.
* If we're processing the initial objects of this link-map list, add
* them to the backward compatibility list.
*/
if (add) {
}
/*
* Having added this link-map to a control list, indicate which control
* list the link-map belongs to. Note, control list information is
* always maintained as an offset, as the Alist can be reallocated.
*/
/*
* Indicate if an interposer is found. Note that the first object on a
* link-map can be explicitly defined as an interposer so that it can
* provide interposition over direct binding requests.
*/
/*
* For backward compatibility with debuggers, the link-map list contains
* pointers to the main control list.
*/
}
}
/*
* Delete an item from the specified link map control list.
*/
void
{
/*
* If the control list pointer hasn't been initialized, this object
* never got added to a link-map list.
*/
return;
/*
* If we're about to delete an object from the main link-map control
* list, alert the debuggers that we are about to mess with this list.
*/
/* LINTED */
else
else
/*
* For backward compatibility with debuggers, the link-map list contains
* pointers to the main control list.
*/
}
/*
* Indicate we have one less object on this control list.
*/
}
/*
* Move a link-map control list to another. Objects that are being relocated
* are maintained on secondary control lists. Once their relocation is
* complete, the entire list is appended to the previous control list, as this
* list must have been the trigger for generating the new control list.
*/
void
{
/*
* If we're about to add a new family of objects to the main link-map
* control list, alert the debuggers that we are about to mess with this
* list. Additions of object families to the main link-map control
* list occur during lazy loading, filtering and dlopen().
*/
/*
* Indicate each new link-map has been moved to the previous link-map
* control list.
*/
/*
* Move the new link-map control list, to the callers link-map control
* list.
*/
} else {
}
/*
* For backward compatibility with debuggers, the link-map list contains
* pointers to the main control list.
*/
}
}
/*
* Environment variables can have a variety of defined permutations, and thus
* the following infrastructure exists to allow this variety and to select the
* required definition.
*
* Environment variables can be defined as 32- or 64-bit specific, and if so
* they will take precedence over any instruction set neutral form. Typically
* this is only useful when the environment value is an informational string.
*
* Environment variables may be obtained from the standard user environment or
* from a configuration file. The latter provides a fallback if no user
* environment setting is found, and can take two forms:
*
* . a replaceable definition - this will be used if no user environment
* setting has been seen, or
*
* . an permanent definition - this will be used no matter what user
* environment setting is seen. In the case of list variables it will be
* appended to any process environment setting seen.
*
* Environment variables can be defined without a value (ie. LD_XXXX=) so as to
* override any replaceable environment variables from a configuration file.
*/
/* variables */
/* variables */
/* variables */
/* variables */
/*
* Classify an environment variables type.
*/
/* the wrong ISA */
/* config file */
/*
* Identify all environment variables.
*/
#define ENV_FLG_AUDIT 0x0000000001ULL
#define ENV_FLG_AUDIT_ARGS 0x0000000002ULL
#define ENV_FLG_BIND_NOW 0x0000000004ULL
#define ENV_FLG_BIND_NOT 0x0000000008ULL
#define ENV_FLG_BINDINGS 0x0000000010ULL
#define ENV_FLG_CONCURRENCY 0x0000000020ULL
#define ENV_FLG_CONFGEN 0x0000000040ULL
#define ENV_FLG_CONFIG 0x0000000080ULL
#define ENV_FLG_DEBUG 0x0000000100ULL
#define ENV_FLG_DEBUG_OUTPUT 0x0000000200ULL
#define ENV_FLG_DEMANGLE 0x0000000400ULL
#define ENV_FLG_FLAGS 0x0000000800ULL
#define ENV_FLG_INIT 0x0000001000ULL
#define ENV_FLG_LIBPATH 0x0000002000ULL
#define ENV_FLG_LOADAVAIL 0x0000004000ULL
#define ENV_FLG_LOADFLTR 0x0000008000ULL
#define ENV_FLG_NOAUDIT 0x0000010000ULL
#define ENV_FLG_NOAUXFLTR 0x0000020000ULL
#define ENV_FLG_NOBAPLT 0x0000040000ULL
#define ENV_FLG_NOCONFIG 0x0000080000ULL
#define ENV_FLG_NODIRCONFIG 0x0000100000ULL
#define ENV_FLG_NODIRECT 0x0000200000ULL
#define ENV_FLG_NOENVCONFIG 0x0000400000ULL
#define ENV_FLG_NOLAZY 0x0000800000ULL
#define ENV_FLG_NOOBJALTER 0x0001000000ULL
#define ENV_FLG_NOVERSION 0x0002000000ULL
#define ENV_FLG_PRELOAD 0x0004000000ULL
#define ENV_FLG_PROFILE 0x0008000000ULL
#define ENV_FLG_PROFILE_OUTPUT 0x0010000000ULL
#define ENV_FLG_SIGNAL 0x0020000000ULL
#define ENV_FLG_TRACE_OBJS 0x0040000000ULL
#define ENV_FLG_TRACE_PTHS 0x0080000000ULL
#define ENV_FLG_UNREF 0x0100000000ULL
#define ENV_FLG_UNUSED 0x0200000000ULL
#define ENV_FLG_VERBOSE 0x0400000000ULL
#define ENV_FLG_WARN 0x0800000000ULL
#define ENV_FLG_NOFLTCONFIG 0x1000000000ULL
#define ENV_FLG_BIND_LAZY 0x2000000000ULL
#ifdef SIEBEL_DISABLE
#define ENV_FLG_FIX_1 0x8000000000ULL
#endif
#define SEL_REPLACE 0x0001
#define SEL_PERMANT 0x0002
/*
* Pattern match an LD_XXXX environment variable. s1 points to the XXXX part
* and len specifies its length (comparing a strings length before the string
* itself speed things up). s2 points to the token itself which has already
* had any leading white-space removed.
*/
static void
{
u_longlong_t variable = 0;
const char **str;
/*
* Determine whether we're dealing with a replaceable or permanent
* string.
*/
if (env_flags & ENV_TYP_PERMANT) {
/*
* If the string is from a configuration file and defined as
* permanent, assign it as permanent.
*/
select |= SEL_PERMANT;
} else
select |= SEL_REPLACE;
/*
* Parse the variable given.
*
* The LD_AUDIT family.
*/
if (*s1 == 'A') {
/*
* Replaceable and permanent audit objects can exist.
*/
select |= SEL_ACT_STR;
if (select & SEL_REPLACE)
else {
rpl_audit = 0;
}
} else if ((len == MSG_LD_AUDIT_ARGS_SIZE) &&
MSG_LD_AUDIT_ARGS_SIZE) == 0)) {
/*
* A specialized variable for plt_exit() use, not
* documented for general use.
*/
select |= SEL_ACT_SPEC_2;
}
}
/*
* The LD_BIND family and LD_BREADTH (historic).
*/
else if (*s1 == 'B') {
MSG_LD_BIND_LAZY_SIZE) == 0)) {
select |= SEL_ACT_RT2;
select |= SEL_ACT_RT2;
/*
* Another trick, enabled to help debug AOUT
* applications under BCP, but not documented for
* general use.
*/
select |= SEL_ACT_RT;
val = RT_FL_NOBIND;
/*
* This variable is simply for backward compatibility.
* If this and LD_DEBUG are both specified, only one of
* the strings is going to get processed.
*/
select |= SEL_ACT_SPEC_2;
#ifndef LD_BREADTH_DISABLED
/*
* Besides some old patches this is no longer available.
*/
return;
#endif
}
}
/*
* LD_CONCURRENCY and LD_CONFIG family.
*/
else if (*s1 == 'C') {
MSG_LD_CONCURRENCY_SIZE) == 0)) {
/*
* Waiting in the wings, as concurrency checking isn't
* yet enabled.
*/
select |= SEL_ACT_SPEC_2;
/*
* Set by crle(1) to indicate it's building a
* configuration file, not documented for general use.
*/
select |= SEL_ACT_SPEC_2;
/*
* Secure applications must use a default configuration
* file. A setting from a configuration file doesn't
* make sense (given we must be reading a configuration
* file to have gotten this).
*/
if ((rtld_flags & RT_FL_SECURE) ||
(env_flags & ENV_TYP_CONFIG))
return;
select |= SEL_ACT_STR;
}
}
/*
* The LD_DEBUG family and LD_DEMANGLE.
*/
else if (*s1 == 'D') {
select |= SEL_ACT_STR;
if (select & SEL_REPLACE)
else {
rpl_debug = 0;
}
MSG_LD_DEBUG_OUTPUT_SIZE) == 0)) {
select |= SEL_ACT_STR;
select |= SEL_ACT_RT;
}
}
/*
* LD_FLAGS - collect the best variable definition. On completion of
* environment variable processing pass the result to ld_flags_env()
* where they'll be decomposed and passed back to this routine.
*/
else if (*s1 == 'F') {
select |= SEL_ACT_SPEC_1;
if (select & SEL_REPLACE)
str = &rpl_ldflags;
else {
str = &prm_ldflags;
rpl_ldflags = 0;
}
}
}
/*
* LD_INIT (internal, used by ldd(1)).
*/
else if (*s1 == 'I') {
select |= SEL_ACT_LML;
}
}
/*
* The LD_LIBRARY_PATH and LD_LOAD families.
*/
else if (*s1 == 'L') {
select |= SEL_ACT_SPEC_1;
if (select & SEL_REPLACE)
str = &rpl_libpath;
else {
str = &prm_libpath;
rpl_libpath = 0;
}
/*
* Internal use by crle(1), not documented for general
* use.
*/
select |= SEL_ACT_LML;
select |= SEL_ACT_SPEC_2;
}
}
/*
* The LD_NO family.
*/
else if (*s1 == 'N') {
select |= SEL_ACT_RT;
val = RT_FL_NOAUDIT;
select |= SEL_ACT_RT;
select |= SEL_ACT_RT;
val = RT_FL_NOBAPLT;
select |= SEL_ACT_RT;
val = RT_FL_NOCFG;
MSG_LD_NODIRCONFIG_SIZE) == 0)) {
select |= SEL_ACT_RT;
select |= SEL_ACT_LMLT;
MSG_LD_NOENVCONFIG_SIZE) == 0)) {
select |= SEL_ACT_RT;
MSG_LD_NOFLTCONFIG_SIZE) == 0)) {
select |= SEL_ACT_RT2;
select |= SEL_ACT_LMLT;
MSG_LD_NOOBJALTER_SIZE) == 0)) {
select |= SEL_ACT_RT;
select |= SEL_ACT_RT;
}
}
/*
* LD_ORIGIN.
*/
else if (*s1 == 'O') {
#ifndef EXPAND_RELATIVE
/*
* Besides some old patches this is no longer required.
*/
}
#endif
return;
}
/*
* LD_PRELOAD and LD_PROFILE family.
*/
else if (*s1 == 'P') {
select |= SEL_ACT_STR;
if (select & SEL_REPLACE)
str = &rpl_preload;
else {
str = &prm_preload;
rpl_preload = 0;
}
/*
* Only one user library can be profiled at a time.
*/
select |= SEL_ACT_SPEC_2;
MSG_LD_PROFILE_OUTPUT_SIZE) == 0)) {
/*
* Only one user library can be profiled at a time.
*/
select |= SEL_ACT_STR;
str = &profile_out;
}
}
/*
* LD_SIGNAL.
*/
else if (*s1 == 'S') {
if (rtld_flags & RT_FL_SECURE)
return;
if ((len == MSG_LD_SIGNAL_SIZE) &&
MSG_LD_SIGNAL_SIZE) == 0)) {
select |= SEL_ACT_SPEC_2;
}
}
/*
* The LD_TRACE family (internal, used by ldd(1)). This definition is
* the key to enabling all other ldd(1) specific environment variables.
* In case an auditor is called, which in turn might exec(2) a
* subprocess, this variable is disabled, so that any subprocess
* escapes ldd(1) processing.
*/
else if (*s1 == 'T') {
if (((len == MSG_LD_TRACE_OBJS_SIZE) &&
MSG_LD_TRACE_OBJS_SIZE) == 0)) ||
((len == MSG_LD_TRACE_OBJS_E_SIZE) &&
MSG_LD_TRACE_OBJS_E_SIZE) == 0) && !aout) ||
MSG_LD_TRACE_OBJS_A_SIZE) == 0) && aout)))) {
select |= SEL_ACT_SPEC_2;
/*
* The simplest way to "disable" this variable is to
* truncate this string to "LD_'\0'". This string is
* ignored by any ld.so.1 environment processing.
* Use of such interfaces as unsetenv(3c) are overkill,
* and would drag too much libc implementation detail
* into ld.so.1.
*/
*s0 = '\0';
#else
/*
* Verify that the above write is appropriate for any new platforms.
*/
#endif
MSG_LD_TRACE_PTHS_SIZE) == 0)) {
select |= SEL_ACT_LML;
}
}
/*
* LD_UNREF and LD_UNUSED (internal, used by ldd(1)).
*/
else if (*s1 == 'U') {
select |= SEL_ACT_LML;
select |= SEL_ACT_LML;
}
}
/*
* LD_VERBOSE (internal, used by ldd(1)).
*/
else if (*s1 == 'V') {
select |= SEL_ACT_LML;
}
}
/*
* LD_WARN (internal, used by ldd(1)).
*/
else if (*s1 == 'W') {
select |= SEL_ACT_LML;
}
#ifdef SIEBEL_DISABLE
}
/*
* LD__FIX__ (undocumented, enable future technology that can't be
* delivered in a patch release).
*/
else if (*s1 == '_') {
select |= SEL_ACT_RT;
}
#endif
}
if (variable == 0)
return;
/*
* If the variable is already processed with ISA specific variable,
* no further processing needed.
*/
return;
/*
* Now mark the appropriate variables.
* If the replaceable variable is already set, then the
* process environment variable must be set. Any replaceable
* variable specified in a configuration file can be ignored.
*/
if (env_flags & ENV_TYP_ISA) {
/*
* This is ISA setting. We do the setting
* even if s2 is NULL.
* If s2 is NULL, we might need to undo
* the setting.
*/
if (select & SEL_REPLACE) {
return;
} else {
}
} else if (s2) {
/*
* This is non0-ISA setting
*/
if (select & SEL_REPLACE) {
return;
} else
} else
/*
* This is non-ISA setting which
* can be ignored.
*/
return;
/*
* Now perform the setting.
*/
if (select & SEL_ACT_RT) {
if (s2)
rtld_flags |= val;
else
rtld_flags &= ~val;
} else if (select & SEL_ACT_RT2) {
if (s2)
rtld_flags2 |= val;
else
rtld_flags2 &= ~val;
} else if (select & SEL_ACT_STR)
else if (select & SEL_ACT_LML) {
if (s2)
else
} else if (select & SEL_ACT_LMLT) {
if (s2)
else
} else if (select & SEL_ACT_SPEC_1) {
/*
* variable is either ENV_FLG_FLAGS or ENV_FLG_LIBPATH
*/
if (s2) {
if (variable == ENV_FLG_FLAGS)
else
} else {
if (variable == ENV_FLG_FLAGS)
env_info &= ~ENV_INF_FLAGCFG;
else
env_info &= ~ENV_INF_PATHCFG;
}
}
} else if (select & SEL_ACT_SPEC_2) {
/*
* variables can be: ENV_FLG_
* AUDIT_ARGS, BINDING, CONCURRENCY, CONFGEN,
* LOADFLTR, PROFILE, SIGNAL, TRACE_OBJS
*/
if (variable == ENV_FLG_AUDIT_ARGS) {
if (s2) {
} else
audit_argcnt = 0;
} else if (variable == ENV_FLG_BINDINGS) {
if (s2)
else
rpl_debug = 0;
} else if (variable == ENV_FLG_CONCURRENCY) {
if (s2)
rtld_flags &= ~RT_FL_NOCONCUR;
else
} else if (variable == ENV_FLG_CONFGEN) {
if (s2) {
*lmflags |= LML_FLG_IGNRELERR;
} else {
rtld_flags &= ~RT_FL_CONFGEN;
*lmflags &= ~LML_FLG_IGNRELERR;
}
} else if (variable == ENV_FLG_LOADFLTR) {
if (s2) {
if (*s2 == '2')
} else {
*lmtflags &= ~LML_TFLG_LOADFLTR;
rtld_flags &= ~RT_FL_WARNFLTR;
}
} else if (variable == ENV_FLG_PROFILE) {
profile_name = s2;
if (s2) {
return;
}
/* BEGIN CSTYLED */
if (rtld_flags & RT_FL_SECURE) {
#if defined(_ELF64)
#else
#endif
} else {
#if defined(_ELF64)
#else
#endif
}
/* END CSTYLED */
} else
profile_lib = 0;
} else if (variable == ENV_FLG_SIGNAL) {
} else if (variable == ENV_FLG_TRACE_OBJS) {
if (s2) {
if (*s2 == '2')
} else
*lmflags &=
}
}
}
/*
* Determine whether we have an architecture specific environment variable.
* If we do, and we're the wrong architecture, it'll just get ignored.
* Otherwise the variable is processed in it's architecture neutral form.
*/
static int
{
#if defined(_ELF64)
return (ENV_TYP_IGNORE);
#else
return (ENV_TYP_ISA);
#endif
}
#if defined(_ELF64)
return (ENV_TYP_ISA);
#else
return (ENV_TYP_IGNORE);
#endif
}
}
return (0);
}
/*
* Process an LD_FLAGS environment variable. The value can be a comma
* separated set of tokens, which are sent (in upper case) into the generic
* LD_XXXX environment variable engine. For example:
*
* LD_FLAGS=bind_now -> LD_BIND_NOW=1
* LD_FLAGS=library_path=/foo:. -> LD_LIBRARY_PATH=/foo:.
* LD_FLAGS=debug=files:detail -> LD_DEBUG=files:detail
* or
* LD_FLAGS=bind_now,library_path=/foo:.,debug=files:detail
*/
static int
{
if (str == 0)
return (0);
/*
* Create a new string as we're going to transform the token(s) into
* uppercase and separate tokens with nulls.
*/
return (1);
int flags;
if (estr == 0) {
if (*sstr == '=')
else {
/*
* Translate token to uppercase. Don't
* use toupper(3C) as including this
* code doubles the size of ld.so.1.
*/
}
}
continue;
}
*sstr = '\0';
if (estr) {
estr = 0;
} else
/*
* Fabricate a boolean definition for any unqualified variable.
* Thus LD_FLAGS=bind_now is represented as BIND_NOW=(null).
* The value is sufficient to assert any boolean variables, plus
* the term "(null)" is specifically chosen in case someone
* mistakenly supplies something like LD_FLAGS=library_path.
*/
if (estr == 0)
/*
* Determine whether the environment variable is 32- or 64-bit
* specific. The length, len, will reflect the architecture
* neutral portion of the string.
*/
}
if (len == 0)
return (0);
estr = 0;
}
return (0);
}
/*
* Process a single environment string. Only strings starting with `LD_' are
* reserved for our use. By convention, all strings should be of the form
* `LD_XXXX=', if the string is followed by a non-null value the appropriate
* functionality is enabled. Also pick off applicable locale variables.
*/
#define LOC_LANG 1
#define LOC_MESG 2
#define LOC_ALL 3
static void
int aout)
{
const char *s2;
if (*s1++ != 'L')
return;
/*
* See if we have any locale environment settings. These environment
* variables have a precedence, LC_ALL is higher than LC_MESSAGES which
* is higher than LANG.
*/
s2 += MSG_LC_ALL_SIZE;
}
MSG_LC_MESSAGES_SIZE) == 0) {
}
}
return;
}
return;
}
/*
* Pick off any LD_XXXX environment variables.
*/
int flags;
/*
* In a branded process we must ignore all LD_XXXX env vars
* because they are intended for the brand's linker.
* To affect the Solaris linker, use LD_BRAND_XXXX instead.
*/
if (rtld_flags2 & RT_FL2_BRANDED) {
MSG_LD_BRAND_PREFIX_SIZE) != 0)
return;
}
/*
* Environment variables with no value (ie. LD_XXXX=) typically
* have no impact, however if environment variables are defined
* within a configuration file, these null user settings can be
* used to disable any configuration replaceable definitions.
*/
s2 = 0;
} else if (*++s2 == '\0') {
s2 = 0;
} else {
s2++;
}
/*
* Determine whether the environment variable is 32- or 64-bit
* specific. The length, len, will reflect the architecture
* neutral portion of the string.
*/
return;
}
}
/*
* Internal getenv routine. Called immediately after ld.so.1 initializes
* itself.
*/
int
{
char *locale;
if (envp == (const char **)0)
return (0);
while (*envp != (const char *)0)
/*
* Having collected the best representation of any LD_FLAGS, process
* these strings.
*/
return (1);
/*
* Don't allow environment controlled auditing when tracing or if
* explicitly disabled. Trigger all tracing modes from
* LML_FLG_TRC_ENABLE.
*/
if ((*lmflags & LML_FLG_TRC_ENABLE) == 0)
*lmflags &= ~LML_MSK_TRC;
/*
* If both LD_BIND_NOW and LD_BIND_LAZY are specified, the former wins.
*/
/*
* If we have a locale setting make sure its worth processing further.
* C and POSIX locales don't need any processing. In addition, to
* the locale to contain a segment that leads upward in the file system
* hierarchy (i.e. no '..' segments). Given that we'll be confined to
* validate the mode or ownership of any message file (as libc's
* generic handling of message files does). Duplicate the string so
* that new locale setting can generically cleanup any previous locales.
*/
else
}
return (0);
}
/*
* Configuration environment processing. Called after the a.out has been
* processed (as the a.out can specify its own configuration file).
*/
int
{
return (0);
envtbl++;
}
/*
* Having collected the best representation of any LD_FLAGS, process
* these strings.
*/
return (1);
aout) == 1)
return (1);
/*
* Don't allow environment controlled auditing when tracing or if
* explicitly disabled. Trigger all tracing modes from
* LML_FLG_TRC_ENABLE.
*/
if ((*lmflags & LML_FLG_TRC_ENABLE) == 0)
*lmflags &= ~LML_MSK_TRC;
return (0);
}
int
{
/*
* We do not have a valid file descriptor, so we are unable
* to flush the buffer.
*/
return (0);
return (1);
}
/*
* Simplified printing. The following conversion specifications are supported:
*
* % [#] [-] [min field width] [. precision] s|d|x|c
*
*
* dorprf takes the output buffer in the form of Prfbuf which permits
* the verification of the output buffer size and the concatenation
* of data to an already existing output buffer. The Prfbuf
* structure contains the following:
*
* pr_buf pointer to the beginning of the output buffer.
* pr_cur pointer to the next available byte in the output buffer. By
* setting pr_cur ahead of pr_buf you can append to an already
* existing buffer.
* pr_len the size of the output buffer. By setting pr_len to '0' you
* disable protection from overflows in the output buffer.
* pr_fd a pointer to the file-descriptor the buffer will eventually be
* output to. If pr_fd is set to '-1' then it's assumed there is
* no output buffer, and doprf() will return with an error to
* indicate an output buffer overflow. If pr_fd is > -1 then when
* the output buffer is filled it will be flushed to pr_fd and will
* then be available for additional data.
*/
/*
* This macro is for use from within doprf only. It is to be used for checking
* the output buffer size and placing characters into the buffer.
*/
#define PUTC(c) \
{ \
char tmpc; \
\
tmpc = (c); \
return (0); \
} \
}
/*
* Define a local buffer size for building a numeric value - large enough to
* hold a 64-bit value.
*/
#define NUM_SIZE 22
{
char c;
while ((c = *format++) != '\0') {
if (c != '%') {
PUTC(c);
} else {
char *_s;
int ls = 0;
c = *format++;
switch (c) {
case '-':
flag |= FLG_UT_MINUS;
goto again;
case '#':
flag |= FLG_UT_SHARP;
goto again;
case '.':
flag |= FLG_UT_DOTSEEN;
goto again;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (flag & FLG_UT_DOTSEEN)
else
goto again;
case 'x':
case 'X':
base = 16;
break;
case 'd':
case 'D':
case 'u':
base = 10;
flag &= ~FLG_UT_SHARP;
break;
case 'l':
base = 10;
ls++; /* number of l's (long or long long) */
if ((*format == 'l') ||
goto again;
break;
case 'o':
case 'O':
base = 8;
break;
case 'c':
PUTC(c);
}
}
PUTC(c);
}
break;
case 's':
/* LINTED */
if (!prec)
/* LINTED */
while (_n-- > 0)
PUTC(' ');
}
PUTC(c);
}
while (_n-- > 0)
PUTC(' ');
}
break;
case '%':
PUTC('%');
break;
default:
break;
}
/*
* Numeric processing
*/
if (base) {
const char *string =
const char *prefix =
switch (ls) {
case 0: /* int */
num = (u_longlong_t)
break;
case 1: /* long */
num = (u_longlong_t)
break;
case 2: /* long long */
break;
}
if (flag & FLG_UT_SHARP) {
if (base == 16) {
psize = 2;
} else {
psize = 1;
}
}
}
/*
* Convert the numeric value into a local
* string (stored in reverse order).
*/
do {
ssize++;
} while (num);
/*
* Provide any precision or width padding.
*/
if (prec) {
/* LINTED */
while ((_n-- > 0) &&
*_s++ = '0';
ssize++;
}
}
/* LINTED */
while (_n-- > 0) {
PUTC(' ');
}
}
/*
* Print any prefix and the numeric string
*/
while (*prefix)
do {
/*
* Provide any width padding.
*/
/* LINTED */
while (_n-- > 0)
PUTC(' ');
}
}
}
}
PUTC('\0');
return (1);
}
static int
{
return (0);
/* LINTED */
}
/* VARARGS2 */
int
{
int len;
/*
* sprintf() return value excludes the terminating null byte.
*/
return (len - 1);
}
/* VARARGS3 */
int
{
int len;
return (len);
}
/* VARARGS2 */
int
{
int len;
return (len);
}
/*PRINTFLIKE1*/
int
{
/*
* Trim trailing '\0' form buffer
*/
}
/*PRINTFLIKE3*/
void
{
int overflow = 0;
static int lock = 0;
return;
/*
* Note: this lock is here to prevent the same thread from recursively
* entering itself during a eprintf. ie: during eprintf malloc() fails
* and we try and call eprintf ... and then malloc() fails ....
*/
lock = 1;
/*
* If we have completed startup initialization, all error messages
* must be saved. These are reported through dlerror(). If we're
* still in the initialization stage, output the error directly and
* add a newline.
*/
if (!(rtld_flags & RT_FL_APPLIC))
else
error = ERR_WARNING;
if (error == ERR_WARNING) {
if (err_strs[ERR_WARNING] == 0)
}
if (procname) {
overflow = 1;
} else {
overflow = 1;
}
if (overflow == 0) {
/*
* Remove the terminating '\0'.
*/
}
}
overflow = 1;
/*
* If this is an ELF error, it will have been generated by a support
* object that has a dependency on libelf. ld.so.1 doesn't generate any
* ELF error messages as it doesn't interact with libelf. Determine the
* ELF error string.
*/
static int (*elfeno)() = 0;
static const char *(*elfemg)();
const char *emsg;
elfeno = 0;
}
/*
* Lookup the message; equivalent to elf_errmsg(elf_errno()).
*/
emsg) == 0)
overflow = 1;
}
}
/*
* Push out any message that's been built. Note, in the case of an
* overflow condition, this message may be incomplete, in which case
* make sure any partial string is null terminated.
*/
if (overflow)
}
/*
* Determine if there was insufficient space left in the buffer to
* complete the message. If so, we'll have printed out as much as had
* been processed if we're not yet executing the application.
* Otherwise, there will be some debugging diagnostic indicating
* as much of the error message as possible. Write out a final buffer
* overflow diagnostic - unlocalized, so we don't chance more errors.
*/
if (overflow) {
if ((rtld_flags & RT_FL_SILENCERR) == 0) {
if ((rtld_flags & RT_FL_APPLIC) == 0) {
}
}
lock = 0;
return;
}
/*
* If the application has started, then error messages are being saved
* for retrieval by dlerror(), or possible flushing from rtldexit() in
* the case of a fatal error. In this case, establish the next error
* pointer. If we haven't started the application, the whole message
* buffer can be reused.
*/
if ((rtld_flags & RT_FL_SILENCERR) == 0) {
/*
* Note, should we encounter an error such as ENOMEM, there may
* be a number of the same error messages (ie. an operation
* fails with ENOMEM, and then the attempts to construct the
* error message itself, which incurs additional ENOMEM errors).
* Compare any previous error message with the one we've just
* created to prevent any duplication clutter.
*/
if ((rtld_flags & RT_FL_APPLIC) &&
*nextptr = '\0';
}
}
lock = 0;
}
#if DEBUG
/*
* Provide assfail() for ASSERT() statements,
*/
int
assfail(const char *a, const char *f, int l)
{
(void) printf("assertion failed: %s, file: %s, line: %d\n", a, f, l);
return (0);
}
#endif
/*
* Exit. If we arrive here with a non zero status it's because of a fatal
* error condition (most commonly a relocation error). If the application has
* already had control, then the actual fatal error message will have been
* recorded in the dlerror() message buffer. Print the message before really
* exiting.
*/
void
{
if (status) {
if (rtld_flags & RT_FL_APPLIC) {
/*
* If the error buffer has been used, write out all
* pending messages - lasterr is simply a pointer to
* the last message in this buffer. However, if the
* buffer couldn't be created at all, lasterr points
* to a constant error message string.
*/
if (*errbuf) {
}
}
}
}
}
}
/*
* dz_fd is exported for possible use by libld.so, and to insure it gets
* closed on leaving ld.so.1.
*/
int dz_fd = FD_UNAVAIL;
void
{
}
/*
* mmap() a page from MAP_ANON
*
* Note: MAP_ANON is only on Solaris8++, we use this routine to
* not only mmap(MAP_ANON) but to also probe if it is available
* on the current OS.
*/
{
#if defined(MAP_ANON)
static int noanon = 0;
if (noanon == 0) {
return (AM_OK);
}
return (AM_ERROR);
} else
noanon = 1;
}
#endif
return (AM_NOSUP);
}
/*
*
* (MAP_ANON only appears on Solaris 8, so we need fall-back
* behavior for older systems.)
*/
{
int err;
return (addr);
return (MAP_FAILED);
/* amret == AM_NOSUP -> fallback to a devzero mmaping */
if (dz_fd == FD_UNAVAIL) {
O_RDONLY)) == FD_UNAVAIL) {
return (MAP_FAILED);
}
}
}
return (va);
}
static int pr_fd = FD_UNAVAIL;
int
{
char proc[16];
if (pr_fd == FD_UNAVAIL) {
(int)getpid());
}
}
return (pr_fd);
}
static int nu_fd = FD_UNAVAIL;
{
int err;
if (nu_fd == FD_UNAVAIL) {
O_RDONLY)) == FD_UNAVAIL) {
return (MAP_FAILED);
}
}
MAP_FAILED) {
}
return (va);
}
/*
* Generic entry point from user code - simply grabs a lock.
*/
int
enter(void)
{
if (rt_bind_guard(THR_FLG_RTLD)) {
(void) rt_mutex_lock(&rtldlock);
return (1);
}
return (0);
}
/*
* Generate diagnostics as to whether an object has been used. A symbolic
* reference that gets bound to an object marks it as used. Dependencies that
* are unused when RTLD_NOW is in effect should be removed from future builds
* of an object. Dependencies that are unused without RTLD_NOW in effect are
* candidates for lazy-loading.
* Unreferenced objects identify objects that are defined as dependencies but
* are unreferenced by the caller (they may however be referenced by other
* objects within the process, and therefore don't qualify as completely unused.
*/
void
{
int nl = 0;
/*
* If we're not tracing unused references or dependencies, or debugging
* there's nothing to do.
*/
if ((tracing == 0) && (DBG_ENABLED == 0))
return;
/*
* Traverse the link-maps looking for unreferenced or unused
* dependencies. Ignore the first object on a link-map list, as this
* is effectively always used.
*/
/*
* If tracing unreferenced objects, or under debugging,
* determine whether any of this objects callers haven't
* referenced it.
*/
continue;
continue;
/* BEGIN CSTYLED */
if (nl++ == 0) {
if (tracing & LML_FLG_TRC_UNREF)
else
DBG_NL_STD));
}
if (tracing & LML_FLG_TRC_UNREF)
else
/* END CSTYLED */
}
}
/*
* If tracing unused objects simply display those objects that
* haven't been referenced by anyone.
*/
continue;
if (nl++ == 0) {
if (tracing)
else
}
if (tracing)
else
} else {
if (tracing)
else
}
}
}
/*
* Initialization routine for the Fmap structure. If the fmap structure is
* already in use, any mapping is released. The structure is then initialized
* in preparation for further use.
*/
void
{
#if defined(MAP_ALIGN)
/*
* If MAP_ALIGN is set, the fm_addr has been seeded with an alignment
* value. Otherwise, if fm_addr is non-null it indicates a mapping that
* should now be freed.
*/
/*
* Providing we haven't determined that this system doesn't support
* MAP_ALIGN, initialize the mapping address with the default segment
* alignment.
*/
if ((rtld_flags2 & RT_FL2_NOMALIGN) == 0) {
} else {
}
#else
#endif
}
/*
* Generic cleanup routine called prior to returning control to the user.
* Insures that any ld.so.1 specific file descriptors or temporary mapping are
* released, and any locks dropped.
*/
void
{
/*
* Alert the debuggers that the link-maps are consistent. Note, in the
* case of tearing down a whole link-map list, lml will be null. In
* this case use the main link-map list to test for a notification.
*/
if (elml == 0)
/*
* Alert any auditors that the link-maps are consistent.
*/
}
if (dz_fd != FD_UNAVAIL) {
dz_fd = FD_UNAVAIL;
}
if (pr_fd != FD_UNAVAIL) {
pr_fd = FD_UNAVAIL;
}
if (nu_fd != FD_UNAVAIL) {
nu_fd = FD_UNAVAIL;
}
fmap_setup();
/*
* Reinitialize error message pointer, and any overflow indication.
*/
prevptr = 0;
/*
* Don't drop our lock if we are running on our link-map list as
* there's little point in doing so since we are single-threaded.
*
* LML_FLG_HOLDLOCK is set for:
* *) The ld.so.1's link-map list.
* *) The auditor's link-map if the environment is
*/
return;
if (rt_bind_clear(0) & THR_FLG_RTLD) {
(void) rt_mutex_unlock(&rtldlock);
(void) rt_bind_clear(THR_FLG_RTLD);
}
}
int
{
/*
* An object can always find symbols within itself.
*/
return (1);
/*
* Don't allow an object to bind to an object that is being deleted
* unless the binder is also being deleted.
*/
return (0);
/*
* An object with world access can always bind to an object with global
* visibility.
*/
return (1);
/*
* An object with local access can only bind to an object that is a
* member of the same group.
*/
return (0);
/*
* Traverse the list of groups the caller is a part of.
*/
/*
* If we're testing for the ability of two objects to bind to
* each other regardless of a specific group, ignore that group.
*/
continue;
/*
* Traverse the list of groups the destination is a part of.
*/
continue;
/*
* Make sure the relationship between the destination
* and the caller provide symbols for relocation.
* Parents are maintained as callers, but unless the
* destination object was opened with RTLD_PARENT, the
* parent doesn't provide symbols for the destination
* to relocate against.
*/
continue;
return (1);
}
}
}
return (0);
}
/*
* Initialize the environ symbol. Traditionally this is carried out by the crt
* code prior to jumping to main. However, init sections get fired before this
* variable is initialized, so ld.so.1 sets this directly from the AUX vector
* information. In addition, a process may have multiple link-maps (ld.so.1's
* debugging and preloading objects), and link auditing, and each may need an
* environ variable set.
*
* This routine is called after a relocation() pass, and thus provides for:
*
* o setting environ on the main link-map after the initial application and
* its dependencies have been established. Typically environ lives in the
* application (provided by its crt), but in older applications it might
* be in libc. Who knows what's expected of applications not built on
* Solaris.
*
* o after loading a new shared object. We can add shared objects to various
* link-maps, and any link-map dependencies requiring getopt() require
* their own environ. In addition, lazy loading might bring in the
* supplier of environ (libc used to be a lazy loading candidate) after
* the link-map has been established and other objects are present.
*
* This routine handles all these scenarios, without adding unnecessary overhead
* to ld.so.1.
*/
void
{
sl.sl_rsymndx = 0;
lml->lm_environ =
}
}
/*
* Determine whether we have a secure executable. Uid and gid information
* can be passed to us via the aux vector, however if these values are -1
* then use the appropriate system call to obtain them.
*
* o If the user is the root they can do anything
*
* o If the real and effective uid's don't match, or the real and
* effective gid's don't match then this is determined to be a `secure'
* application.
*
* This function is called prior to any dependency processing (see _setup.c).
* Any secure setting will remain in effect for the life of the process.
*/
void
{
#ifdef AT_SUN_AUXFLAGS
if (auxflags != -1) {
if ((auxflags & AF_SUN_SETUGID) != 0)
return;
}
#endif
if (uid) {
else {
}
}
}
/*
* _REENTRANT code gets errno redefined to a function so provide for return
* of the thread errno if applicable. This has no meaning in ld.so.1 which
* is basically singled threaded. Provide the interface for our dependencies.
*/
int *
___errno()
{
extern int errno;
return (&errno);
}
/*
* The interface with the c library which is supplied through libdl.so.1.
* A non-null argument allows a function pointer array to be passed to us which
* is used to re-initialize the linker libc table.
*/
void
{
}
/*
* Determine whether a symbol name should be demangled.
*/
const char *
{
if (rtld_flags & RT_FL_DEMANGLE)
return (conv_demangle_name(name));
else
return (name);
}