2013-02-15 12:38:59 +00:00
|
|
|
// Copyright 2013 the V8 project authors. All rights reserved.
|
2014-09-16 09:23:27 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2013-02-15 12:38:59 +00:00
|
|
|
|
2014-10-21 08:25:14 +00:00
|
|
|
#include <stdint.h>
|
2020-10-13 15:44:09 +00:00
|
|
|
|
2021-08-23 13:01:06 +00:00
|
|
|
#include "include/v8-function.h"
|
2014-09-16 09:23:27 +00:00
|
|
|
#include "src/base/build_config.h"
|
2014-06-30 13:25:46 +00:00
|
|
|
#include "src/base/platform/platform.h"
|
2020-10-13 15:44:09 +00:00
|
|
|
#include "test/cctest/cctest-utils.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
2013-02-15 12:38:59 +00:00
|
|
|
|
2017-10-26 17:50:29 +00:00
|
|
|
using OS = v8::base::OS;
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
#ifdef V8_CC_GNU
|
2013-07-05 08:34:17 +00:00
|
|
|
|
2020-10-14 09:16:11 +00:00
|
|
|
static uintptr_t sp_addr = 0;
|
2013-07-05 08:34:17 +00:00
|
|
|
|
2020-10-14 09:16:11 +00:00
|
|
|
void GetStackPointerCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
|
|
GET_STACK_POINTER_TO(sp_addr);
|
2014-09-16 09:23:27 +00:00
|
|
|
args.GetReturnValue().Set(v8::Integer::NewFromUnsigned(
|
|
|
|
args.GetIsolate(), static_cast<uint32_t>(sp_addr)));
|
2013-07-05 08:34:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(StackAlignment) {
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
2013-07-05 08:34:17 +00:00
|
|
|
v8::HandleScope handle_scope(isolate);
|
2015-10-08 09:48:05 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> global_template =
|
2014-01-08 06:53:31 +00:00
|
|
|
v8::ObjectTemplate::New(isolate);
|
2020-10-13 15:44:09 +00:00
|
|
|
global_template->Set(
|
|
|
|
isolate, "get_stack_pointer",
|
|
|
|
v8::FunctionTemplate::New(isolate, GetStackPointerCallback));
|
2013-07-05 08:34:17 +00:00
|
|
|
|
2017-10-13 16:33:03 +00:00
|
|
|
LocalContext env(nullptr, global_template);
|
2013-07-05 08:34:17 +00:00
|
|
|
CompileRun(
|
|
|
|
"function foo() {"
|
|
|
|
" return get_stack_pointer();"
|
|
|
|
"}");
|
|
|
|
|
|
|
|
v8::Local<v8::Object> global_object = env->Global();
|
2015-10-08 09:48:05 +00:00
|
|
|
v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
|
|
|
|
global_object->Get(isolate->GetCurrentContext(), v8_str("foo"))
|
|
|
|
.ToLocalChecked());
|
2013-07-05 08:34:17 +00:00
|
|
|
|
2015-10-08 09:48:05 +00:00
|
|
|
v8::Local<v8::Value> result =
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(isolate->GetCurrentContext(), global_object, 0, nullptr)
|
2015-10-08 09:48:05 +00:00
|
|
|
.ToLocalChecked();
|
|
|
|
CHECK_EQ(0u, result->Uint32Value(isolate->GetCurrentContext()).FromJust() %
|
2017-10-26 17:50:29 +00:00
|
|
|
OS::ActivationFrameAlignment());
|
2013-07-05 08:34:17 +00:00
|
|
|
}
|
2014-09-16 09:23:27 +00:00
|
|
|
#endif // V8_CC_GNU
|
2017-10-26 17:50:29 +00:00
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|