Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(386)

Unified Diff: test/cctest/test-platform.cc

Issue 18300003: Fix stack alignment corruption for MinGW32 build (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Enable StackAlignment test only for GCC Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/test-assembler-x64.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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__
« no previous file with comments | « test/cctest/test-assembler-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698