VirtualBox

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

Last change on this file since 44528 was 44528, checked in by vboxsync, 12 years ago

header (C) fixes

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