adding tests to the semdiff test suite
[hiphop-php.git] / hphp / hhvm / process-init.cpp
blob3e6d0ceea3b9da9ac7312096053ef414bb058a8b
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/compiler/option.h"
19 #include "hphp/runtime/vm/jit/fixup.h"
20 #include "hphp/runtime/vm/jit/mcgen.h"
21 #include "hphp/runtime/vm/jit/prof-data.h"
22 #include "hphp/runtime/vm/jit/translator.h"
24 #include "hphp/runtime/vm/bytecode.h"
25 #include "hphp/runtime/vm/repo.h"
26 #include "hphp/runtime/vm/runtime.h"
27 #include "hphp/runtime/vm/unit.h"
29 #include "hphp/runtime/base/execution-context.h"
30 #include "hphp/runtime/base/program-functions.h"
31 #include "hphp/runtime/base/rds.h"
32 #include "hphp/runtime/base/runtime-option.h"
33 #include "hphp/runtime/base/unit-cache.h"
35 #include "hphp/system/systemlib.h"
37 #include "hphp/util/build-info.h"
38 #include "hphp/util/logger.h"
40 #include <folly/portability/Libgen.h>
42 #include <string>
44 namespace HPHP {
46 ///////////////////////////////////////////////////////////////////////////////
48 #define STRINGIZE_CLASS_NAME(cls) #cls
49 #define pinitSentinel __pinitSentinel
50 #define resource __resource
52 #define SYSTEM_CLASS_STRING(cls) \
53 const StaticString s_##cls(STRINGIZE_CLASS_NAME(cls));
54 SYSTEMLIB_CLASSES(SYSTEM_CLASS_STRING)
56 #undef resource
57 #undef pinitSentinel
58 #undef STRINGIZE_CLASS_NAME
60 namespace {
61 const StaticString s_Throwable("\\__SystemLib\\Throwable");
62 const StaticString s_BaseException("\\__SystemLib\\BaseException");
63 const StaticString s_Error("\\__SystemLib\\Error");
64 const StaticString s_ArithmeticError("\\__SystemLib\\ArithmeticError");
65 const StaticString s_ArgumentCountError("\\__SystemLib\\ArgumentCountError");
66 const StaticString s_AssertionError("\\__SystemLib\\AssertionError");
67 const StaticString s_DivisionByZeroError("\\__SystemLib\\DivisionByZeroError");
68 const StaticString s_ParseError("\\__SystemLib\\ParseError");
69 const StaticString s_TypeError("\\__SystemLib\\TypeError");
72 void tweak_variant_dtors();
73 void ProcessInit() {
74 // Save the current options, and set things up so that
75 // systemlib.php can be read from and stored in the
76 // normal repo.
77 int db = RuntimeOption::EvalDumpBytecode;
78 bool rp = RuntimeOption::AlwaysUseRelativePath;
79 bool sf = RuntimeOption::SafeFileAccess;
80 bool ah = RuntimeOption::EvalAllowHhas;
81 bool wp = Option::WholeProgram;
82 RuntimeOption::EvalDumpBytecode &= ~1;
83 RuntimeOption::AlwaysUseRelativePath = false;
84 RuntimeOption::SafeFileAccess = false;
85 RuntimeOption::EvalAllowHhas = true;
86 Option::WholeProgram = false;
88 if (RuntimeOption::RepoAuthoritative) {
89 LitstrTable::init();
90 Repo::get().loadGlobalData();
93 jit::mcgen::processInit();
94 jit::processInitProfData();
96 rds::requestInit();
97 std::string hhas;
98 auto const slib = get_systemlib(&hhas);
100 if (slib.empty()) {
101 // Die a horrible death.
102 Logger::Error("Unable to find/load systemlib.php, check /proc is mounted"
103 " or export HHVM_SYSTEMLIB to your ENV");
104 _exit(1);
107 // Save this in case the debugger needs it. Once we know if this
108 // process does not have debugger support, we'll clear it.
109 SystemLib::s_source = slib;
111 SystemLib::s_unit = compile_systemlib_string(slib.c_str(), slib.size(),
112 "systemlib.php");
114 const StringData* msg;
115 int line;
116 if (SystemLib::s_unit->compileTimeFatal(msg, line)) {
117 Logger::Error("An error has been introduced into the systemlib, "
118 "but we cannot give you a file and line number right now.");
119 Logger::Error("Check all of your changes to hphp/system/php");
120 Logger::Error("HipHop Parse Error: %s", msg->data());
121 _exit(1);
124 if (!hhas.empty()) {
125 SystemLib::s_hhas_unit = compile_systemlib_string(
126 hhas.c_str(), hhas.size(), "systemlib.hhas");
127 if (SystemLib::s_hhas_unit->compileTimeFatal(msg, line)) {
128 Logger::Error("An error has been introduced in the hhas portion of "
129 "systemlib.");
130 Logger::Error("Check all of your changes to hhas files in "
131 "hphp/system/php");
132 Logger::Error("HipHop Parse Error: %s", msg->data());
133 _exit(1);
137 // Load the systemlib unit to build the Class objects
138 SystemLib::s_unit->merge();
139 if (SystemLib::s_hhas_unit) {
140 SystemLib::s_hhas_unit->merge();
143 SystemLib::s_nullFunc =
144 Unit::lookupFunc(makeStaticString("__SystemLib\\__86null"));
146 #define INIT_SYSTEMLIB_CLASS_FIELD(cls) \
148 Class *cls = NamedEntity::get(s_##cls.get())->clsList(); \
149 assert(cls); \
150 SystemLib::s_##cls##Class = cls; \
153 INIT_SYSTEMLIB_CLASS_FIELD(Throwable)
154 INIT_SYSTEMLIB_CLASS_FIELD(BaseException)
155 INIT_SYSTEMLIB_CLASS_FIELD(Error)
156 INIT_SYSTEMLIB_CLASS_FIELD(ArithmeticError)
157 INIT_SYSTEMLIB_CLASS_FIELD(ArgumentCountError)
158 INIT_SYSTEMLIB_CLASS_FIELD(AssertionError)
159 INIT_SYSTEMLIB_CLASS_FIELD(DivisionByZeroError)
160 INIT_SYSTEMLIB_CLASS_FIELD(ParseError)
161 INIT_SYSTEMLIB_CLASS_FIELD(TypeError)
163 // Stash a pointer to the VM Classes for stdclass, Exception,
164 // pinitSentinel and resource
165 SYSTEMLIB_CLASSES(INIT_SYSTEMLIB_CLASS_FIELD)
167 #undef INIT_SYSTEMLIB_CLASS_FIELD
169 Stack::ValidateStackSize();
170 SystemLib::s_inited = true;
172 RuntimeOption::AlwaysUseRelativePath = rp;
173 RuntimeOption::SafeFileAccess = sf;
174 RuntimeOption::EvalDumpBytecode = db;
175 RuntimeOption::EvalAllowHhas = ah;
176 Option::WholeProgram = wp;
178 tweak_variant_dtors();
181 ///////////////////////////////////////////////////////////////////////////////