VirtualBox

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

Last change on this file since 331 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.5 KB
Line 
1/* $Id: init.cpp 1 1970-01-01 00:00:00Z vboxsync $ */
2/** @file
3 * InnoTek Portable Runtime - Init Ring-3.
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22
23
24/*******************************************************************************
25* Header Files *
26*******************************************************************************/
27#define LOG_GROUP RTLOGGROUP_DEFAULT
28#ifdef __WIN__
29# include <process.h>
30#else
31# include <unistd.h>
32#endif
33
34#include <iprt/runtime.h>
35#include <iprt/path.h>
36#include <iprt/assert.h>
37#include <iprt/log.h>
38#include <iprt/time.h>
39#include <iprt/err.h>
40#include <iprt/string.h>
41#include <iprt/param.h>
42#ifndef IN_GUEST
43# include <iprt/file.h>
44# include <VBox/sup.h>
45# include <stdlib.h>
46#endif
47#include "internal/path.h"
48#include "internal/process.h"
49#include "internal/thread.h"
50#include "internal/thread.h"
51#include "internal/time.h"
52
53
54/*******************************************************************************
55* Global Variables *
56*******************************************************************************/
57/** Program path.
58 * The size is hardcoded, so we'll have to check for overflow when setting it
59 * since some hosts might support longer paths.
60 * @internal
61 */
62char g_szrtProgramPath[RTPATH_MAX];
63
64/**
65 * Program start nanosecond TS.
66 */
67uint64_t g_u64ProgramStartNanoTS;
68
69/**
70 * Program start millisecond TS.
71 */
72uint64_t g_u64ProgramStartMilliTS;
73
74/**
75 * The process identifier of the running process.
76 */
77RTPROCESS g_ProcessSelf = NIL_RTPROCESS;
78
79/**
80 * The current process priority.
81 */
82RTPROCPRIORITY g_enmProcessPriority = RTPROCPRIORITY_DEFAULT;
83
84
85/**
86 * Initalizes the runtime library.
87 *
88 * @returns iprt status code.
89 *
90 * @param fInitSUPLib Set if SUPInit() shall be called during init (default).
91 * Clear if not to call it.
92 * @param cbReserve The number of bytes of contiguous memory that should be reserved by
93 * the runtime / support library.
94 * Set this to 0 if no reservation is required. (default)
95 * Set this to ~0 if the maximum amount supported by the VM is to be
96 * attempted reserved, or the maximum available.
97 * This argument only applies if fInitSUPLib is true and we're in ring-3 HC.
98 */
99RTR3DECL(int) RTR3Init(bool fInitSUPLib, size_t cbReserve)
100{
101 /* no entry log flow, because prefixes and thread may freak out. */
102
103#ifndef IN_GUEST
104# ifdef VBOX
105 /*
106 * This MUST be done as the very first thing, before any file is opened.
107 * The log is opened on demand, but the first log entries may be caused
108 * by rtThreadInit() below.
109 */
110 const char *pszDisableHostCache = getenv("VBOX_DISABLE_HOST_DISK_CACHE");
111 if ( pszDisableHostCache != NULL
112 && strlen(pszDisableHostCache) > 0
113 && strcmp(pszDisableHostCache, "0") != 0)
114 {
115 RTFileSetForceFlags(RTFILE_O_WRITE, RTFILE_O_WRITE_THROUGH, 0);
116 RTFileSetForceFlags(RTFILE_O_READWRITE, RTFILE_O_WRITE_THROUGH, 0);
117 }
118# endif /* VBOX */
119#endif /* !IN_GUEST */
120
121 /*
122 * Thread Thread database and adopt the caller thread as 'main'.
123 * This must be done before everything else or else we'll call into threading
124 * without having initialized TLS entries and suchlike.
125 */
126 int rc = rtThreadInit();
127 if (RT_FAILURE(rc))
128 {
129 AssertMsgFailed(("Failed to get executable directory path, rc=%d!\n", rc));
130 return rc;
131 }
132
133#ifndef IN_GUEST
134 if (fInitSUPLib)
135 {
136 /*
137 * Init GIP first.
138 * (The more time for updates before real use, the better.)
139 */
140 SUPInit(NULL, cbReserve);
141 }
142#endif
143
144 /*
145 * Init the program start TSes.
146 */
147 g_u64ProgramStartNanoTS = RTTimeNanoTS();
148 g_u64ProgramStartMilliTS = RTTimeMilliTS();
149
150#ifndef IN_GUEST
151 /*
152 * The threading is initialized we can safely sleep a bit if GIP
153 * needs some time to update itself updating.
154 */
155 if (fInitSUPLib && g_pSUPGlobalInfoPage)
156 {
157 RTThreadSleep(20);
158 RTTimeNanoTS();
159 }
160#endif
161
162 /*
163 * Get the executable path.
164 *
165 * We're also checking the depth here since we'll be
166 * appending filenames to the executable path. Currently
167 * we assume 16 bytes are what we need.
168 */
169 char szPath[RTPATH_MAX - 16];
170 rc = RTPathProgram(szPath, sizeof(szPath));
171 if (RT_FAILURE(rc))
172 {
173 AssertMsgFailed(("Failed to get executable directory path, rc=%d!\n", rc));
174 return rc;
175 }
176
177 /*
178 * The Process ID.
179 */
180#ifdef _MSC_VER
181 g_ProcessSelf = _getpid(); /* crappy ansi compiler */
182#else
183 g_ProcessSelf = getpid();
184#endif
185
186 /*
187 * More stuff to come.
188 */
189
190 LogFlow(("RTR3Init: returns VINF_SUCCESS\n"));
191 return VINF_SUCCESS;
192}
193
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