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

Unified Diff: src/trusted/validator/validation_rewrite_32_test.cc

Issue 1269113003: Rewrite non-temporal instructions Base URL: https://chromium.googlesource.com/native_client/src/native_client.git@master
Patch Set: Trivial: fix comments Created 5 years, 4 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: 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 65%
copy from src/trusted/validator/validation_disable_nontemporals_test.cc
copy to src/trusted/validator/validation_rewrite_32_test.cc
index 211288d2407295b2c17043332d239f2f39ce42f9..ad24da6eb567683ee891ab2832ab586c7e82d705 100644
--- a/src/trusted/validator/validation_disable_nontemporals_test.cc
+++ b/src/trusted/validator/validation_rewrite_32_test.cc
@@ -4,6 +4,7 @@
* found in the LICENSE file.
*/
+#include <string.h>
#include "gtest/gtest.h"
#include "native_client/src/shared/platform/nacl_log.h"
@@ -12,12 +13,8 @@
#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";
-
-class ValidationDisableNonTemporalsTests : public ::testing::Test {
+class ValidationMovntRewriteTests : public ::testing::Test {
protected:
NaClValidationMetadata *metadata_ptr;
const struct NaClValidatorInterface *validator;
@@ -50,23 +47,37 @@ class ValidationDisableNonTemporalsTests : public ::testing::Test {
}
};
-TEST_F(ValidationDisableNonTemporalsTests, NotDisableNonTemporals) {
- memcpy(code_buffer, movnti_code, MOVNTI_CODE_SIZE);
+TEST_F(ValidationMovntRewriteTests, DisableNonTemporalsNoRewrite) {
+ // movntq %mm0, (%ebx)
+ const char *code = "\x0f\xe7\x03";
bradn 2015/08/04 22:03:30 Could you add a .S file with the asm for each of t
ruiq 2015/08/05 20:11:02 Done.
+ memcpy(code_buffer, code, strlen(code));
+ NaClValidationStatus status = Validate(NACL_DISABLE_NONTEMPORALS_X86);
+ // Disable nontemporals, no rewrite.
+ EXPECT_EQ(NaClValidationFailed, status);
+ // Code should not change.
+ EXPECT_EQ(0, memcmp(code_buffer, code, strlen(code)));
+}
+
+TEST_F(ValidationMovntRewriteTests, RewriteMovntq) {
+ // movntq %mm0, (%ebx)
+ const char *code = "\x0f\xe7\x03";
+ memcpy(code_buffer, code, strlen(code));
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));
+ // movq %mm0, (%ebx)
+ const char *expect_code = "\x0f\x7f\x03";
+ EXPECT_EQ(0, memcmp(code_buffer, expect_code, strlen(expect_code)));
}
-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) {
+ // movntdq %xmm0, (%edx)
+ const char *code = "\x66\x0f\xe7\x02";
+ memcpy(code_buffer, code, strlen(code));
+ NaClValidationStatus status = Validate(0);
+ EXPECT_EQ(NaClValidationSucceeded, status);
+ // movdqa %xmm0, (%edx)
+ const char *expect_code = "\x66\x0f\x7f\x02";
+ EXPECT_EQ(0, memcmp(code_buffer, expect_code, strlen(expect_code)));
}
int main(int argc, char *argv[]) {

Powered by Google App Engine
This is Rietveld 408576698