xref: /openbsd-src/lib/libc/stdlib/atexit.h (revision 720afc0eea9594cc39e94e9ff3059afbb0ab9593)
1*720afc0eSguenther /*	$OpenBSD: atexit.h,v 1.12 2017/12/16 20:06:56 guenther Exp $ */
22762c2edSdhartmei 
32762c2edSdhartmei /*
42762c2edSdhartmei  * Copyright (c) 2002 Daniel Hartmeier
5df930be7Sderaadt  * All rights reserved.
6df930be7Sderaadt  *
7df930be7Sderaadt  * Redistribution and use in source and binary forms, with or without
8df930be7Sderaadt  * modification, are permitted provided that the following conditions
9df930be7Sderaadt  * are met:
102762c2edSdhartmei  *
112762c2edSdhartmei  *    - Redistributions of source code must retain the above copyright
12df930be7Sderaadt  *      notice, this list of conditions and the following disclaimer.
132762c2edSdhartmei  *    - Redistributions in binary form must reproduce the above
142762c2edSdhartmei  *      copyright notice, this list of conditions and the following
152762c2edSdhartmei  *      disclaimer in the documentation and/or other materials provided
162762c2edSdhartmei  *      with the distribution.
17df930be7Sderaadt  *
182762c2edSdhartmei  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
192762c2edSdhartmei  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
202762c2edSdhartmei  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
212762c2edSdhartmei  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
222762c2edSdhartmei  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
232762c2edSdhartmei  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
242762c2edSdhartmei  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
252762c2edSdhartmei  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
262762c2edSdhartmei  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
272762c2edSdhartmei  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
282762c2edSdhartmei  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
292762c2edSdhartmei  * POSSIBILITY OF SUCH DAMAGE.
30df930be7Sderaadt  *
31df930be7Sderaadt  */
32df930be7Sderaadt 
33df930be7Sderaadt struct atexit {
34df930be7Sderaadt 	struct atexit *next;		/* next in list */
35df930be7Sderaadt 	int ind;			/* next index in this table */
362762c2edSdhartmei 	int max;			/* max entries >= ATEXIT_SIZE */
375198527cSmillert 	struct atexit_fn {
385537d3e0Skettenis 		void (*fn_ptr)(void *);
395198527cSmillert 		void *fn_arg;		/* argument for CXA callback */
405198527cSmillert 		void *fn_dso;		/* shared module handle */
415198527cSmillert 	} fns[1];			/* the table itself */
42df930be7Sderaadt };
43df930be7Sderaadt 
44*720afc0eSguenther /* a chain of these are hung off each thread's TIB's tib_atexit member */
45*720afc0eSguenther struct thread_atexit_fn {
46*720afc0eSguenther 	void (*func)(void *);
47*720afc0eSguenther 	void *arg;
48*720afc0eSguenther 	struct thread_atexit_fn *next;
49*720afc0eSguenther };
50*720afc0eSguenther 
5157b9636dSguenther __BEGIN_HIDDEN_DECLS
52df930be7Sderaadt extern struct atexit *__atexit;		/* points to head of LIFO stack */
5357b9636dSguenther __END_HIDDEN_DECLS
545198527cSmillert 
555198527cSmillert int	__cxa_atexit(void (*)(void *), void *, void *);
560afcdedaSkettenis int	__cxa_thread_atexit(void (*)(void *), void *, void *);
575198527cSmillert void	__cxa_finalize(void *);
5857b9636dSguenther 
5957b9636dSguenther PROTO_NORMAL(__cxa_atexit);
600afcdedaSkettenis PROTO_STD_DEPRECATED(__cxa_thread_atexit);
6157b9636dSguenther PROTO_NORMAL(__cxa_finalize);
62