VirtualBox

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

Last change on this file since 49907 was 48681, checked in by vboxsync, 11 years ago

Main,IPRT: Added RTR3INIT_FLAGS_UTF8_ARGV so VBoxExtPackHelperApp can stop IPRT from converting UTF-8 argument strings to UTF-8 again as ANSI. Fixes #6963.

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