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

Side by Side Diff: src/trusted/validator/validation_disable_unsupported_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: Use 0 to represent normal validation in NaClValidationFlags 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 (c) 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 ValidationDisableUnsupportedTests : 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(ValidationDisableUnsupportedTests, NormalValidation) {
54 memcpy(code_buffer, movnti_code, MOVNTI_CODE_SIZE);
55 NaClValidationStatus status = Validate(0);
56 // If we are not disabling unsupported instructions, use the original
57 // validation rule, i.e., allow non-temporal writes. In future, we will do
58 // rewriting.
59 EXPECT_EQ(NaClValidationSucceeded, status);
60 // Code should not change.
61 EXPECT_EQ(0, memcmp(code_buffer, movnti_code, MOVNTI_CODE_SIZE));
62 }
63
64 TEST_F(ValidationDisableUnsupportedTests, DisableUnsupported) {
65 memcpy(code_buffer, movnti_code, MOVNTI_CODE_SIZE);
66 NaClValidationStatus status = Validate(DISABLE_UNSUPPORTED);
67 // Disable unsupported instructions, in this case, non-temporal writes.
68 EXPECT_EQ(NaClValidationFailed, status);
69 // Code should not change.
70 EXPECT_EQ(0, memcmp(code_buffer, movnti_code, MOVNTI_CODE_SIZE));
71 }
72
73 int main(int argc, char *argv[]) {
74 // The IllegalInst test touches the log mutex deep inside the validator.
75 // This causes an SEH exception to be thrown on Windows if the mutex is not
76 // initialized.
77 // http://code.google.com/p/nativeclient/issues/detail?id=1696
78 NaClLogModuleInit();
79 testing::InitGoogleTest(&argc, argv);
80 return RUN_ALL_TESTS();
81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698