VirtualBox

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

Last change on this file since 47988 was 46583, checked in by vboxsync, 11 years ago

doc fix

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