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

Side by Side 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, 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 unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7 #include "gtest/gtest.h"
8
9 #include "native_client/src/shared/platform/nacl_log.h"
10 #include "native_client/src/shared/utils/types.h"
11 #include "native_client/src/trusted/validator/ncvalidate.h"
12
13 #define CODE_SIZE 32
14 #define NOP 0x90
15 #define MOVNTI_CODE_SIZE 8
16
17 // mov %edi,%edi; movnti %rax,0x68(%r15,%rdi,1)
18 const char* movnti_code = "\x89\xff\x49\x0f\xc3\x44\x3f\x68";
19
20 class ValidationDisableNonTemporalsTests : public ::testing::Test {
21 protected:
22 NaClValidationMetadata *metadata_ptr;
23 const struct NaClValidatorInterface *validator;
24 NaClCPUFeatures *cpu_features;
25
26 unsigned char code_buffer[CODE_SIZE];
27
28 void SetUp() {
29 metadata_ptr = NULL;
30 validator = NaClCreateValidator();
31 cpu_features = (NaClCPUFeatures *) malloc(validator->CPUFeatureSize);
32 EXPECT_NE(cpu_features, (NaClCPUFeatures *) NULL);
33 memset(cpu_features, 0, validator->CPUFeatureSize);
34 validator->SetAllCPUFeatures(cpu_features);
35 memset(code_buffer, NOP, sizeof(code_buffer));
36 }
37
38 NaClValidationStatus Validate(uint32_t flags) {
39 return validator->Validate(0, code_buffer, 32,
40 FALSE, /* stubout_mode */
41 flags,
42 FALSE, /* readonly_test */
43 cpu_features,
44 metadata_ptr,
45 NULL);
46 }
47
48 void TearDown() {
49 free(cpu_features);
50 }
51 };
52
53 TEST_F(ValidationDisableNonTemporalsTests, NotDisableNonTemporals) {
54 memcpy(code_buffer, movnti_code, MOVNTI_CODE_SIZE);
55 NaClValidationStatus status = Validate(0);
56 // If we are not disabling non-temporal instructions, use the original
57 // validation rule, i.e., allow them. In future, we will do rewriting.
58 EXPECT_EQ(NaClValidationSucceeded, status);
59 // Code should not change.
60 EXPECT_EQ(0, memcmp(code_buffer, movnti_code, MOVNTI_CODE_SIZE));
61 }
62
63 TEST_F(ValidationDisableNonTemporalsTests, DisableNonTemporals) {
64 memcpy(code_buffer, movnti_code, MOVNTI_CODE_SIZE);
65 NaClValidationStatus status = Validate(DISABLE_NONTEMPORALS);
66 // Disable non-temporal instructions.
67 EXPECT_EQ(NaClValidationFailed, status);
68 // Code should not change.
69 EXPECT_EQ(0, memcmp(code_buffer, movnti_code, MOVNTI_CODE_SIZE));
70 }
71
72 int main(int argc, char *argv[]) {
73 // The IllegalInst test touches the log mutex deep inside the validator.
74 // This causes an SEH exception to be thrown on Windows if the mutex is not
75 // initialized.
76 // http://code.google.com/p/nativeclient/issues/detail?id=1696
77 NaClLogModuleInit();
78 testing::InitGoogleTest(&argc, argv);
79 return RUN_ALL_TESTS();
80 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698