VirtualBox

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

Last change on this file since 3672 was 3672, checked in by vboxsync, 17 years ago

RT_OS_* and RT_ARCH_* for Runtime/ and Support/

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.7 KB
Line 
1/* $Id: init.cpp 3672 2007-07-17 12:39:30Z vboxsync $ */
2/** @file
3 * innotek Portable Runtime - Init Ring-3.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek 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 RT_OS_WINDOWS
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 microsecond TS.
71 */
72uint64_t g_u64ProgramStartMicroTS;
73
74/**
75 * Program start millisecond TS.
76 */
77uint64_t g_u64ProgramStartMilliTS;
78
79/**
80 * The process identifier of the running process.
81 */
82RTPROCESS g_ProcessSelf = NIL_RTPROCESS;
83
84/**
85 * The current process priority.
86 */
87RTPROCPRIORITY g_enmProcessPriority = RTPROCPRIORITY_DEFAULT;
88
89
90/**
91 * Initalizes the runtime library.
92 *
93 * @returns iprt status code.
94 *
95 * @param fInitSUPLib Set if SUPInit() shall be called during init (default).
96 * Clear if not to call it.
97 * @param cbReserve The number of bytes of contiguous memory that should be reserved by
98 * the runtime / support library.
99 * Set this to 0 if no reservation is required. (default)
100 * Set this to ~0 if the maximum amount supported by the VM is to be
101 * attempted reserved, or the maximum available.
102 * This argument only applies if fInitSUPLib is true and we're in ring-3 HC.
103 */
104RTR3DECL(int) RTR3Init(bool fInitSUPLib, size_t cbReserve)
105{
106 /* no entry log flow, because prefixes and thread may freak out. */
107
108#ifndef IN_GUEST
109# ifdef VBOX
110 /*
111 * This MUST be done as the very first thing, before any file is opened.
112 * The log is opened on demand, but the first log entries may be caused
113 * by rtThreadInit() below.
114 */
115 const char *pszDisableHostCache = getenv("VBOX_DISABLE_HOST_DISK_CACHE");
116 if ( pszDisableHostCache != NULL
117 && strlen(pszDisableHostCache) > 0
118 && strcmp(pszDisableHostCache, "0") != 0)
119 {
120 RTFileSetForceFlags(RTFILE_O_WRITE, RTFILE_O_WRITE_THROUGH, 0);
121 RTFileSetForceFlags(RTFILE_O_READWRITE, RTFILE_O_WRITE_THROUGH, 0);
122 }
123# endif /* VBOX */
124#endif /* !IN_GUEST */
125
126 /*
127 * Thread Thread database and adopt the caller thread as 'main'.
128 * This must be done before everything else or else we'll call into threading
129 * without having initialized TLS entries and suchlike.
130 */
131 int rc = rtThreadInit();
132 if (RT_FAILURE(rc))
133 {
134 AssertMsgFailed(("Failed to get executable directory path, rc=%d!\n", rc));
135 return rc;
136 }
137
138#ifndef IN_GUEST
139 if (fInitSUPLib)
140 {
141 /*
142 * Init GIP first.
143 * (The more time for updates before real use, the better.)
144 */
145 SUPInit(NULL, cbReserve);
146 }
147#endif
148
149 /*
150 * Init the program start TSes.
151 */
152 g_u64ProgramStartNanoTS = RTTimeNanoTS();
153 g_u64ProgramStartMicroTS = g_u64ProgramStartNanoTS / 1000;
154 g_u64ProgramStartMilliTS = g_u64ProgramStartNanoTS / 1000000;
155
156#ifndef IN_GUEST
157 /*
158 * The threading is initialized we can safely sleep a bit if GIP
159 * needs some time to update itself updating.
160 */
161 if (fInitSUPLib && g_pSUPGlobalInfoPage)
162 {
163 RTThreadSleep(20);
164 RTTimeNanoTS();
165 }
166#endif
167
168 /*
169 * Get the executable path.
170 *
171 * We're also checking the depth here since we'll be
172 * appending filenames to the executable path. Currently
173 * we assume 16 bytes are what we need.
174 */
175 char szPath[RTPATH_MAX - 16];
176 rc = RTPathProgram(szPath, sizeof(szPath));
177 if (RT_FAILURE(rc))
178 {
179 AssertMsgFailed(("Failed to get executable directory path, rc=%d!\n", rc));
180 return rc;
181 }
182
183 /*
184 * The Process ID.
185 */
186#ifdef _MSC_VER
187 g_ProcessSelf = _getpid(); /* crappy ansi compiler */
188#else
189 g_ProcessSelf = getpid();
190#endif
191
192 /*
193 * More stuff to come.
194 */
195
196 LogFlow(("RTR3Init: returns VINF_SUCCESS\n"));
197 return VINF_SUCCESS;
198}
199
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