Index: test/cctest/test-platform.cc |
diff --git a/test/cctest/test-platform.cc b/test/cctest/test-platform.cc |
index 6c20b853c5e7408b1877ee74617c01c3fc32ed5f..7c8d4a450379b54f4ec372731608ff25d5f48197 100644 |
--- a/test/cctest/test-platform.cc |
+++ b/test/cctest/test-platform.cc |
@@ -35,3 +35,65 @@ using namespace ::v8::internal; |
TEST(NumberOfCores) { |
CHECK_GT(OS::NumberOfCores(), 0); |
} |
+ |
+ |
+#ifdef __GNUC__ |
+#define ASM __asm__ __volatile__ |
+ |
+#if defined(_M_X64) || defined(__x86_64__) |
+#define GET_STACK_POINTER() \ |
+ static int sp_addr = 0; \ |
+ do { \ |
+ ASM("mov %%rsp, %0" : "=g" (sp_addr)); \ |
+ } while (0) |
+#elif defined(_M_IX86) || defined(__i386__) |
+#define GET_STACK_POINTER() \ |
+ static int sp_addr = 0; \ |
+ do { \ |
+ ASM("mov %%esp, %0" : "=g" (sp_addr)); \ |
+ } while (0) |
+#elif defined(__ARMEL__) |
+#define GET_STACK_POINTER() \ |
+ static int sp_addr = 0; \ |
+ do { \ |
+ ASM("str %%sp, %0" : "=g" (sp_addr)); \ |
+ } while (0) |
+#elif defined(__MIPSEL__) |
+#define GET_STACK_POINTER() \ |
+ static int sp_addr = 0; \ |
+ do { \ |
+ ASM("sw $sp, %0" : "=g" (sp_addr)); \ |
+ } while (0) |
+#else |
+#error Host architecture was not detected as supported by v8 |
+#endif |
+ |
+void GetStackPointer(const v8::FunctionCallbackInfo<v8::Value>& args) { |
+ GET_STACK_POINTER(); |
+ args.GetReturnValue().Set(v8_num(sp_addr)); |
+} |
+ |
+TEST(StackAlignment) { |
+ v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
+ v8::HandleScope handle_scope(isolate); |
+ v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
+ global_template->Set(v8_str("get_stack_pointer"), |
+ v8::FunctionTemplate::New(GetStackPointer)); |
+ |
+ 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); |
+ CHECK_EQ(0, result->Int32Value() % OS::ActivationFrameAlignment()); |
+} |
+ |
+#undef GET_STACK_POINTERS |
+#undef ASM |
+#endif // __GNUC__ |