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

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: Added command line flag Created 6 years, 11 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
Index: runtime/vm/object_test.cc
diff --git a/runtime/vm/object_test.cc b/runtime/vm/object_test.cc
index ced3d4fc03dd830da791a807fcb852d9c70634b3..39dcfe3342805731f494e30e3b56b1c718cb9f26 100644
--- a/runtime/vm/object_test.cc
+++ b/runtime/vm/object_test.cc
@@ -2464,6 +2464,31 @@ TEST_CASE(Code) {
}
+// 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);

Powered by Google App Engine
This is Rietveld 408576698