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

Unified Diff: runtime/vm/object_test.cc

Issue 136563002: Landing: Write protect executable pages in the VM. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 10 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 | « runtime/vm/object.cc ('k') | runtime/vm/pages.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object_test.cc
===================================================================
--- runtime/vm/object_test.cc (revision 32487)
+++ runtime/vm/object_test.cc (working copy)
@@ -2464,6 +2464,31 @@
}
+// Test for immutability of generated instructions. The test crashes with a
+// segmentation fault when writing into it.
+TEST_CASE(CodeImmutability) {
+ extern void GenerateIncrement(Assembler* assembler);
+ Assembler _assembler_;
+ GenerateIncrement(&_assembler_);
+ Code& code = Code::Handle(Code::FinalizeCode(
+ *CreateFunction("Test_Code"), &_assembler_));
+ Instructions& instructions = Instructions::Handle(code.instructions());
+ uword entry_point = instructions.EntryPoint();
+ // Try writing into the generated code, expected to crash.
+ *(reinterpret_cast<char*>(entry_point) + 1) = 1;
+ intptr_t retval = 0;
+#if defined(USING_SIMULATOR)
+ retval = bit_copy<intptr_t, int64_t>(Simulator::Current()->Call(
+ static_cast<int32_t>(entry_point), 0, 0, 0, 0));
+#else
+ typedef intptr_t (*IncrementCode)();
+ retval = reinterpret_cast<IncrementCode>(entry_point)();
+#endif
+ EXPECT_EQ(3, retval);
+ EXPECT_EQ(instructions.raw(), Instructions::FromEntryPoint(entry_point));
+}
+
+
// Test for Embedded String object in the instructions.
TEST_CASE(EmbedStringInCode) {
extern void GenerateEmbedStringInCode(Assembler* assembler, const char* str);
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/pages.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698