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/bytecode.h"
20 #include "hphp/runtime/vm/repo.h"
21 #include "hphp/runtime/vm/runtime-compiler.h"
22 #include "hphp/runtime/vm/unit.h"
24 #include "hphp/runtime/base/execution-context.h"
25 #include "hphp/runtime/base/program-functions.h"
26 #include "hphp/runtime/base/rds.h"
27 #include "hphp/runtime/base/runtime-option.h"
28 #include "hphp/runtime/base/unit-cache.h"
30 #include "hphp/system/systemlib.h"
32 #include "hphp/util/build-info.h"
33 #include "hphp/util/logger.h"
35 #include <folly/portability/Libgen.h>
41 ///////////////////////////////////////////////////////////////////////////////
43 #define STRINGIZE_CLASS_NAME(cls) #cls
44 #define pinitSentinel __pinitSentinel
45 #define resource __resource
47 #define SYSTEM_CLASS_STRING(cls) \
48 const StaticString s_##cls(STRINGIZE_CLASS_NAME(cls));
49 SYSTEMLIB_CLASSES(SYSTEM_CLASS_STRING
)
53 #undef STRINGIZE_CLASS_NAME
56 const StaticString
s_Throwable("Throwable");
57 const StaticString
s_BaseException("\\__SystemLib\\BaseException");
58 const StaticString
s_Error("Error");
59 const StaticString
s_ArithmeticError("ArithmeticError");
60 const StaticString
s_ArgumentCountError("ArgumentCountError");
61 const StaticString
s_AssertionError("AssertionError");
62 const StaticString
s_DivisionByZeroError("DivisionByZeroError");
63 const StaticString
s_ParseError("ParseError");
64 const StaticString
s_TypeError("TypeError");
67 void tweak_variant_dtors();
69 // Save the current options, and set things up so that
70 // systemlib.php can be read from and stored in the
72 int db
= RuntimeOption::EvalDumpBytecode
;
73 bool rp
= RuntimeOption::AlwaysUseRelativePath
;
74 bool sf
= RuntimeOption::SafeFileAccess
;
75 bool ah
= RuntimeOption::EvalAllowHhas
;
76 bool wp
= Option::WholeProgram
;
77 RuntimeOption::EvalDumpBytecode
&= ~1;
78 RuntimeOption::AlwaysUseRelativePath
= false;
79 RuntimeOption::SafeFileAccess
= false;
80 RuntimeOption::EvalAllowHhas
= true;
81 Option::WholeProgram
= false;
83 if (RuntimeOption::RepoAuthoritative
) {
85 Repo::get().loadGlobalData();
90 auto const slib
= get_systemlib(&hhas
);
93 // Die a horrible death.
94 Logger::Error("Unable to find/load systemlib.php, check /proc is mounted"
95 " or export HHVM_SYSTEMLIB to your ENV");
99 // Save this in case the debugger needs it. Once we know if this
100 // process does not have debugger support, we'll clear it.
101 SystemLib::s_source
= slib
;
103 SystemLib::s_unit
= compile_systemlib_string(slib
.c_str(), slib
.size(),
106 const StringData
* msg
;
108 if (SystemLib::s_unit
->compileTimeFatal(msg
, line
)) {
109 Logger::Error("An error has been introduced into the systemlib, "
110 "but we cannot give you a file and line number right now.");
111 Logger::Error("Check all of your changes to hphp/system/php");
112 Logger::Error("HipHop Parse Error: %s %d", msg
->data(), line
);
117 SystemLib::s_hhas_unit
= compile_systemlib_string(
118 hhas
.c_str(), hhas
.size(), "/:systemlib.hhas");
119 if (SystemLib::s_hhas_unit
->compileTimeFatal(msg
, line
)) {
120 Logger::Error("An error has been introduced in the hhas portion of "
122 Logger::Error("Check all of your changes to hhas files in "
124 Logger::Error("HipHop Parse Error: %s", msg
->data());
129 // Load the systemlib unit to build the Class objects
130 SystemLib::s_unit
->merge();
131 if (SystemLib::s_hhas_unit
) {
132 SystemLib::s_hhas_unit
->merge();
135 SystemLib::s_nullFunc
=
136 Unit::lookupFunc(makeStaticString("__SystemLib\\__86null"));
138 #define INIT_SYSTEMLIB_CLASS_FIELD(cls) \
140 Class *cls = NamedEntity::get(s_##cls.get())->clsList(); \
142 SystemLib::s_##cls##Class = cls; \
145 INIT_SYSTEMLIB_CLASS_FIELD(Throwable
)
146 INIT_SYSTEMLIB_CLASS_FIELD(BaseException
)
147 INIT_SYSTEMLIB_CLASS_FIELD(Error
)
148 INIT_SYSTEMLIB_CLASS_FIELD(ArithmeticError
)
149 INIT_SYSTEMLIB_CLASS_FIELD(ArgumentCountError
)
150 INIT_SYSTEMLIB_CLASS_FIELD(AssertionError
)
151 INIT_SYSTEMLIB_CLASS_FIELD(DivisionByZeroError
)
152 INIT_SYSTEMLIB_CLASS_FIELD(ParseError
)
153 INIT_SYSTEMLIB_CLASS_FIELD(TypeError
)
155 // Stash a pointer to the VM Classes for stdclass, Exception,
156 // pinitSentinel and resource
157 SYSTEMLIB_CLASSES(INIT_SYSTEMLIB_CLASS_FIELD
)
159 #undef INIT_SYSTEMLIB_CLASS_FIELD
161 Stack::ValidateStackSize();
162 SystemLib::s_inited
= true;
164 RuntimeOption::AlwaysUseRelativePath
= rp
;
165 RuntimeOption::SafeFileAccess
= sf
;
166 RuntimeOption::EvalDumpBytecode
= db
;
167 RuntimeOption::EvalAllowHhas
= ah
;
168 Option::WholeProgram
= wp
;
170 tweak_variant_dtors();
173 ///////////////////////////////////////////////////////////////////////////////