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

Side by Side Diff: src/trusted/validator/validation_pnacl_mode_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: Renaming 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 unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 2 * Copyright (c) 2015 The Native Client Authors. All rights reserved.
3 3 * Use of this source code is governed by a BSD-style license that can be
4 4 * found in the LICENSE file.
5 5 */
Petr Hosek 2015/07/20 23:58:57 Please remove the line numbers.
ruiq 2015/07/21 02:52:24 Done.
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
16
17 class ValidationPnaclModeTests : public ::testing::Test {
Petr Hosek 2015/07/20 23:58:57 Nit: Please use PNaCl, not Pnacl.
ruiq 2015/07/21 02:52:24 Done.
18 protected:
19 NaClValidationMetadata *metadata_ptr;
20 const struct NaClValidatorInterface *validator;
21 NaClCPUFeatures *cpu_features;
22
23 unsigned char code_buffer[CODE_SIZE];
24
25 void SetUp() {
26 metadata_ptr = NULL;
27 validator = NaClCreateValidator();
28 cpu_features = (NaClCPUFeatures *) malloc(validator->CPUFeatureSize);
29 EXPECT_NE(cpu_features, (NaClCPUFeatures *) NULL);
30 memset(cpu_features, 0, validator->CPUFeatureSize);
31 validator->SetAllCPUFeatures(cpu_features);
32
33 memset(code_buffer, NOP, sizeof(code_buffer));
34 }
35
36 NaClValidationStatus Validate(int pnacl_mode) {
37 return validator->Validate(0, code_buffer, 32,
38 FALSE, /* stubout_mode */
39 pnacl_mode,
40 FALSE, /* readonly_test */
41 cpu_features,
42 metadata_ptr,
43 NULL);
44 }
45
46 void TearDown() {
47 free(cpu_features);
48 }
49 };
50
51 // mov %edi,%edi; movnti %rax,0x68(%r15,%rdi,1)
52 const char* movnti_code = "\x89\xff\x49\x0f\xc3\x44\x3f\x68";
53
54 TEST_F(ValidationPnaclModeTests, movnti_non_pnacl_mode) {
55 memcpy(code_buffer, movnti_code, 8);
56 NaClValidationStatus status = Validate(0);
57 // In non-pnacl mode: use the original validation rule, i.e., allow
58 // non-temporal writes. In future, we will do rewriting.
59 EXPECT_EQ(NaClValidationSucceeded, status);
60 // Code should not change.
61 EXPECT_EQ(0, memcmp(code_buffer, movnti_code, 8));
62 }
63
64 TEST_F(ValidationPnaclModeTests, movnti_pnacl_mode) {
65 memcpy(code_buffer, movnti_code, 8);
66 NaClValidationStatus status = Validate(1);
67 // In pnacl mode: forbid non-temporal writes.
68 EXPECT_EQ(NaClValidationFailed, status);
69 // Code should not change.
70 EXPECT_EQ(0, memcmp(code_buffer, movnti_code, 8));
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