Remove positive is_typechecker guards
[hiphop-php.git] / hphp / hhvm / process-init.cpp
blob43f38d16eb4e9d11ff0ab6ff1bf78f83483a43e8
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/runtime/vm/bytecode.h"
18 #include "hphp/runtime/vm/repo-file.h"
19 #include "hphp/runtime/vm/repo-global-data.h"
20 #include "hphp/runtime/vm/runtime-compiler.h"
21 #include "hphp/runtime/vm/unit.h"
23 #include "hphp/runtime/base/execution-context.h"
24 #include "hphp/runtime/base/program-functions.h"
25 #include "hphp/runtime/base/rds.h"
26 #include "hphp/runtime/base/runtime-option.h"
27 #include "hphp/runtime/base/unit-cache.h"
29 #include "hphp/system/systemlib.h"
31 #include "hphp/util/build-info.h"
32 #include "hphp/util/logger.h"
34 #include <folly/portability/Libgen.h>
36 #include <string>
38 namespace HPHP {
40 ///////////////////////////////////////////////////////////////////////////////
42 #define STRINGIZE_CLASS_NAME(cls) #cls
43 #define pinitSentinel __pinitSentinel
44 #define resource __resource
46 #define SYSTEM_CLASS_STRING(cls) \
47 const StaticString s_##cls(STRINGIZE_CLASS_NAME(cls));
48 SYSTEMLIB_CLASSES(SYSTEM_CLASS_STRING)
49 #undef SYSTEM_CLASS_STRING
51 #undef resource
52 #undef pinitSentinel
53 #undef STRINGIZE_CLASS_NAME
55 #define STRINGIZE_HH_CLASS_NAME(cls) "HH\\" #cls
56 #define SYSTEM_HH_CLASS_STRING(cls) \
57 const StaticString s_HH_##cls(STRINGIZE_HH_CLASS_NAME(cls));
58 SYSTEMLIB_HH_CLASSES(SYSTEM_HH_CLASS_STRING)
59 #undef SYSTEM_HH_CLASS_STRING
60 #undef STRINGIZE_HH_CLASS_NAME
62 namespace {
63 const StaticString s_Throwable("Throwable");
64 const StaticString s_BaseException("\\__SystemLib\\BaseException");
65 const StaticString s_Error("Error");
66 const StaticString s_ArithmeticError("ArithmeticError");
67 const StaticString s_ArgumentCountError("ArgumentCountError");
68 const StaticString s_AssertionError("AssertionError");
69 const StaticString s_DivisionByZeroError("DivisionByZeroError");
70 const StaticString s_ParseError("ParseError");
71 const StaticString s_TypeError("TypeError");
72 const StaticString s_MethCallerHelper("\\__SystemLib\\MethCallerHelper");
73 const StaticString s_DynMethCallerHelper("\\__SystemLib\\DynMethCallerHelper");
76 void ProcessInit() {
77 // Save the current options, and set things up so that
78 // systemlib.php can be read from and stored in the
79 // normal repo.
80 int db = RuntimeOption::EvalDumpBytecode;
81 bool rp = RuntimeOption::AlwaysUseRelativePath;
82 bool sf = RuntimeOption::SafeFileAccess;
83 bool ah = RuntimeOption::EvalAllowHhas;
84 RuntimeOption::EvalDumpBytecode &= ~1;
85 RuntimeOption::AlwaysUseRelativePath = false;
86 RuntimeOption::SafeFileAccess = false;
87 RuntimeOption::EvalAllowHhas = true;
89 if (RuntimeOption::RepoAuthoritative) {
90 LitstrTable::init();
91 LitarrayTable::init();
92 RepoFile::loadGlobalTables(RO::RepoLitstrLazyLoad);
93 RepoFile::globalData().load();
95 StringData::markSymbolsLoaded();
97 rds::requestInit();
98 std::string hhas;
99 auto const slib = get_systemlib(&hhas);
101 if (slib.empty()) {
102 // Die a horrible death.
103 Logger::Error("Unable to find/load systemlib.php, check /proc is mounted"
104 " or export HHVM_SYSTEMLIB to your ENV");
105 _exit(1);
108 // Save this in case the debugger needs it. Once we know if this
109 // process does not have debugger support, we'll clear it.
110 SystemLib::s_source = slib;
112 SystemLib::s_unit = compile_systemlib_string(slib.c_str(), slib.size(),
113 "/:systemlib.php",
114 Native::s_systemNativeFuncs);
116 if (auto const info = SystemLib::s_unit->getFatalInfo()) {
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 %d",
121 info->m_fatalMsg.c_str(), info->m_fatalLoc.line1);
122 _exit(1);
125 if (!hhas.empty()) {
126 SystemLib::s_hhas_unit = compile_systemlib_string(
127 hhas.c_str(), hhas.size(), "/:systemlib.hhas",
128 Native::s_systemNativeFuncs);
129 if (auto const info = SystemLib::s_hhas_unit->getFatalInfo()) {
130 Logger::Error("An error has been introduced in the hhas portion of "
131 "systemlib.");
132 Logger::Error("Check all of your changes to hhas files in "
133 "hphp/system/php");
134 Logger::Error("HipHop Parse Error: %s", info->m_fatalMsg.c_str());
135 _exit(1);
139 // Load the systemlib unit to build the Class objects
140 SystemLib::s_unit->merge();
141 if (SystemLib::s_hhas_unit) {
142 SystemLib::s_hhas_unit->merge();
145 SystemLib::s_nullFunc =
146 Func::lookup(makeStaticString("__SystemLib\\__86null"));
148 #define INIT_SYSTEMLIB_CLASS_FIELD(cls) \
150 Class *cls = NamedEntity::get(s_##cls.get())->clsList(); \
151 assert(cls); \
152 SystemLib::s_##cls##Class = cls; \
155 INIT_SYSTEMLIB_CLASS_FIELD(Throwable)
156 INIT_SYSTEMLIB_CLASS_FIELD(BaseException)
157 INIT_SYSTEMLIB_CLASS_FIELD(Error)
158 INIT_SYSTEMLIB_CLASS_FIELD(ArithmeticError)
159 INIT_SYSTEMLIB_CLASS_FIELD(ArgumentCountError)
160 INIT_SYSTEMLIB_CLASS_FIELD(AssertionError)
161 INIT_SYSTEMLIB_CLASS_FIELD(DivisionByZeroError)
162 INIT_SYSTEMLIB_CLASS_FIELD(DivisionByZeroException)
163 INIT_SYSTEMLIB_CLASS_FIELD(ParseError)
164 INIT_SYSTEMLIB_CLASS_FIELD(TypeError)
165 INIT_SYSTEMLIB_CLASS_FIELD(MethCallerHelper)
166 INIT_SYSTEMLIB_CLASS_FIELD(DynMethCallerHelper)
168 // Stash a pointer to the VM Classes for stdclass, Exception,
169 // pinitSentinel and resource
170 SYSTEMLIB_CLASSES(INIT_SYSTEMLIB_CLASS_FIELD)
172 #undef INIT_SYSTEMLIB_CLASS_FIELD
174 #define INIT_SYSTEMLIB_HH_CLASS_FIELD(cls) \
176 Class *cls = NamedEntity::get(s_HH_##cls.get())->clsList(); \
177 assert(cls); \
178 SystemLib::s_HH_##cls##Class = cls; \
181 // Stash a pointer to the VM Classes for various HH namespace classes
182 SYSTEMLIB_HH_CLASSES(INIT_SYSTEMLIB_HH_CLASS_FIELD)
184 #undef INIT_SYSTEMLIB_HH_CLASS_FIELD
186 Stack::ValidateStackSize();
187 SystemLib::s_inited = true;
189 RuntimeOption::AlwaysUseRelativePath = rp;
190 RuntimeOption::SafeFileAccess = sf;
191 RuntimeOption::EvalDumpBytecode = db;
192 RuntimeOption::EvalAllowHhas = ah;
195 ///////////////////////////////////////////////////////////////////////////////