VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/init.cpp@ 92613

Last change on this file since 92613 was 92613, checked in by vboxsync, 3 years ago

SUP,IPRT,++: Adding SUPSECMAIN_FLAGS_DRIVERLESS_IEM_ALLOWED and SUPR3INIT_F_DRIVERLESS_NEM_FALLBACK to SUPLib and RTR3INIT_FLAGS_TRY_SUPLIB to RTR3Init*, the latter probably reflects the actual state there a lot better. Currently only the TRY_SUPLIB option works, the other two aren't really implemented in SUPLib yet. bugref:10138

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 21.2 KB
Line 
1/* $Id: init.cpp 92613 2021-11-26 21:53:47Z vboxsync $ */
2/** @file
3 * IPRT - Init Ring-3.
4 */
5
6/*
7 * Copyright (C) 2006-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#define LOG_GROUP RTLOGGROUP_DEFAULT
32#include <iprt/types.h> /* darwin: UINT32_C and others. */
33
34#ifdef RT_OS_WINDOWS
35# include <process.h>
36# include <iprt/win/windows.h>
37#else
38# include <unistd.h>
39# ifndef RT_OS_OS2
40# include <pthread.h>
41# include <signal.h>
42# include <errno.h>
43# define IPRT_USE_SIG_CHILD_DUMMY
44# endif
45#endif
46#ifdef RT_OS_OS2
47# include <InnoTekLIBC/fork.h>
48# define INCL_DOSMISC
49# include <os2.h>
50#endif
51#include <locale.h>
52
53#include <iprt/initterm.h>
54#include <iprt/asm.h>
55#include <iprt/assert.h>
56#include <iprt/errcore.h>
57#include <iprt/log.h>
58#include <iprt/mem.h>
59#include <iprt/path.h>
60#include <iprt/time.h>
61#include <iprt/string.h>
62#include <iprt/param.h>
63#ifdef RT_OS_WINDOWS
64# include <iprt/utf16.h>
65#endif
66#if !defined(IN_GUEST) && !defined(RT_NO_GIP)
67# include <iprt/file.h>
68# include <VBox/sup.h>
69#endif
70#include <stdlib.h>
71
72#include "init.h"
73#include "internal/alignmentchecks.h"
74#include "internal/path.h"
75#include "internal/process.h"
76#include "internal/thread.h"
77#include "internal/time.h"
78
79
80/*********************************************************************************************************************************
81* Global Variables *
82*********************************************************************************************************************************/
83/** The number of calls to RTR3Init*. */
84static int32_t volatile g_cUsers = 0;
85/** Whether we're currently initializing the IPRT. */
86static bool volatile g_fInitializing = false;
87
88/** The process path.
89 * This is used by RTPathExecDir and RTProcGetExecutablePath and set by rtProcInitName. */
90DECL_HIDDEN_DATA(char) g_szrtProcExePath[RTPATH_MAX];
91/** The length of g_szrtProcExePath. */
92DECL_HIDDEN_DATA(size_t) g_cchrtProcExePath;
93/** The length of directory path component of g_szrtProcExePath. */
94DECL_HIDDEN_DATA(size_t) g_cchrtProcDir;
95/** The offset of the process name into g_szrtProcExePath. */
96DECL_HIDDEN_DATA(size_t) g_offrtProcName;
97
98/** The IPRT init flags. */
99static uint32_t g_fInitFlags;
100
101/** The argument count of the program. */
102static int g_crtArgs = -1;
103/** The arguments of the program (UTF-8). This is "leaked". */
104static char ** g_papszrtArgs;
105/** The original argument vector of the program. */
106static char ** g_papszrtOrgArgs;
107
108/**
109 * Program start nanosecond TS.
110 */
111DECL_HIDDEN_DATA(uint64_t) g_u64ProgramStartNanoTS;
112
113/**
114 * The process identifier of the running process.
115 */
116DECL_HIDDEN_DATA(RTPROCESS) g_ProcessSelf = NIL_RTPROCESS;
117
118/**
119 * The current process priority.
120 */
121DECL_HIDDEN_DATA(RTPROCPRIORITY) g_enmProcessPriority = RTPROCPRIORITY_DEFAULT;
122
123/**
124 * Set if the atexit callback has been called, i.e. indicating
125 * that the process is terminating.
126 */
127DECL_HIDDEN_DATA(bool volatile) g_frtAtExitCalled = false;
128
129#ifdef IPRT_WITH_ALIGNMENT_CHECKS
130/**
131 * Whether alignment checks are enabled.
132 * This is set if the environment variable IPRT_ALIGNMENT_CHECKS is 1.
133 */
134RTDATADECL(bool) g_fRTAlignmentChecks = false;
135#endif
136
137
138#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD) || defined(RT_OS_HAIKU) \
139 || defined(RT_OS_LINUX) || defined(RT_OS_OS2) || defined(RT_OS_SOLARIS) /** @todo add host init hooks everywhere. */
140/* Stubs */
141DECLHIDDEN(int) rtR3InitNativeFirst(uint32_t fFlags) { RT_NOREF_PV(fFlags); return VINF_SUCCESS; }
142DECLHIDDEN(int) rtR3InitNativeFinal(uint32_t fFlags) { RT_NOREF_PV(fFlags); return VINF_SUCCESS; }
143DECLHIDDEN(void) rtR3InitNativeObtrusive(uint32_t fFlags) { RT_NOREF_PV(fFlags); }
144#endif
145
146
147/**
148 * atexit callback.
149 *
150 * This makes sure any loggers are flushed and will later also work the
151 * termination callback chain.
152 */
153static void rtR3ExitCallback(void) RT_NOTHROW_DEF
154{
155 ASMAtomicWriteBool(&g_frtAtExitCalled, true);
156
157 if (g_cUsers > 0)
158 {
159 PRTLOGGER pLogger = RTLogGetDefaultInstance();
160 if (pLogger)
161 RTLogFlush(pLogger);
162
163 pLogger = RTLogRelGetDefaultInstance();
164 if (pLogger)
165 RTLogFlush(pLogger);
166 }
167}
168
169
170#ifndef RT_OS_WINDOWS
171/**
172 * Fork callback, child context.
173 */
174static void rtR3ForkChildCallback(void)
175{
176 g_ProcessSelf = getpid();
177}
178#endif /* RT_OS_WINDOWS */
179
180#ifdef RT_OS_OS2
181/** Fork completion callback for OS/2. Only called in the child. */
182static void rtR3ForkOs2ChildCompletionCallback(void *pvArg, int rc, __LIBC_FORKCTX enmCtx)
183{
184 Assert(enmCtx == __LIBC_FORK_CTX_CHILD); NOREF(enmCtx);
185 NOREF(pvArg);
186
187 if (!rc)
188 rtR3ForkChildCallback();
189}
190
191/** Low-level fork callback for OS/2. */
192int rtR3ForkOs2Child(__LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation)
193{
194 if (enmOperation == __LIBC_FORK_OP_EXEC_CHILD)
195 return pForkHandle->pfnCompletionCallback(pForkHandle, rtR3ForkOs2ChildCompletionCallback, NULL, __LIBC_FORK_CTX_CHILD);
196 return 0;
197}
198
199# define static static volatile /** @todo _FORK_CHILD1 causes unresolved externals in optimized builds. Fix macro. */
200_FORK_CHILD1(0, rtR3ForkOs2Child);
201# undef static
202#endif /* RT_OS_OS2 */
203
204
205
206/**
207 * Internal worker which initializes or re-initializes the
208 * program path, name and directory globals.
209 *
210 * @returns IPRT status code.
211 * @param pszProgramPath The program path, NULL if not specified.
212 */
213static int rtR3InitProgramPath(const char *pszProgramPath)
214{
215 /*
216 * We're reserving 32 bytes here for file names as what not.
217 */
218 if (!pszProgramPath)
219 {
220 int rc = rtProcInitExePath(g_szrtProcExePath, sizeof(g_szrtProcExePath) - 32);
221 if (RT_FAILURE(rc))
222 return rc;
223 }
224 else
225 {
226 size_t cch = strlen(pszProgramPath);
227 Assert(cch > 1);
228 AssertMsgReturn(cch < sizeof(g_szrtProcExePath) - 32, ("%zu\n", cch), VERR_BUFFER_OVERFLOW);
229 memcpy(g_szrtProcExePath, pszProgramPath, cch + 1);
230 }
231
232 /*
233 * Parse the name.
234 */
235 ssize_t offName;
236 g_cchrtProcExePath = RTPathParseSimple(g_szrtProcExePath, &g_cchrtProcDir, &offName, NULL);
237 g_offrtProcName = offName;
238 return VINF_SUCCESS;
239}
240
241
242/**
243 * Internal worker which initializes or re-initializes the
244 * program path, name and directory globals.
245 *
246 * @returns IPRT status code.
247 * @param fFlags Flags, see RTR3INIT_XXX.
248 * @param cArgs Pointer to the argument count.
249 * @param ppapszArgs Pointer to the argument vector pointer. NULL
250 * allowed if @a cArgs is 0.
251 */
252static int rtR3InitArgv(uint32_t fFlags, int cArgs, char ***ppapszArgs)
253{
254 NOREF(fFlags);
255 if (cArgs)
256 {
257 AssertPtr(ppapszArgs);
258 AssertPtr(*ppapszArgs);
259 char **papszOrgArgs = *ppapszArgs;
260
261 /*
262 * Normally we should only be asked to convert arguments once. If we
263 * are though, it should be the already convered arguments.
264 */
265 if (g_crtArgs != -1)
266 {
267 AssertReturn( g_crtArgs == cArgs
268 && g_papszrtArgs == papszOrgArgs,
269 VERR_WRONG_ORDER); /* only init once! */
270 return VINF_SUCCESS;
271 }
272
273 if (!(fFlags & RTR3INIT_FLAGS_UTF8_ARGV))
274 {
275 /*
276 * Convert the arguments.
277 */
278 char **papszArgs = (char **)RTMemAllocZ((cArgs + 1) * sizeof(char *));
279 if (!papszArgs)
280 return VERR_NO_MEMORY;
281
282#ifdef RT_OS_WINDOWS
283 /* HACK ALERT! Try convert from unicode versions if possible.
284 Unfortunately for us, __wargv is only initialized if we have a
285 unicode main function. So, we have to use CommandLineToArgvW to get
286 something similar. It should do the same conversion... :-) */
287 /** @todo Replace this CommandLineToArgvW call with a call into
288 * getoptargv.cpp so we don't depend on shell32 and an API not present
289 * in NT 3.1. */
290 int cArgsW = -1;
291 PWSTR *papwszArgs = NULL;
292 if ( papszOrgArgs == __argv
293 && cArgs == __argc
294 && (papwszArgs = CommandLineToArgvW(GetCommandLineW(), &cArgsW)) != NULL )
295 {
296 AssertMsg(cArgsW == cArgs, ("%d vs %d\n", cArgsW, cArgs));
297 for (int i = 0; i < cArgs; i++)
298 {
299 int rc = RTUtf16ToUtf8Tag(papwszArgs[i], &papszArgs[i], "will-leak:rtR3InitArgv");
300 if (RT_FAILURE(rc))
301 {
302 while (i--)
303 RTStrFree(papszArgs[i]);
304 RTMemFree(papszArgs);
305 LocalFree(papwszArgs);
306 return rc;
307 }
308 }
309 LocalFree(papwszArgs);
310 }
311 else
312#endif
313 {
314 for (int i = 0; i < cArgs; i++)
315 {
316 int rc = RTStrCurrentCPToUtf8(&papszArgs[i], papszOrgArgs[i]);
317 if (RT_FAILURE(rc))
318 {
319 while (i--)
320 RTStrFree(papszArgs[i]);
321 RTMemFree(papszArgs);
322 return rc;
323 }
324 }
325 }
326
327 papszArgs[cArgs] = NULL;
328
329 g_papszrtOrgArgs = papszOrgArgs;
330 g_papszrtArgs = papszArgs;
331 g_crtArgs = cArgs;
332
333 *ppapszArgs = papszArgs;
334 }
335 else
336 {
337 /*
338 * The arguments are already UTF-8, no conversion needed.
339 */
340 g_papszrtOrgArgs = papszOrgArgs;
341 g_papszrtArgs = papszOrgArgs;
342 g_crtArgs = cArgs;
343 }
344 }
345
346 return VINF_SUCCESS;
347}
348
349
350#ifdef IPRT_USE_SIG_CHILD_DUMMY
351/**
352 * Dummy SIGCHILD handler.
353 *
354 * Assigned on rtR3Init only when SIGCHILD handler is set SIGIGN or SIGDEF to
355 * ensure waitpid works properly for the terminated processes.
356 */
357static void rtR3SigChildHandler(int iSignal)
358{
359 NOREF(iSignal);
360}
361#endif /* IPRT_USE_SIG_CHILD_DUMMY */
362
363
364/**
365 * rtR3Init worker.
366 */
367static int rtR3InitBody(uint32_t fFlags, int cArgs, char ***ppapszArgs, const char *pszProgramPath)
368{
369 /*
370 * Early native initialization.
371 */
372 int rc = rtR3InitNativeFirst(fFlags);
373 AssertMsgRCReturn(rc, ("rtR3InitNativeFirst failed with %Rrc\n", rc), rc);
374
375 /*
376 * Disable error popups.
377 */
378#if defined(RT_OS_OS2) /** @todo move to private code. */
379 DosError(FERR_DISABLEHARDERR);
380#endif
381
382 /*
383 * Init C runtime locale before we do anything that may end up converting
384 * paths or we'll end up using the "C" locale for path conversion.
385 */
386 setlocale(LC_CTYPE, "");
387
388 /*
389 * The Process ID.
390 */
391#ifdef _MSC_VER
392 g_ProcessSelf = _getpid(); /* crappy ansi compiler */
393#else
394 g_ProcessSelf = getpid();
395#endif
396
397 /*
398 * Save the init flags.
399 */
400 g_fInitFlags |= fFlags;
401
402#if !defined(IN_GUEST) && !defined(RT_NO_GIP)
403# ifdef VBOX
404 /*
405 * This MUST be done as the very first thing, before any file is opened.
406 * The log is opened on demand, but the first log entries may be caused
407 * by rtThreadInit() below.
408 */
409 const char *pszDisableHostCache = getenv("VBOX_DISABLE_HOST_DISK_CACHE");
410 if ( pszDisableHostCache != NULL
411 && *pszDisableHostCache
412 && strcmp(pszDisableHostCache, "0") != 0)
413 {
414 RTFileSetForceFlags(RTFILE_O_WRITE, RTFILE_O_WRITE_THROUGH, 0);
415 RTFileSetForceFlags(RTFILE_O_READWRITE, RTFILE_O_WRITE_THROUGH, 0);
416 }
417# endif /* VBOX */
418#endif /* !IN_GUEST && !RT_NO_GIP */
419
420 /*
421 * Thread Thread database and adopt the caller thread as 'main'.
422 * This must be done before everything else or else we'll call into threading
423 * without having initialized TLS entries and suchlike.
424 */
425 rc = rtThreadInit();
426 AssertMsgRCReturn(rc, ("Failed to initialize threads, rc=%Rrc!\n", rc), rc);
427
428 /*
429 * The executable path before SUPLib (windows requirement).
430 */
431 rc = rtR3InitProgramPath(pszProgramPath);
432 AssertLogRelMsgRCReturn(rc, ("Failed to get executable directory path, rc=%Rrc!\n", rc), rc);
433
434#if !defined(IN_GUEST) && !defined(RT_NO_GIP)
435 /*
436 * Initialize SUPLib here so the GIP can get going as early as possible
437 * (improves accuracy for the first client).
438 */
439 if (fFlags & (RTR3INIT_FLAGS_SUPLIB | RTR3INIT_FLAGS_TRY_SUPLIB))
440 {
441 rc = SUPR3InitEx( fFlags >> RTR3INIT_FLAGS_SUPLIB_SHIFT
442 ? fFlags >> RTR3INIT_FLAGS_SUPLIB_SHIFT : SUPR3INIT_F_UNRESTRICTED, NULL /*ppSession*/);
443 AssertMsgReturn(RT_SUCCESS(rc) || (fFlags & RTR3INIT_FLAGS_TRY_SUPLIB),
444 ("Failed to initialize the support library, rc=%Rrc!\n", rc), rc);
445 }
446#endif
447
448 /*
449 * Convert arguments.
450 */
451 rc = rtR3InitArgv(fFlags, cArgs, ppapszArgs);
452 AssertLogRelMsgRCReturn(rc, ("Failed to convert the arguments, rc=%Rrc!\n", rc), rc);
453
454#if !defined(IN_GUEST) && !defined(RT_NO_GIP)
455 /*
456 * The threading is initialized, so we can safely sleep a bit if GIP
457 * needs some time to start updating itself. Currently limited to
458 * the first mapping of GIP (u32TransactionId <= 4), quite possible we
459 * could just ditch this now.
460 */
461 /** @todo consider dropping this... */
462 PSUPGLOBALINFOPAGE pGip;
463 if ( (fFlags & (RTR3INIT_FLAGS_SUPLIB | RTR3INIT_FLAGS_TRY_SUPLIB))
464 && (pGip = g_pSUPGlobalInfoPage) != NULL
465 && pGip->u32Magic == SUPGLOBALINFOPAGE_MAGIC)
466 {
467 PSUPGIPCPU pGipCpu = SUPGetGipCpuPtr(pGip);
468 if ( pGipCpu
469 && pGipCpu->u32TransactionId <= 4)
470 {
471 RTThreadSleep(pGip->u32UpdateIntervalNS / RT_NS_1MS + 2);
472 RTTimeNanoTS();
473 }
474 }
475#endif
476
477 /*
478 * Init the program start timestamp TS.
479 * Do that here to be sure that the GIP time was properly updated the 1st time.
480 */
481 g_u64ProgramStartNanoTS = RTTimeNanoTS();
482
483 /*
484 * The remainder cannot easily be undone, so it has to go last.
485 */
486
487 /* Fork and exit callbacks. */
488#if !defined(RT_OS_WINDOWS) && !defined(RT_OS_OS2)
489 rc = pthread_atfork(NULL, NULL, rtR3ForkChildCallback);
490 AssertMsg(rc == 0, ("%d\n", rc));
491#endif
492 atexit(rtR3ExitCallback);
493
494#ifdef IPRT_USE_SIG_CHILD_DUMMY
495 /*
496 * SIGCHLD must not be ignored (that's default), otherwise posix compliant waitpid
497 * implementations won't work right.
498 */
499 for (;;)
500 {
501 struct sigaction saOld;
502 rc = sigaction(SIGCHLD, 0, &saOld); AssertMsg(rc == 0, ("%d/%d\n", rc, errno));
503 if ( rc != 0
504 || (saOld.sa_flags & SA_SIGINFO)
505 || ( saOld.sa_handler != SIG_IGN
506 && saOld.sa_handler != SIG_DFL)
507 )
508 break;
509
510 /* Try install dummy handler. */
511 struct sigaction saNew = saOld;
512 saNew.sa_flags = SA_NOCLDSTOP | SA_RESTART;
513 saNew.sa_handler = rtR3SigChildHandler;
514 rc = sigemptyset(&saNew.sa_mask); AssertMsg(rc == 0, ("%d/%d\n", rc, errno));
515 struct sigaction saOld2;
516 rc = sigaction(SIGCHLD, &saNew, &saOld2); AssertMsg(rc == 0, ("%d/%d\n", rc, errno));
517 if ( rc != 0
518 || ( saOld2.sa_handler == saOld.sa_handler
519 && !(saOld2.sa_flags & SA_SIGINFO))
520 )
521 break;
522
523 /* Race during dynamic load, restore and try again... */
524 sigaction(SIGCHLD, &saOld2, NULL);
525 RTThreadYield();
526 }
527#endif /* IPRT_USE_SIG_CHILD_DUMMY */
528
529#ifdef IPRT_WITH_ALIGNMENT_CHECKS
530 /*
531 * Enable alignment checks.
532 */
533 const char *pszAlignmentChecks = getenv("IPRT_ALIGNMENT_CHECKS");
534 g_fRTAlignmentChecks = pszAlignmentChecks != NULL
535 && pszAlignmentChecks[0] == '1'
536 && pszAlignmentChecks[1] == '\0';
537 if (g_fRTAlignmentChecks)
538 IPRT_ALIGNMENT_CHECKS_ENABLE();
539#endif
540
541 /*
542 * Final native initialization.
543 */
544 rc = rtR3InitNativeFinal(fFlags);
545 AssertMsgRCReturn(rc, ("rtR3InitNativeFinal failed with %Rrc\n", rc), rc);
546
547 return VINF_SUCCESS;
548}
549
550
551/**
552 * Internal initialization worker.
553 *
554 * @returns IPRT status code.
555 * @param fFlags Flags, see RTR3INIT_XXX.
556 * @param cArgs Pointer to the argument count.
557 * @param ppapszArgs Pointer to the argument vector pointer. NULL
558 * allowed if @a cArgs is 0.
559 * @param pszProgramPath The program path. Pass NULL if we're to figure it
560 * out ourselves.
561 */
562static int rtR3Init(uint32_t fFlags, int cArgs, char ***ppapszArgs, const char *pszProgramPath)
563{
564 /* no entry log flow, because prefixes and thread may freak out. */
565 Assert(!(fFlags & ~RTR3INIT_FLAGS_VALID_MASK));
566 Assert(!(fFlags & RTR3INIT_FLAGS_DLL) || cArgs == 0);
567
568 /*
569 * Do reference counting, only initialize the first time around.
570 *
571 * We are ASSUMING that nobody will be able to race RTR3Init* calls when the
572 * first one, the real init, is running (second assertion).
573 */
574 int32_t cUsers = ASMAtomicIncS32(&g_cUsers);
575 if (cUsers != 1)
576 {
577 AssertMsg(cUsers > 1, ("%d\n", cUsers));
578 Assert(!g_fInitializing);
579
580#if !defined(IN_GUEST) && !defined(RT_NO_GIP)
581 /* Initialize the support library if requested. We've always ignored the
582 status code here for some reason, making the two flags same. */
583 if (fFlags & (RTR3INIT_FLAGS_SUPLIB | RTR3INIT_FLAGS_TRY_SUPLIB))
584 {
585 SUPR3InitEx( fFlags >> RTR3INIT_FLAGS_SUPLIB_SHIFT
586 ? fFlags >> RTR3INIT_FLAGS_SUPLIB_SHIFT : SUPR3INIT_F_UNRESTRICTED, NULL /*ppSession*/);
587 g_fInitFlags |= fFlags & (RTR3INIT_FLAGS_SUPLIB | RTR3INIT_FLAGS_TRY_SUPLIB | RTR3INIT_FLAGS_SUPLIB_MASK);
588 }
589#endif
590 g_fInitFlags |= fFlags & RTR3INIT_FLAGS_UTF8_ARGV;
591
592 if ( !(fFlags & RTR3INIT_FLAGS_UNOBTRUSIVE)
593 && (g_fInitFlags & RTR3INIT_FLAGS_UNOBTRUSIVE))
594 {
595 g_fInitFlags &= ~RTR3INIT_FLAGS_UNOBTRUSIVE;
596 g_fInitFlags |= fFlags & RTR3INIT_FLAGS_STANDALONE_APP;
597 rtR3InitNativeObtrusive(g_fInitFlags | fFlags);
598 rtThreadReInitObtrusive();
599 }
600 else
601 Assert(!(fFlags & RTR3INIT_FLAGS_STANDALONE_APP) || (g_fInitFlags & RTR3INIT_FLAGS_STANDALONE_APP));
602
603 int rc = VINF_SUCCESS;
604 if (pszProgramPath)
605 rc = rtR3InitProgramPath(pszProgramPath);
606 if (RT_SUCCESS(rc))
607 rc = rtR3InitArgv(fFlags, cArgs, ppapszArgs);
608 return rc;
609 }
610
611 /*
612 * Do the initialization.
613 */
614 ASMAtomicWriteBool(&g_fInitializing, true);
615 int rc = rtR3InitBody(fFlags, cArgs, ppapszArgs, pszProgramPath);
616 ASMAtomicWriteBool(&g_fInitializing, false);
617 if (RT_FAILURE(rc))
618 {
619 /* failure */
620 ASMAtomicDecS32(&g_cUsers);
621 return rc;
622 }
623
624 /* success */
625 LogFlow(("rtR3Init: returns VINF_SUCCESS\n"));
626 return VINF_SUCCESS;
627}
628
629
630RTR3DECL(int) RTR3InitExe(int cArgs, char ***ppapszArgs, uint32_t fFlags)
631{
632 Assert(!(fFlags & RTR3INIT_FLAGS_DLL));
633 return rtR3Init(fFlags, cArgs, ppapszArgs, NULL);
634}
635
636
637RTR3DECL(int) RTR3InitExeNoArguments(uint32_t fFlags)
638{
639 Assert(!(fFlags & RTR3INIT_FLAGS_DLL));
640 return rtR3Init(fFlags, 0, NULL, NULL);
641}
642
643
644RTR3DECL(int) RTR3InitDll(uint32_t fFlags)
645{
646 Assert(!(fFlags & RTR3INIT_FLAGS_DLL));
647 return rtR3Init(fFlags | RTR3INIT_FLAGS_DLL, 0, NULL, NULL);
648}
649
650
651RTR3DECL(int) RTR3InitEx(uint32_t iVersion, uint32_t fFlags, int cArgs, char ***ppapszArgs, const char *pszProgramPath)
652{
653 AssertReturn(iVersion == RTR3INIT_VER_CUR, VERR_NOT_SUPPORTED);
654 return rtR3Init(fFlags, cArgs, ppapszArgs, pszProgramPath);
655}
656
657
658RTR3DECL(bool) RTR3InitIsInitialized(void)
659{
660 return g_cUsers >= 1 && !g_fInitializing;
661}
662
663
664RTR3DECL(bool) RTR3InitIsUnobtrusive(void)
665{
666 return RT_BOOL(g_fInitFlags & RTR3INIT_FLAGS_UNOBTRUSIVE);
667}
668
669
670#if 0 /** @todo implement RTR3Term. */
671RTR3DECL(void) RTR3Term(void)
672{
673}
674#endif
675
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette