VirtualBox

source: vbox/trunk/include/iprt/initterm.h@ 25003

Last change on this file since 25003 was 24179, checked in by vboxsync, 15 years ago

iprt/initterm.h,SUPDrv-solaris.c: Added RTR0TermForced so the module containing IPRT can make sure it's really terminated and that modules not calling RTR0Term doesn't create trouble (other than debug assertions). Use this for SUPDrv on Solaris.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1/** @file
2 * IPRT - Runtime Init/Term.
3 */
4
5/*
6 * Copyright (C) 2006-2009 Sun Microsystems, Inc.
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 *
25 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
26 * Clara, CA 95054 USA or visit http://www.sun.com if you need
27 * additional information or have any questions.
28 */
29
30#ifndef ___iprt_initterm_h
31#define ___iprt_initterm_h
32
33#include <iprt/cdefs.h>
34#include <iprt/types.h>
35
36RT_C_DECLS_BEGIN
37
38/** @defgroup grp_rt IPRT APIs
39 * @{
40 */
41
42/** @defgroup grp_rt_initterm Init / Term
43 * @{
44 */
45
46#ifdef IN_RING3
47/**
48 * Initializes the runtime library.
49 *
50 * @returns iprt status code.
51 */
52RTR3DECL(int) RTR3Init(void);
53
54
55/**
56 * Initializes the runtime library and try initialize SUPLib too.
57 *
58 * @returns IPRT status code.
59 * @param pszProgramPath The path to the program file.
60 *
61 * @remarks Failure to initialize SUPLib is ignored.
62 */
63RTR3DECL(int) RTR3InitAndSUPLib(void);
64
65/**
66 * Initializes the runtime library passing it the program path.
67 *
68 * @returns IPRT status code.
69 * @param pszProgramPath The path to the program file.
70 */
71RTR3DECL(int) RTR3InitWithProgramPath(const char *pszProgramPath);
72
73/**
74 * Initializes the runtime library passing it the program path,
75 * and try initialize SUPLib too (failures ignored).
76 *
77 * @returns IPRT status code.
78 * @param pszProgramPath The path to the program file.
79 *
80 * @remarks Failure to initialize SUPLib is ignored.
81 */
82RTR3DECL(int) RTR3InitAndSUPLibWithProgramPath(const char *pszProgramPath);
83
84/**
85 * Initializes the runtime library and possibly also SUPLib too.
86 *
87 * Avoid this interface, it's not considered stable.
88 *
89 * @returns IPRT status code.
90 * @param iVersion The interface version. Must be 0 atm.
91 * @param pszProgramPath The program path. Pass NULL if we're to figure it out ourselves.
92 * @param fInitSUPLib Whether to initialize the support library or not.
93 */
94RTR3DECL(int) RTR3InitEx(uint32_t iVersion, const char *pszProgramPath, bool fInitSUPLib);
95
96/**
97 * Terminates the runtime library.
98 */
99RTR3DECL(void) RTR3Term(void);
100
101#endif /* IN_RING3 */
102
103
104#ifdef IN_RING0
105/**
106 * Initalizes the ring-0 driver runtime library.
107 *
108 * @returns iprt status code.
109 * @param fReserved Flags reserved for the future.
110 */
111RTR0DECL(int) RTR0Init(unsigned fReserved);
112
113/**
114 * Terminates the ring-0 driver runtime library.
115 */
116RTR0DECL(void) RTR0Term(void);
117
118/**
119 * Forcibily terminates the ring-0 driver runtime library.
120 *
121 * This should be used when statically linking the IPRT. Module using dynamic
122 * linking shall use RTR0Term. If you're not sure, use RTR0Term!
123 */
124RTR0DECL(void) RTR0TermForced(void);
125#endif
126
127#ifdef IN_RC
128/**
129 * Initializes the raw-mode context runtime library.
130 *
131 * @returns iprt status code.
132 *
133 * @param u64ProgramStartNanoTS The startup timestamp.
134 */
135RTGCDECL(int) RTRCInit(uint64_t u64ProgramStartNanoTS);
136
137/**
138 * Terminates the raw-mode context runtime library.
139 */
140RTGCDECL(void) RTRCTerm(void);
141#endif
142
143
144/**
145 * Termination reason.
146 */
147typedef enum RTTERMREASON
148{
149 /** Normal exit. iStatus contains the exit code. */
150 RTTERMREASON_EXIT = 1,
151 /** Any abnormal exit. iStatus is 0 and has no meaning. */
152 RTTERMREASON_ABEND,
153 /** Killed by a signal. The iStatus contains the signal number. */
154 RTTERMREASON_SIGNAL,
155 /** The IPRT module is being unloaded. iStatus is 0 and has no meaning. */
156 RTTERMREASON_UNLOAD
157} RTTERMREASON;
158
159/** Whether lazy clean up is Okay or not.
160 * When the process is exiting, it is a waste of time to for instance free heap
161 * memory or close open files. OTOH, when the runtime is unloaded from the
162 * process, it is important to release absolutely all resources to prevent
163 * resource leaks. */
164#define RTTERMREASON_IS_LAZY_CLEANUP_OK(enmReason) ((enmReason) != RTTERMREASON_UNLOAD)
165
166
167/**
168 * IPRT termination callback function.
169 *
170 * @param enmReason The cause of the termination.
171 * @param iStatus The meaning of this depends on enmReason.
172 * @param pvUser User argument passed to RTTermRegisterCallback.
173 */
174typedef DECLCALLBACK(void) FNRTTERMCALLBACK(RTTERMREASON enmReason, int32_t iStatus, void *pvUser);
175/** Pointer to an IPRT termination callback function. */
176typedef FNRTTERMCALLBACK *PFNRTTERMCALLBACK;
177
178
179/**
180 * Registers a termination callback.
181 *
182 * This is intended for performing clean up during IPRT termination. Frequently
183 * paired with lazy initialization thru RTOnce.
184 *
185 * The callbacks are called in LIFO order.
186 *
187 * @returns IPRT status code.
188 *
189 * @param pfnCallback The callback function.
190 * @param pvUser The user argument for the callback.
191 *
192 * @remarks May need to acquire a fast mutex or critical section, so use with
193 * some care in ring-0 context.
194 *
195 * @remarks Be very careful using this from code that may be unloaded before
196 * IPRT terminates. Unlike some atexit and on_exit implementations,
197 * IPRT will not automatically unregister callbacks when a module gets
198 * unloaded.
199 */
200RTDECL(int) RTTermRegisterCallback(PFNRTTERMCALLBACK pfnCallback, void *pvUser);
201
202/**
203 * Deregister a termination callback.
204 *
205 * @returns VINF_SUCCESS if found, VERR_NOT_FOUND if the callback/pvUser pair
206 * wasn't found.
207 *
208 * @param pfnCallback The callback function.
209 * @param pvUser The user argument for the callback.
210 */
211RTDECL(int) RTTermDeregisterCallback(PFNRTTERMCALLBACK pfnCallback, void *pvUser);
212
213/**
214 * Runs the termination callback queue.
215 *
216 * Normally called by an internal IPRT termination function, but may also be
217 * called by external code immediately prior to terminating IPRT if it is in a
218 * better position to state the termination reason and/or status.
219 *
220 * @param enmReason The reason why it's called.
221 * @param iStatus The associated exit status or signal number.
222 */
223RTDECL(void) RTTermRunCallbacks(RTTERMREASON enmReason, int32_t iStatus);
224
225/** @} */
226
227/** @} */
228
229RT_C_DECLS_END
230
231
232#endif
233
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette