2 +----------------------------------------------------------------------+
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>
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
)
58 #undef STRINGIZE_CLASS_NAME
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_AssertionError("\\__SystemLib\\AssertionError");
66 const StaticString
s_DivisionByZeroError("\\__SystemLib\\DivisionByZeroError");
67 const StaticString
s_ParseError("\\__SystemLib\\ParseError");
68 const StaticString
s_TypeError("\\__SystemLib\\TypeError");
71 void tweak_variant_dtors();
73 jit::mcgen::processInit();
74 jit::processInitProfData();
76 // Save the current options, and set things up so that
77 // systemlib.php can be read from and stored in the
79 int db
= RuntimeOption::EvalDumpBytecode
;
80 bool rp
= RuntimeOption::AlwaysUseRelativePath
;
81 bool sf
= RuntimeOption::SafeFileAccess
;
82 bool ah
= RuntimeOption::EvalAllowHhas
;
83 bool wp
= Option::WholeProgram
;
84 RuntimeOption::EvalDumpBytecode
&= ~1;
85 RuntimeOption::AlwaysUseRelativePath
= false;
86 RuntimeOption::SafeFileAccess
= false;
87 RuntimeOption::EvalAllowHhas
= true;
88 Option::WholeProgram
= false;
92 auto const slib
= get_systemlib(&hhas
);
95 // Die a horrible death.
96 Logger::Error("Unable to find/load systemlib.php, check /proc is mounted"
97 " or export HHVM_SYSTEMLIB to your ENV");
102 if (!RuntimeOption::RepoAuthoritative
) LitstrTable::get().setWriting();
103 Repo::get().loadGlobalData();
105 // Save this in case the debugger needs it. Once we know if this
106 // process does not have debugger support, we'll clear it.
107 SystemLib::s_source
= slib
;
109 SystemLib::s_unit
= compile_systemlib_string(slib
.c_str(), slib
.size(),
112 const StringData
* msg
;
114 if (SystemLib::s_unit
->compileTimeFatal(msg
, line
)) {
115 Logger::Error("An error has been introduced into the systemlib, "
116 "but we cannot give you a file and line number right now.");
117 Logger::Error("Check all of your changes to hphp/system/php");
118 Logger::Error("HipHop Parse Error: %s", msg
->data());
123 SystemLib::s_hhas_unit
= compile_systemlib_string(
124 hhas
.c_str(), hhas
.size(), "systemlib.hhas");
125 if (SystemLib::s_hhas_unit
->compileTimeFatal(msg
, line
)) {
126 Logger::Error("An error has been introduced in the hhas portion of "
128 Logger::Error("Check all of your changes to hhas files in "
130 Logger::Error("HipHop Parse Error: %s", msg
->data());
135 // Load the systemlib unit to build the Class objects
136 SystemLib::s_unit
->merge();
137 if (SystemLib::s_hhas_unit
) {
138 SystemLib::s_hhas_unit
->merge();
141 SystemLib::s_nullFunc
=
142 Unit::lookupFunc(makeStaticString("__SystemLib\\__86null"));
144 LitstrTable::get().setReading();
146 #define INIT_SYSTEMLIB_CLASS_FIELD(cls) \
148 Class *cls = NamedEntity::get(s_##cls.get())->clsList(); \
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(AssertionError
)
158 INIT_SYSTEMLIB_CLASS_FIELD(DivisionByZeroError
)
159 INIT_SYSTEMLIB_CLASS_FIELD(ParseError
)
160 INIT_SYSTEMLIB_CLASS_FIELD(TypeError
)
162 // Stash a pointer to the VM Classes for stdclass, Exception,
163 // pinitSentinel and resource
164 SYSTEMLIB_CLASSES(INIT_SYSTEMLIB_CLASS_FIELD
)
166 #undef INIT_SYSTEMLIB_CLASS_FIELD
168 Stack::ValidateStackSize();
169 SystemLib::s_inited
= true;
171 RuntimeOption::AlwaysUseRelativePath
= rp
;
172 RuntimeOption::SafeFileAccess
= sf
;
173 RuntimeOption::EvalDumpBytecode
= db
;
174 RuntimeOption::EvalAllowHhas
= ah
;
175 Option::WholeProgram
= wp
;
177 tweak_variant_dtors();
180 ///////////////////////////////////////////////////////////////////////////////