forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharguments.h
More file actions
203 lines (171 loc) · 7.8 KB
/
Copy patharguments.h
File metadata and controls
203 lines (171 loc) · 7.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// Copyright 2012 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_EXECUTION_ARGUMENTS_H_
#define V8_EXECUTION_ARGUMENTS_H_
#include "src/execution/clobber-registers.h"
#include "src/handles/handles.h"
#include "src/logging/runtime-call-stats-scope.h"
#include "src/objects/objects.h"
#include "src/objects/slots.h"
#include "src/sandbox/check.h"
#include "src/tracing/trace-event.h"
#include "src/utils/allocation.h"
namespace v8 {
namespace internal {
// Arguments provides access to runtime call parameters.
//
// It uses the fact that the instance fields of Arguments
// (length_, arguments_) are "overlayed" with the parameters
// (no. of parameters, and the parameter pointer) passed so
// that inside the C++ function, the parameters passed can
// be accessed conveniently:
//
// Object Runtime_function(Arguments args) {
// ... use args[i] here ...
// }
//
// Note that length_ (whose value is in the integer range) is defined
// as intptr_t to provide endian-neutrality on 64-bit archs.
template <ArgumentsType arguments_type>
class Arguments {
public:
// Scope to temporarily change the value of an argument.
class ChangeValueScope {
public:
inline ChangeValueScope(Isolate* isolate, Arguments* args, int index,
Tagged<Object> value);
~ChangeValueScope() { *location_ = (*old_value_).ptr(); }
private:
Address* location_;
DirectHandle<Object> old_value_;
};
Arguments(int length, Address* arguments)
: length_(length), arguments_(arguments) {
DCHECK_GE(length_, 0);
}
V8_INLINE Tagged<Object> operator[](int index) const {
return Tagged<Object>(*address_of_arg_at(index));
}
template <class S = Object>
V8_INLINE Handle<S> at(int index) const;
V8_INLINE FullObjectSlot slot_from_address_at(int index, int offset) const;
V8_INLINE int smi_value_at(int index) const;
V8_INLINE uint32_t positive_smi_value_at(int index) const;
V8_INLINE int tagged_index_value_at(int index) const;
V8_INLINE double number_value_at(int index) const;
V8_INLINE Handle<Object> atOrUndefined(Isolate* isolate, int index) const;
V8_INLINE Address* address_of_arg_at(int index) const {
// Corruption of certain heap objects (see e.g. crbug.com/1507223) can lead
// to OOB arguments access, and therefore OOB stack access. This SBXCHECK
// defends against that.
// Note: "LE" is intentional: it's okay to compute the address of the
// first nonexistent entry.
SBXCHECK_LE(static_cast<uint32_t>(index), static_cast<uint32_t>(length_));
uintptr_t offset = index * kSystemPointerSize;
if (arguments_type == ArgumentsType::kJS) {
offset = (length_ - index - 1) * kSystemPointerSize;
}
return reinterpret_cast<Address*>(reinterpret_cast<Address>(arguments_) -
offset);
}
// Get the total number of arguments including the receiver.
V8_INLINE int length() const { return static_cast<int>(length_); }
V8_INLINE uint32_t ulength() const { return static_cast<uint32_t>(length_); }
private:
intptr_t length_;
Address* arguments_;
};
template <ArgumentsType T>
template <class S>
Handle<S> Arguments<T>::at(int index) const {
Handle<Object> obj = Handle<Object>(address_of_arg_at(index));
return Cast<S>(obj);
}
template <ArgumentsType T>
FullObjectSlot Arguments<T>::slot_from_address_at(int index, int offset) const {
Address* location = *reinterpret_cast<Address**>(address_of_arg_at(index));
return FullObjectSlot(location + offset);
}
#ifdef DEBUG
#define CLOBBER_DOUBLE_REGISTERS() ClobberDoubleRegisters(1, 2, 3, 4);
#else
#define CLOBBER_DOUBLE_REGISTERS()
#endif
// TODO(cbruni): add global flag to check whether any tracing events have been
// enabled.
#ifdef V8_RUNTIME_CALL_STATS
#define RUNTIME_ENTRY_WITH_RCS(Type, InternalType, Convert, Name) \
V8_NOINLINE static Type Stats_##Name(int args_length, Address* args_object, \
Isolate* isolate) { \
RCS_SCOPE(isolate, RuntimeCallCounterId::k##Name); \
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.runtime"), \
"V8.Runtime_" #Name); \
RuntimeArguments args(args_length, args_object); \
return Convert(__RT_impl_##Name(args, isolate)); \
}
#define TEST_AND_CALL_RCS(Name) \
if (V8_UNLIKELY(TracingFlags::is_runtime_stats_enabled())) { \
return Stats_##Name(args_length, args_object, isolate); \
}
#else // V8_RUNTIME_CALL_STATS
#define RUNTIME_ENTRY_WITH_RCS(Type, InternalType, Convert, Name)
#define TEST_AND_CALL_RCS(Name)
#endif // V8_RUNTIME_CALL_STATS
namespace detail {
// The RUNTIME_FUNCTION_RETURNS_TYPE macro doesn't know the Runtime::kFoo name
// of the runtime function it's used for since it's only passed Runtime_Foo as
// "Name". RuntimeFunctionFullName is a trick to get from Runtime_Foo to
// Runtime::kFoo, in order to figure out if Runtime::kFoo can trigger GC.
enum class RuntimeFunctionFullName {
#define F(name, ...) kRuntime_##name,
FOR_EACH_INTRINSIC(F)
#undef F
};
constexpr bool RuntimeFunctionFullNameCanTriggerGC(
RuntimeFunctionFullName function_name) {
switch (function_name) {
#define CASE(name, ...) \
case RuntimeFunctionFullName::kRuntime_##name: \
return Runtime::kCanTriggerGC[static_cast<int>(Runtime::k##name)];
FOR_EACH_INTRINSIC(CASE)
#undef CASE
}
}
} // namespace detail
#define RUNTIME_FUNCTION_RETURNS_TYPE(Type, InternalType, Convert, Name) \
static V8_INLINE InternalType __RT_impl_##Name(RuntimeArguments args, \
Isolate* isolate); \
RUNTIME_ENTRY_WITH_RCS(Type, InternalType, Convert, Name) \
Type Name(int args_length, Address* args_object, Isolate* isolate) { \
DCHECK(isolate->context().is_null() || IsContext(isolate->context())); \
DCHECK(isolate->IsOnCentralStack()); \
CLOBBER_DOUBLE_REGISTERS(); \
TEST_AND_CALL_RCS(Name) \
RuntimeArguments args(args_length, args_object); \
if constexpr (detail::RuntimeFunctionFullNameCanTriggerGC( \
detail::RuntimeFunctionFullName::k##Name)) { \
return Convert(__RT_impl_##Name(args, isolate)); \
} else { \
DisallowGarbageCollection no_gc; \
return Convert(__RT_impl_##Name(args, isolate)); \
} \
} \
\
static InternalType __RT_impl_##Name(RuntimeArguments args, Isolate* isolate)
#ifdef DEBUG
#define BUILTIN_CONVERT_RESULT(x) (isolate->VerifyBuiltinsResult(x)).ptr()
#define BUILTIN_CONVERT_RESULT_PAIR(x) isolate->VerifyBuiltinsResult(x)
#else // DEBUG
#define BUILTIN_CONVERT_RESULT(x) (x).ptr()
#define BUILTIN_CONVERT_RESULT_PAIR(x) (x)
#endif // DEBUG
#define RUNTIME_FUNCTION(Name) \
RUNTIME_FUNCTION_RETURNS_TYPE(Address, Tagged<Object>, \
BUILTIN_CONVERT_RESULT, Name)
#define RUNTIME_FUNCTION_RETURN_PAIR(Name) \
RUNTIME_FUNCTION_RETURNS_TYPE(ObjectPair, ObjectPair, \
BUILTIN_CONVERT_RESULT_PAIR, Name)
} // namespace internal
} // namespace v8
#endif // V8_EXECUTION_ARGUMENTS_H_