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 +----------------------------------------------------------------------+
16 #ifndef incl_HPHP_VM_RUNTIME_H_
17 #define incl_HPHP_VM_RUNTIME_H_
19 #include "hphp/runtime/ext/generator/ext_generator.h"
20 #include "hphp/runtime/ext/asio/ext_async-function-wait-handle.h"
21 #include "hphp/runtime/ext/asio/ext_async-generator.h"
22 #include "hphp/runtime/ext/std/ext_std_errorfunc.h"
23 #include "hphp/runtime/vm/act-rec.h"
24 #include "hphp/runtime/vm/event-hook.h"
25 #include "hphp/runtime/vm/func.h"
26 #include "hphp/runtime/vm/reified-generics.h"
27 #include "hphp/runtime/vm/resumable.h"
28 #include "hphp/runtime/base/builtin-functions.h"
29 #include "hphp/runtime/base/execution-context.h"
30 #include "hphp/runtime/base/object-data.h"
31 #include "hphp/runtime/base/stats.h"
32 #include "hphp/runtime/base/tv-refcount.h"
33 #include "hphp/runtime/base/tv-val.h"
37 struct HhbcExtFuncInfo
;
38 struct HhbcExtClassInfo
;
40 StringData
* concat_is(int64_t v1
, StringData
* v2
);
41 StringData
* concat_si(StringData
* v1
, int64_t v2
);
42 StringData
* concat_ss(StringData
* v1
, StringData
* v2
);
43 StringData
* concat_s3(StringData
* v1
, StringData
* v2
, StringData
* v3
);
44 StringData
* concat_s4(StringData
* v1
, StringData
* v2
,
45 StringData
* v3
, StringData
* v4
);
47 void print_string(StringData
* s
);
48 void print_int(int64_t i
);
49 void print_boolean(bool val
);
51 void raiseWarning(const StringData
* sd
);
52 void raiseNotice(const StringData
* sd
);
53 [[noreturn
]] void throwArrayIndexException(const ArrayData
*ad
, int64_t index
);
54 [[noreturn
]] void throwArrayKeyException(const ArrayData
*ad
, const StringData
* key
);
55 std::string
formatParamInOutMismatch(const char* fname
, uint32_t index
,
57 [[noreturn
]] void throwParamInOutMismatch(const Func
* func
, uint32_t index
);
58 [[noreturn
]] void throwParamInOutMismatchRange(const Func
* func
,
59 unsigned firstBit
, uint64_t mask
,
61 [[noreturn
]] void throwInvalidUnpackArgs();
62 void raiseRxCallViolation(const ActRec
* caller
, const Func
* callee
);
65 frame_iter(const ActRec
* fp
, int i
) {
66 return (Iter
*)(uintptr_t(fp
)
67 - uintptr_t(fp
->func()->numLocals() * sizeof(TypedValue
))
68 - uintptr_t((i
+1) * sizeof(Iter
)));
72 frame_local(const ActRec
* fp
, int n
) {
73 return (TypedValue
*)(uintptr_t(fp
) - uintptr_t((n
+1) * sizeof(TypedValue
)));
77 frame_resumable(const ActRec
* fp
) {
78 assertx(isResumed(fp
));
79 return (Resumable
*)((char*)fp
- Resumable::arOff());
82 inline c_AsyncFunctionWaitHandle
*
83 frame_afwh(const ActRec
* fp
) {
84 assertx(fp
->func()->isAsyncFunction());
85 auto resumable
= frame_resumable(fp
);
86 auto arOffset
= c_AsyncFunctionWaitHandle::arOff();
87 auto waitHandle
= (c_AsyncFunctionWaitHandle
*)((char*)resumable
- arOffset
);
88 assertx(waitHandle
->getVMClass() == c_AsyncFunctionWaitHandle::classof());
93 frame_generator(const ActRec
* fp
) {
94 assertx(fp
->func()->isNonAsyncGenerator());
95 auto resumable
= frame_resumable(fp
);
96 return (Generator
*)((char*)resumable
- Generator::resumableOff());
99 inline AsyncGenerator
*
100 frame_async_generator(const ActRec
* fp
) {
101 assertx(fp
->func()->isAsyncGenerator());
102 auto resumable
= frame_resumable(fp
);
103 return (AsyncGenerator
*)((char*)resumable
-
104 AsyncGenerator::resumableOff());
108 frame_free_locals_helper_inl(ActRec
* fp
, int numLocals
) {
109 assertx(numLocals
== fp
->func()->numLocals());
111 for (int i
= numLocals
- 1; i
>= 0; --i
) {
112 TRACE_MOD(Trace::runtime
, 5,
113 "RetC: freeing %d'th local of %d\n", i
,
114 fp
->func()->numLocals());
115 tvDecRefGen(*frame_local(fp
, i
));
120 frame_free_locals_inl_no_hook(ActRec
* fp
, int numLocals
) {
121 frame_free_locals_helper_inl(fp
, numLocals
);
122 if (fp
->func()->cls() && fp
->hasThis()) {
123 decRefObj(fp
->getThis());
128 frame_free_locals_inl(ActRec
* fp
, int numLocals
, TypedValue
* rv
) {
129 frame_free_locals_inl_no_hook(fp
, numLocals
);
130 EventHook::FunctionReturn(fp
, *rv
);
134 frame_free_locals_no_this_inl(ActRec
* fp
, int numLocals
, TypedValue
* rv
) {
135 frame_free_locals_helper_inl(fp
, numLocals
);
136 EventHook::FunctionReturn(fp
, *rv
);
139 // Helper for iopFCallBuiltin.
141 frame_free_args(TypedValue
* args
, int count
) {
142 for (auto i
= count
; i
--; ) tvDecRefGen(*(args
- i
));
145 int64_t zero_error_level();
146 void restore_error_level(int64_t oldLevel
);