Index: src/trusted/validator/validation_rewrite_32_test.cc |
diff --git a/src/trusted/validator/validation_disable_nontemporals_test.cc b/src/trusted/validator/validation_rewrite_32_test.cc |
similarity index 51% |
copy from src/trusted/validator/validation_disable_nontemporals_test.cc |
copy to src/trusted/validator/validation_rewrite_32_test.cc |
index 211288d2407295b2c17043332d239f2f39ce42f9..1f0bc2c2586b33a7f18ed6532e196483a29f1586 100644 |
--- a/src/trusted/validator/validation_disable_nontemporals_test.cc |
+++ b/src/trusted/validator/validation_rewrite_32_test.cc |
@@ -4,6 +4,8 @@ |
* found in the LICENSE file. |
*/ |
+#include <string.h> |
+ |
#include "gtest/gtest.h" |
#include "native_client/src/shared/platform/nacl_log.h" |
@@ -12,12 +14,23 @@ |
#define CODE_SIZE 32 |
#define NOP 0x90 |
-#define MOVNTI_CODE_SIZE 8 |
-// mov %edi,%edi; movnti %rax,0x68(%r15,%rdi,1) |
-const char* movnti_code = "\x89\xff\x49\x0f\xc3\x44\x3f\x68"; |
+extern "C" { |
+ extern const char no_rewrite_code[]; |
+ extern const char no_rewrite_code_end[]; |
+ extern const char no_rewrite_code_post_rewrite[]; |
+ extern const char no_rewrite_code_post_rewrite_end[]; |
+ extern const char movntq_code[]; |
+ extern const char movntq_code_end[]; |
+ extern const char movntq_code_post_rewrite[]; |
+ extern const char movntq_code_post_rewrite_end[]; |
+ extern const char movntdq_code[]; |
+ extern const char movntdq_code_end[]; |
+ extern const char movntdq_code_post_rewrite[]; |
+ extern const char movntdq_code_post_rewrite_end[]; |
+} |
-class ValidationDisableNonTemporalsTests : public ::testing::Test { |
+class ValidationMovntRewriteTests : public ::testing::Test { |
protected: |
NaClValidationMetadata *metadata_ptr; |
const struct NaClValidatorInterface *validator; |
@@ -36,7 +49,7 @@ class ValidationDisableNonTemporalsTests : public ::testing::Test { |
} |
NaClValidationStatus Validate(uint32_t flags) { |
- return validator->Validate(0, code_buffer, 32, |
+ return validator->Validate(0, code_buffer, CODE_SIZE, |
FALSE, /* stubout_mode */ |
flags, |
FALSE, /* readonly_test */ |
@@ -50,23 +63,35 @@ class ValidationDisableNonTemporalsTests : public ::testing::Test { |
} |
}; |
-TEST_F(ValidationDisableNonTemporalsTests, NotDisableNonTemporals) { |
- memcpy(code_buffer, movnti_code, MOVNTI_CODE_SIZE); |
+TEST_F(ValidationMovntRewriteTests, DisableNonTemporalsNoRewrite) { |
+ size_t len = no_rewrite_code_end - no_rewrite_code; |
+ size_t post_len = |
+ no_rewrite_code_post_rewrite_end - no_rewrite_code_post_rewrite; |
+ EXPECT_EQ(len, post_len); |
+ memcpy(code_buffer, no_rewrite_code, len); |
+ NaClValidationStatus status = Validate(NACL_DISABLE_NONTEMPORALS_X86); |
+ EXPECT_EQ(NaClValidationFailed, status); |
+ EXPECT_EQ(0, memcmp(code_buffer, no_rewrite_code_post_rewrite, post_len)); |
+} |
+ |
+TEST_F(ValidationMovntRewriteTests, RewriteMovntq) { |
+ size_t len = movntq_code_end - movntq_code; |
+ size_t post_len = movntq_code_post_rewrite_end - movntq_code_post_rewrite; |
+ EXPECT_EQ(len, post_len); |
+ memcpy(code_buffer, movntq_code, len); |
NaClValidationStatus status = Validate(0); |
- // If we are not disabling non-temporal instructions, use the original |
- // validation rule, i.e., allow them. In future, we will do rewriting. |
EXPECT_EQ(NaClValidationSucceeded, status); |
- // Code should not change. |
- EXPECT_EQ(0, memcmp(code_buffer, movnti_code, MOVNTI_CODE_SIZE)); |
+ EXPECT_EQ(0, memcmp(code_buffer, movntq_code_post_rewrite, post_len)); |
} |
-TEST_F(ValidationDisableNonTemporalsTests, DisableNonTemporals) { |
- memcpy(code_buffer, movnti_code, MOVNTI_CODE_SIZE); |
- NaClValidationStatus status = Validate(NACL_DISABLE_NONTEMPORALS_X86); |
- // Disable non-temporal instructions. |
- EXPECT_EQ(NaClValidationFailed, status); |
- // Code should not change. |
- EXPECT_EQ(0, memcmp(code_buffer, movnti_code, MOVNTI_CODE_SIZE)); |
+TEST_F(ValidationMovntRewriteTests, RewriteMovntdq) { |
+ size_t len = movntdq_code_end - movntdq_code; |
+ size_t post_len = movntdq_code_post_rewrite_end - movntdq_code_post_rewrite; |
+ EXPECT_EQ(len, post_len); |
+ memcpy(code_buffer, movntdq_code, len); |
+ NaClValidationStatus status = Validate(0); |
+ EXPECT_EQ(NaClValidationSucceeded, status); |
+ EXPECT_EQ(0, memcmp(code_buffer, movntdq_code_post_rewrite, post_len)); |
} |
int main(int argc, char *argv[]) { |