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

Unified Diff: tests/dynamic_code_loading/dynamic_modify_test.c

Issue 9328024: Merge 7712 - Ensure super instructions are marked during dynamic code modification. (Closed) Base URL: svn://svn.chromium.org/native_client/branches/963/src/native_client/
Patch Set: '' Created 8 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 | « src/trusted/validator/x86/ncval_seg_sfi/ncvalidate.c ('k') | tests/dynamic_code_loading/templates.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/dynamic_code_loading/dynamic_modify_test.c
===================================================================
--- tests/dynamic_code_loading/dynamic_modify_test.c (revision 7726)
+++ tests/dynamic_code_loading/dynamic_modify_test.c (working copy)
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011 The Native Client Authors. All rights reserved.
+ * Copyright (c) 2012 The Native Client Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -311,7 +311,62 @@
assert(rc == 1234);
}
+#if defined(__i386__) || defined(__x86_64__)
+void test_jump_into_super_inst_create() {
+ uint8_t *load_area = allocate_code_space(1);
+ uint8_t buf[BUF_SIZE];
+ int rc;
+ /* A direct jump into a bundle is invalid. */
+ copy_and_pad_fragment(buf, sizeof(buf), &jump_into_super_inst_modified,
+ &jump_into_super_inst_modified_end);
+ rc = nacl_dyncode_create(load_area, buf, sizeof(buf));
+ assert(rc != 0);
+ assert(errno == EINVAL);
+}
+
+void test_start_with_super_inst_replace() {
+ uint8_t *load_area = allocate_code_space(1);
+ uint8_t buf[BUF_SIZE];
+ int rc;
+
+ /* The original version is fine. */
+ copy_and_pad_fragment(buf, sizeof(buf), &jump_into_super_inst_original,
+ &jump_into_super_inst_original_end);
+ rc = nacl_dyncode_create(load_area, buf, sizeof(buf));
+ assert(rc == 0);
+
+ /* Replace the code with itself. This makes sure that replacement code can
+ * start with a super instruction.
+ */
+ copy_and_pad_fragment(buf, sizeof(buf), &jump_into_super_inst_original,
+ &jump_into_super_inst_original_end);
+ rc = nacl_dyncode_modify(load_area, buf, sizeof(buf));
+ assert(rc == 0);
+}
+
+void test_jump_into_super_inst_replace() {
+ uint8_t *load_area = allocate_code_space(1);
+ uint8_t buf[BUF_SIZE];
+ int rc;
+
+ /* The original version is fine. */
+ copy_and_pad_fragment(buf, sizeof(buf), &jump_into_super_inst_original,
+ &jump_into_super_inst_original_end);
+ rc = nacl_dyncode_create(load_area, buf, sizeof(buf));
+ assert(rc == 0);
+
+ /* The modified version cannot be used as a replacement.
+ * See: http://code.google.com/p/nativeclient/issues/detail?id=2563
+ */
+ copy_and_pad_fragment(buf, sizeof(buf), &jump_into_super_inst_modified,
+ &jump_into_super_inst_modified_end);
+ rc = nacl_dyncode_modify(load_area, buf, sizeof(buf));
+ assert(rc != 0);
+ assert(errno == EINVAL);
+}
+#endif
+
void run_test(const char *test_name, void (*test_func)(void)) {
printf("Running %s...\n", test_name);
test_func();
@@ -334,6 +389,9 @@
RUN_TEST(test_replacing_code_unaligned);
#if defined(__i386__) || defined(__x86_64__)
RUN_TEST(test_replacing_code_slowpaths);
+ RUN_TEST(test_jump_into_super_inst_create);
+ RUN_TEST(test_start_with_super_inst_replace);
+ RUN_TEST(test_jump_into_super_inst_replace);
#endif
RUN_TEST(test_illegal_code_replacment);
RUN_TEST(test_external_jump_target_replacement);
« no previous file with comments | « src/trusted/validator/x86/ncval_seg_sfi/ncvalidate.c ('k') | tests/dynamic_code_loading/templates.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698