VirtualBox

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

Last change on this file since 55969 was 53525, checked in by vboxsync, 10 years ago

iprt: added RTR3InitIsInitialized

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.4 KB
Line 
1/** @file
2 * IPRT - Runtime Init/Term.
3 */
4
5/*
6 * Copyright (C) 2006-2013 Oracle Corporation
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
26#ifndef ___iprt_initterm_h
27#define ___iprt_initterm_h
28
29#include <iprt/cdefs.h>
30#include <iprt/types.h>
31
32RT_C_DECLS_BEGIN
33
34/** @defgroup grp_rt IPRT C/C++ APIs
35 * @{
36 */
37
38/** @defgroup grp_rt_initterm Init / Term
39 * @{
40 */
41
42#ifdef IN_RING3
43/** @name RTR3Init flags (RTR3INIT_XXX).
44 * @{ */
45/** Try initialize SUPLib. */
46#define RTR3INIT_FLAGS_SUPLIB RT_BIT(0)
47/** Initializing IPRT from a DLL. */
48#define RTR3INIT_FLAGS_DLL RT_BIT(1)
49/** We are sharing a process space, so we need to behave. */
50#define RTR3INIT_FLAGS_UNOBTRUSIVE RT_BIT(2)
51/** The caller ensures that the argument bector is UTF-8. */
52#define RTR3INIT_FLAGS_UTF8_ARGV RT_BIT(3)
53/** @} */
54
55/** @name RTR3InitEx version
56 * @{ */
57/** Version 1. */
58#define RTR3INIT_VER_1 UINT32_C(1)
59/** The current version. */
60#define RTR3INIT_VER_CUR RTR3INIT_VER_1
61/** @} */
62
63/**
64 * Initializes the runtime library.
65 *
66 * @returns iprt status code.
67 * @param fFlags Flags, see RTR3INIT_XXX.
68 */
69RTR3DECL(int) RTR3InitExeNoArguments(uint32_t fFlags);
70
71/**
72 * Initializes the runtime library.
73 *
74 * @returns iprt status code.
75 * @param cArgs Pointer to the argument count.
76 * @param ppapszArgs Pointer to the argument vector pointer.
77 * @param fFlags Flags, see RTR3INIT_XXX.
78 */
79RTR3DECL(int) RTR3InitExe(int cArgs, char ***papszArgs, uint32_t fFlags);
80
81/**
82 * Initializes the runtime library.
83 *
84 * @returns iprt status code.
85 * @param fFlags Flags, see RTR3INIT_XXX.
86 */
87RTR3DECL(int) RTR3InitDll(uint32_t fFlags);
88
89/**
90 * Initializes the runtime library and possibly also SUPLib too.
91 *
92 * Avoid this interface, it's not considered stable.
93 *
94 * @returns IPRT status code.
95 * @param iVersion The interface version. Must be 0 atm.
96 * @param fFlags Flags, see RTR3INIT_XXX.
97 * @param cArgs Pointer to the argument count.
98 * @param ppapszArgs Pointer to the argument vector pointer. NULL
99 * allowed if @a cArgs is 0.
100 * @param pszProgramPath The program path. Pass NULL if we're to figure it
101 * out ourselves.
102 */
103RTR3DECL(int) RTR3InitEx(uint32_t iVersion, uint32_t fFlags, int cArgs, char ***papszArgs, const char *pszProgramPath);
104
105/**
106 * Terminates the runtime library.
107 */
108RTR3DECL(void) RTR3Term(void);
109
110/**
111 * Is IPRT succesfully initialized?
112 *
113 * @returns true/false.
114 */
115RTR3DECL(bool) RTR3InitIsInitialized(void);
116
117/**
118 * Are we running in unobtrusive mode?
119 * @returns true/false.
120 */
121RTR3DECL(bool) RTR3InitIsUnobtrusive(void);
122#endif /* IN_RING3 */
123
124
125#ifdef IN_RING0
126/**
127 * Initializes the ring-0 driver runtime library.
128 *
129 * @returns iprt status code.
130 * @param fReserved Flags reserved for the future.
131 */
132RTR0DECL(int) RTR0Init(unsigned fReserved);
133
134/**
135 * Terminates the ring-0 driver runtime library.
136 */
137RTR0DECL(void) RTR0Term(void);
138
139/**
140 * Forcibily terminates the ring-0 driver runtime library.
141 *
142 * This should be used when statically linking the IPRT. Module using dynamic
143 * linking shall use RTR0Term. If you're not sure, use RTR0Term!
144 */
145RTR0DECL(void) RTR0TermForced(void);
146#endif
147
148#ifdef IN_RC
149/**
150 * Initializes the raw-mode context runtime library.
151 *
152 * @returns iprt status code.
153 *
154 * @param u64ProgramStartNanoTS The startup timestamp.
155 */
156RTRCDECL(int) RTRCInit(uint64_t u64ProgramStartNanoTS);
157
158/**
159 * Terminates the raw-mode context runtime library.
160 */
161RTRCDECL(void) RTRCTerm(void);
162#endif
163
164
165/**
166 * Termination reason.
167 */
168typedef enum RTTERMREASON
169{
170 /** Normal exit. iStatus contains the exit code. */
171 RTTERMREASON_EXIT = 1,
172 /** Any abnormal exit. iStatus is 0 and has no meaning. */
173 RTTERMREASON_ABEND,
174 /** Killed by a signal. The iStatus contains the signal number. */
175 RTTERMREASON_SIGNAL,
176 /** The IPRT module is being unloaded. iStatus is 0 and has no meaning. */
177 RTTERMREASON_UNLOAD
178} RTTERMREASON;
179
180/** Whether lazy clean up is Okay or not.
181 * When the process is exiting, it is a waste of time to for instance free heap
182 * memory or close open files. OTOH, when the runtime is unloaded from the
183 * process, it is important to release absolutely all resources to prevent
184 * resource leaks. */
185#define RTTERMREASON_IS_LAZY_CLEANUP_OK(enmReason) ((enmReason) != RTTERMREASON_UNLOAD)
186
187
188/**
189 * IPRT termination callback function.
190 *
191 * @param enmReason The cause of the termination.
192 * @param iStatus The meaning of this depends on enmReason.
193 * @param pvUser User argument passed to RTTermRegisterCallback.
194 */
195typedef DECLCALLBACK(void) FNRTTERMCALLBACK(RTTERMREASON enmReason, int32_t iStatus, void *pvUser);
196/** Pointer to an IPRT termination callback function. */
197typedef FNRTTERMCALLBACK *PFNRTTERMCALLBACK;
198
199
200/**
201 * Registers a termination callback.
202 *
203 * This is intended for performing clean up during IPRT termination. Frequently
204 * paired with lazy initialization thru RTOnce.
205 *
206 * The callbacks are called in LIFO order.
207 *
208 * @returns IPRT status code.
209 *
210 * @param pfnCallback The callback function.
211 * @param pvUser The user argument for the callback.
212 *
213 * @remarks May need to acquire a fast mutex or critical section, so use with
214 * some care in ring-0 context.
215 *
216 * @remarks Be very careful using this from code that may be unloaded before
217 * IPRT terminates. Unlike some atexit and on_exit implementations,
218 * IPRT will not automatically unregister callbacks when a module gets
219 * unloaded.
220 */
221RTDECL(int) RTTermRegisterCallback(PFNRTTERMCALLBACK pfnCallback, void *pvUser);
222
223/**
224 * Deregister a termination callback.
225 *
226 * @returns VINF_SUCCESS if found, VERR_NOT_FOUND if the callback/pvUser pair
227 * wasn't found.
228 *
229 * @param pfnCallback The callback function.
230 * @param pvUser The user argument for the callback.
231 */
232RTDECL(int) RTTermDeregisterCallback(PFNRTTERMCALLBACK pfnCallback, void *pvUser);
233
234/**
235 * Runs the termination callback queue.
236 *
237 * Normally called by an internal IPRT termination function, but may also be
238 * called by external code immediately prior to terminating IPRT if it is in a
239 * better position to state the termination reason and/or status.
240 *
241 * @param enmReason The reason why it's called.
242 * @param iStatus The associated exit status or signal number.
243 */
244RTDECL(void) RTTermRunCallbacks(RTTERMREASON enmReason, int32_t iStatus);
245
246/** @} */
247
248/** @} */
249
250RT_C_DECLS_END
251
252
253#endif
254
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