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

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

Issue 1234393005: A mechanism to identify/forbid/"rewrite" non-temporal instructions (and other) (Closed) Base URL: https://chromium.googlesource.com/native_client/src/native_client.git@master
Patch Set: Fixing nits Created 5 years, 5 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_disable_nontemporals_test.cc
diff --git a/src/trusted/validator/validation_disable_nontemporals_test.cc b/src/trusted/validator/validation_disable_nontemporals_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1949917a572c44e4e8bd983edb319e59daf45aa6
--- /dev/null
+++ b/src/trusted/validator/validation_disable_nontemporals_test.cc
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2015 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.
+ */
+
+#include "gtest/gtest.h"
+
+#include "native_client/src/shared/platform/nacl_log.h"
+#include "native_client/src/shared/utils/types.h"
+#include "native_client/src/trusted/validator/ncvalidate.h"
+
+#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 {
+ protected:
+ NaClValidationMetadata *metadata_ptr;
+ const struct NaClValidatorInterface *validator;
+ NaClCPUFeatures *cpu_features;
+
+ unsigned char code_buffer[CODE_SIZE];
+
+ void SetUp() {
+ metadata_ptr = NULL;
+ validator = NaClCreateValidator();
+ cpu_features = (NaClCPUFeatures *) malloc(validator->CPUFeatureSize);
+ EXPECT_NE(cpu_features, (NaClCPUFeatures *) NULL);
+ memset(cpu_features, 0, validator->CPUFeatureSize);
+ validator->SetAllCPUFeatures(cpu_features);
+ memset(code_buffer, NOP, sizeof(code_buffer));
+ }
+
+ NaClValidationStatus Validate(uint32_t flags) {
+ return validator->Validate(0, code_buffer, 32,
+ FALSE, /* stubout_mode */
+ flags,
+ FALSE, /* readonly_test */
+ cpu_features,
+ metadata_ptr,
+ NULL);
+ }
+
+ void TearDown() {
+ free(cpu_features);
+ }
+};
+
+TEST_F(ValidationDisableNonTemporalsTests, NotDisableNonTemporals) {
+ memcpy(code_buffer, movnti_code, MOVNTI_CODE_SIZE);
+ 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));
+}
+
+TEST_F(ValidationDisableNonTemporalsTests, DisableNonTemporals) {
+ memcpy(code_buffer, movnti_code, MOVNTI_CODE_SIZE);
+ NaClValidationStatus status = Validate(DISABLE_NONTEMPORALS);
+ // Disable non-temporal instructions.
+ EXPECT_EQ(NaClValidationFailed, status);
+ // Code should not change.
+ EXPECT_EQ(0, memcmp(code_buffer, movnti_code, MOVNTI_CODE_SIZE));
+}
+
+int main(int argc, char *argv[]) {
+ // The IllegalInst test touches the log mutex deep inside the validator.
+ // This causes an SEH exception to be thrown on Windows if the mutex is not
+ // initialized.
+ // http://code.google.com/p/nativeclient/issues/detail?id=1696
+ NaClLogModuleInit();
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}

Powered by Google App Engine
This is Rietveld 408576698