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-09-16 09:23:27 +00:00
|
|
|
#include "include/v8stdint.h"
|
|
|
|
#include "src/base/build_config.h"
|
2014-06-30 13:25:46 +00:00
|
|
|
#include "src/base/platform/platform.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
2013-02-15 12:38:59 +00:00
|
|
|
|
2014-09-16 09:23:27 +00:00
|
|
|
#ifdef V8_CC_GNU
|
2013-02-15 12:38:59 +00:00
|
|
|
|
2014-09-16 09:23:27 +00:00
|
|
|
static uintptr_t sp_addr = 0;
|
2013-07-05 08:34:17 +00:00
|
|
|
|
2014-09-16 09:23:27 +00:00
|
|
|
void GetStackPointer(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
|
|
#if V8_HOST_ARCH_X64
|
|
|
|
__asm__ __volatile__("mov %%rsp, %0" : "=g"(sp_addr));
|
|
|
|
#elif V8_HOST_ARCH_IA32
|
|
|
|
__asm__ __volatile__("mov %%esp, %0" : "=g"(sp_addr));
|
|
|
|
#elif V8_HOST_ARCH_ARM
|
|
|
|
__asm__ __volatile__("str %%sp, %0" : "=g"(sp_addr));
|
|
|
|
#elif V8_HOST_ARCH_ARM64
|
|
|
|
__asm__ __volatile__("mov x16, sp; str x16, %0" : "=g"(sp_addr));
|
|
|
|
#elif V8_HOST_ARCH_MIPS
|
|
|
|
__asm__ __volatile__("sw $sp, %0" : "=g"(sp_addr));
|
2013-07-05 08:34:17 +00:00
|
|
|
#else
|
|
|
|
#error Host architecture was not detected as supported by v8
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
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);
|
2014-01-08 06:53:31 +00:00
|
|
|
v8::Handle<v8::ObjectTemplate> global_template =
|
|
|
|
v8::ObjectTemplate::New(isolate);
|
2013-07-05 08:34:17 +00:00
|
|
|
global_template->Set(v8_str("get_stack_pointer"),
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::FunctionTemplate::New(isolate, GetStackPointer));
|
2013-07-05 08:34:17 +00:00
|
|
|
|
|
|
|
LocalContext env(NULL, global_template);
|
|
|
|
CompileRun(
|
|
|
|
"function foo() {"
|
|
|
|
" return get_stack_pointer();"
|
|
|
|
"}");
|
|
|
|
|
|
|
|
v8::Local<v8::Object> global_object = env->Global();
|
|
|
|
v8::Local<v8::Function> foo =
|
|
|
|
v8::Local<v8::Function>::Cast(global_object->Get(v8_str("foo")));
|
|
|
|
|
|
|
|
v8::Local<v8::Value> result = foo->Call(global_object, 0, NULL);
|
2014-09-16 09:23:27 +00:00
|
|
|
CHECK_EQ(0, result->Uint32Value() % v8::base::OS::ActivationFrameAlignment());
|
2013-07-05 08:34:17 +00:00
|
|
|
}
|
|
|
|
|
2014-09-16 09:23:27 +00:00
|
|
|
#endif // V8_CC_GNU
|