/*
* 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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
#include "lint.h"
#include "thr_uberdata.h"
#include "libc_int.h"
#include "atexit.h"
#include "stdiom.h"
/*
* Note that memory is managed by lmalloc()/lfree().
*
* Among other reasons, this is occasioned by the insistence of our
* brothers sh(1) and csh(1) that they can do malloc, etc., better than
* libc can. Those programs define their own malloc routines, and
* initialize the underlying mechanism in main(). This means that calls
* to malloc occuring before main will crash. The loader calls atexit(3C)
* before calling main, so we'd better avoid malloc() when it does.
*
* Another reason for using lmalloc()/lfree() is that the atexit()
* list must transcend all link maps. See the Linker and Libraries
* Guide for information on alternate link maps.
*
* See "thr_uberdata.h" for the definitions of structures used here.
*/
/*
* exitfns_lock is declared to be a recursive mutex so that we
* can hold it while calling out to the registered functions.
* If they call back to us, we are self-consistent and everything
* works, even the case of calling exit() from functions called
* by _exithandle() (recursive exit()). All that is required is
* that the registered functions actually return (no longjmp()s).
*
* Because exitfns_lock is declared to be a recursive mutex, we
* cannot use it with lmutex_lock()/lmutex_unlock() and we must
* use mutex_lock()/mutex_unlock(). This means that atexit()
* and exit() are not async-signal-safe. We make them fork1-safe
* via the atexit_locks()/atexit_unlocks() functions, called from
* libc_prepare_atfork()/libc_child_atfork()/libc_parent_atfork()
*/
/*
* atexit_locks() and atexit_unlocks() are called on every link map.
* Do not use curthread->ul_uberdata->atexit_root for these.
*/
void
{
}
void
{
}
/*
* atexit() is called before the primordial thread is fully set up.
* Be careful about dereferencing self->ul_uberdata->atexit_root.
*/
int
{
_exthdlr_t *p;
return (-1);
else {
}
return (0);
}
void
_exithandle(void)
{
_exthdlr_t *p;
int cancel_state;
/* disable cancellation while running atexit handlers */
while (p != NULL) {
p->hdlr();
lfree(p, sizeof (_exthdlr_t));
}
}
/*
* _get_exit_frame_monitor is called by the C++ runtimes.
*/
void *
_get_exit_frame_monitor(void)
{
return (&arp->exit_frame_monitor);
}
/*
* The following is a routine which the loader (ld.so.1) calls when it
* processes a dlclose call on an object. It resets all signal handlers
* which fall within the union of the ranges specified by the elements
* of the array range to SIG_DFL.
*/
static void
{
int sig;
void (*handler)();
goto again;
}
}
}
}
/*
* The following is a routine which the loader (ld.so.1) calls when it
* processes a dlclose call on an object. It cancels all atfork() entries
* whose prefork, parent postfork, or child postfork functions fall within
* the union of the ranges specified by the elements of the array range.
*/
static void
{
void (*func)(void);
int start_again;
do {
start_again = 0;
/*
* dlclose() called from a fork handler.
* Deleting the entry would wreak havoc.
* Just null out the function pointers
* and leave the entry in place.
*/
continue;
}
/* deleting the list head member */
start_again = 1;
}
/* we deleted the whole list */
break;
}
}
}
}
/*
* The following is a routine which the loader (ld.so.1) calls when it
* processes a dlclose call on an object. It sets the destructor
* function pointer to NULL for all keys whose destructors fall within
* the union of the ranges specified by the elements of the array range.
* We don't assign TSD_UNALLOCATED (the equivalent of pthread_key_destroy())
* because the thread may use the key's TSD further on in fini processing.
*/
static void
{
void (*func)(void *);
int key;
func != TSD_UNALLOCATED &&
}
}
/*
* The following is a routine which the loader (ld.so.1) calls when it
* processes dlclose calls on objects with atexit registrations. It
* executes the exit handlers that fall within the union of the ranges
* specified by the elements of the array range in the REVERSE ORDER of
* their registration. Do not change this characteristic; it is REQUIRED
* BEHAVIOR.
*/
int
{
_exthdlr_t *o; /* previous node */
_exthdlr_t *p; /* this node */
int cancel_state;
/* disable cancellation while running atexit handlers */
o = NULL;
while (p != NULL) {
/* We need to execute this one */
if (o != NULL)
else
p->hdlr();
lfree(p, sizeof (_exthdlr_t));
o = NULL;
} else {
o = p;
p = p->next;
}
}
return (0);
}
static int
{
return (1);
}
}
return (0);
}