VirtualBox

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

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

iprt/*: BEGIN_DECLS -> RT_BEGIN_DECLS; END_DECLS -> RT_END_DECLS.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.5 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_BEGIN_DECLS
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#endif
118
119#ifdef IN_RC
120/**
121 * Initializes the raw-mode context runtime library.
122 *
123 * @returns iprt status code.
124 *
125 * @param u64ProgramStartNanoTS The startup timestamp.
126 */
127RTGCDECL(int) RTRCInit(uint64_t u64ProgramStartNanoTS);
128
129/**
130 * Terminates the raw-mode context runtime library.
131 */
132RTGCDECL(void) RTRCTerm(void);
133#endif
134
135
136/**
137 * Termination reason.
138 */
139typedef enum RTTERMREASON
140{
141 /** Normal exit. iStatus contains the exit code. */
142 RTTERMREASON_EXIT = 1,
143 /** Any abnormal exit. iStatus is 0 and has no meaning. */
144 RTTERMREASON_ABEND,
145 /** Killed by a signal. The iStatus contains the signal number. */
146 RTTERMREASON_SIGNAL,
147 /** The IPRT module is being unloaded. iStatus is 0 and has no meaning. */
148 RTTERMREASON_UNLOAD
149} RTTERMREASON;
150
151/** Whether lazy clean up is Okay or not.
152 * When the process is exiting, it is a waste of time to for instance free heap
153 * memory or close open files. OTOH, when the runtime is unloaded from the
154 * process, it is important to release absolutely all resources to prevent
155 * resource leaks. */
156#define RTTERMREASON_IS_LAZY_CLEANUP_OK(enmReason) ((enmReason) != RTTERMREASON_UNLOAD)
157
158
159/**
160 * IPRT termination callback function.
161 *
162 * @param enmReason The cause of the termination.
163 * @param iStatus The meaning of this depends on enmReason.
164 * @param pvUser User argument passed to RTTermRegisterCallback.
165 */
166typedef DECLCALLBACK(void) FNRTTERMCALLBACK(RTTERMREASON enmReason, int32_t iStatus, void *pvUser);
167/** Pointer to an IPRT termination callback function. */
168typedef FNRTTERMCALLBACK *PFNRTTERMCALLBACK;
169
170
171/**
172 * Registers a termination callback.
173 *
174 * This is intended for performing clean up during IPRT termination. Frequently
175 * paired with lazy initialization thru RTOnce.
176 *
177 * The callbacks are called in LIFO order.
178 *
179 * @returns IPRT status code.
180 *
181 * @param pfnCallback The callback function.
182 * @param pvUser The user argument for the callback.
183 *
184 * @remarks May need to acquire a fast mutex or critical section, so use with
185 * some care in ring-0 context.
186 *
187 * @remarks Be very careful using this from code that may be unloaded before
188 * IPRT terminates. Unlike some atexit and on_exit implementations,
189 * IPRT will not automatically unregister callbacks when a module gets
190 * unloaded.
191 */
192RTDECL(int) RTTermRegisterCallback(PFNRTTERMCALLBACK pfnCallback, void *pvUser);
193
194/**
195 * Deregister a termination callback.
196 *
197 * @returns VINF_SUCCESS if found, VERR_NOT_FOUND if the callback/pvUser pair
198 * wasn't found.
199 *
200 * @param pfnCallback The callback function.
201 * @param pvUser The user argument for the callback.
202 */
203RTDECL(int) RTTermDeregisterCallback(PFNRTTERMCALLBACK pfnCallback, void *pvUser);
204
205/**
206 * Runs the termination callback queue.
207 *
208 * Normally called by an internal IPRT termination function, but may also be
209 * called by external code immediately prior to terminating IPRT if it is in a
210 * better position to state the termination reason and/or status.
211 *
212 * @param enmReason The reason why it's called.
213 * @param iStatus The associated exit status or signal number.
214 */
215RTDECL(void) RTTermRunCallbacks(RTTERMREASON enmReason, int32_t iStatus);
216
217/** @} */
218
219/** @} */
220
221RT_END_DECLS
222
223
224#endif
225
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