source: branches/libc-0.6/src/emx/include/InnoTekLIBC/atexit.h

Last change on this file was 2786, checked in by bird, 19 years ago

Fixed problems with fork() and module loading/unloading. Fixes #76.
Fixed atexit() and on_exit() problem with callbacks in unloaded DLLs. Fixes #103.

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.0 KB
Line 
1/* $Id: atexit.h 2786 2006-08-27 14:26:13Z bird $ */
2/** @file
3 *
4 * LIBC atexit() and on_exit() support.
5 *
6 * Copyright (c) 2005 knut st. osmundsen <bird@anduin.net>
7 *
8 *
9 * This file is part of InnoTek LIBC.
10 *
11 * InnoTek LIBC is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published
13 * by the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * InnoTek LIBC is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with InnoTek LIBC; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27#ifndef __InnoTekLIBC_atexit_h__
28#define __InnoTekLIBC_atexit_h__
29
30#include <sys/types.h>
31
32/** Entry type. */
33typedef enum __LIBC_ATEXITTYPE
34{
35 __LIBC_ATEXITTYPE_FREE = 0,
36 __LIBC_ATEXITTYPE_ATEXIT,
37 __LIBC_ATEXITTYPE_ONEXIT,
38 /** State transition state. */
39 __LIBC_ATEXITTYPE_TRANS,
40 /** The module containing the callback was unloaded. */
41 __LIBC_ATEXITTYPE_UNLOADED
42} __LIBC_ATEXITTYPE;
43
44/**
45 * At exit entry.
46 */
47typedef struct __LIBC_ATEXIT
48{
49 /** Entry type. */
50 __LIBC_ATEXITTYPE volatile enmType;
51 /** The (native) module handle this callback is connected to.
52 * This will be 0 if no such association. */
53 uintptr_t hmod;
54 union
55 {
56 /** Data for a atexit() registration. */
57 struct
58 {
59 /** Pointer to the callback. */
60 void (*pfnCallback)();
61 } AtExit;
62
63 /** Data for a on_exit() registration. */
64 struct
65 {
66 /** Pointer to the callback .*/
67 void (*pfnCallback)(int iExit, void *pvUser);
68 /** User argument. */
69 void *pvUser;
70 } OnExit;
71 } u;
72} __LIBC_ATEXIT, *__LIBC_PATEXIT;
73
74/**
75 * Chunk of at exit registrations.
76 */
77typedef struct __LIBC_ATEXITCHUNK
78{
79 /** Pointer to the next chunk. */
80 struct __LIBC_ATEXITCHUNK * volatile pNext;
81 /** Number of entries which may contain a valid callback.
82 * (May include freed entries.) */
83 uint32_t volatile c;
84 /** Array of at exit entries. */
85 __LIBC_ATEXIT a[64];
86} __LIBC_ATEXITCHUNK, *__LIBC_PATEXITCHUNK;
87
88
89__BEGIN_DECLS
90
91/** Pointer to the head of the exit list chain - LIFO. */
92extern __LIBC_PATEXITCHUNK __libc_gAtExitHead;
93
94/**
95 * Allocate a new atexit entry.
96 *
97 * @returns Pointer to new entry.
98 * @returns NULL on failure.
99 *
100 * @param pvCallback The callback address.
101 * This used to initialize the __LIBC_AT_EXIT::hmod field.
102 */
103__LIBC_PATEXIT __libc_atexit_new(void *pvCallback);
104
105/**
106 * Invalidate all atexit and on_exit callback for a
107 * module which is being unloaded.
108 *
109 * @param hmod The module handle.
110 */
111void __libc_atexit_unload(uintptr_t hmod);
112
113__END_DECLS
114
115#endif
Note: See TracBrowser for help on using the repository browser.