| Index: src/trusted/validator/validation_rewrite_64_test.cc
|
| diff --git a/src/trusted/validator/validation_rewrite_64_test.cc b/src/trusted/validator/validation_rewrite_64_test.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3126c11cd42eff8497712d7ff56034b839825809
|
| --- /dev/null
|
| +++ b/src/trusted/validator/validation_rewrite_64_test.cc
|
| @@ -0,0 +1,138 @@
|
| +/*
|
| + * 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 <string.h>
|
| +#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
|
| +
|
| +extern "C" {
|
| + extern const char no_rewrite_code[];
|
| + extern const char no_rewrite_code_post_rewrite[];
|
| + extern const char prefetchnta_code[];
|
| + extern const char prefetchnta_code_post_rewrite[];
|
| + extern const char movntps_code[];
|
| + extern const char movntps_code_post_rewrite[];
|
| + extern const char movnti_code[];
|
| + extern const char movnti_code_post_rewrite[];
|
| + extern const char movnti_code2[];
|
| + extern const char movnti_code2_post_rewrite[];
|
| + extern const char movntdq_code[];
|
| + extern const char movntdq_code_post_rewrite[];
|
| + extern const char movntdq_code2[];
|
| + extern const char movntdq_code2_post_rewrite[];
|
| +}
|
| +
|
| +class ValidationMovntRewriteTests : 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(ValidationMovntRewriteTests, DisableNonTemporalsNoRewrite) {
|
| + memcpy(code_buffer, no_rewrite_code, strlen(no_rewrite_code));
|
| + NaClValidationStatus status = Validate(NACL_DISABLE_NONTEMPORALS_X86);
|
| + EXPECT_EQ(NaClValidationFailed, status);
|
| + EXPECT_EQ(0, memcmp(code_buffer,
|
| + no_rewrite_code_post_rewrite,
|
| + strlen(no_rewrite_code_post_rewrite)));
|
| +}
|
| +
|
| +TEST_F(ValidationMovntRewriteTests, RewritePrefetchnta) {
|
| + memcpy(code_buffer, prefetchnta_code, strlen(prefetchnta_code));
|
| + NaClValidationStatus status = Validate(0);
|
| + EXPECT_EQ(NaClValidationSucceeded, status);
|
| + EXPECT_EQ(0, memcmp(code_buffer,
|
| + prefetchnta_code_post_rewrite,
|
| + strlen(prefetchnta_code_post_rewrite)));
|
| +}
|
| +
|
| +TEST_F(ValidationMovntRewriteTests, RewriteMovntps) {
|
| + memcpy(code_buffer, movntps_code, strlen(movntps_code));
|
| + NaClValidationStatus status = Validate(0);
|
| + EXPECT_EQ(NaClValidationSucceeded, status);
|
| + EXPECT_EQ(0, memcmp(code_buffer,
|
| + movntps_code_post_rewrite,
|
| + strlen(movntps_code_post_rewrite)));
|
| +}
|
| +
|
| +TEST_F(ValidationMovntRewriteTests, RewriteMovnti) {
|
| + memcpy(code_buffer, movnti_code, strlen(movnti_code));
|
| + NaClValidationStatus status = Validate(0);
|
| + EXPECT_EQ(NaClValidationSucceeded, status);
|
| + EXPECT_EQ(0, memcmp(code_buffer,
|
| + movnti_code_post_rewrite,
|
| + strlen(movnti_code_post_rewrite)));
|
| +}
|
| +
|
| +TEST_F(ValidationMovntRewriteTests, RewriteMovnti2) {
|
| + memcpy(code_buffer, movnti_code2, strlen(movnti_code2));
|
| + NaClValidationStatus status = Validate(0);
|
| + EXPECT_EQ(NaClValidationSucceeded, status);
|
| + EXPECT_EQ(0, memcmp(code_buffer,
|
| + movnti_code2_post_rewrite,
|
| + strlen(movnti_code2_post_rewrite)));
|
| +}
|
| +
|
| +TEST_F(ValidationMovntRewriteTests, RewriteMovntdq) {
|
| + memcpy(code_buffer, movntdq_code, strlen(movntdq_code));
|
| + NaClValidationStatus status = Validate(0);
|
| + EXPECT_EQ(NaClValidationSucceeded, status);
|
| + EXPECT_EQ(0, memcmp(code_buffer,
|
| + movntdq_code_post_rewrite,
|
| + strlen(movntdq_code_post_rewrite)));
|
| +}
|
| +
|
| +TEST_F(ValidationMovntRewriteTests, RewriteMovntdq2) {
|
| + memcpy(code_buffer, movntdq_code2, strlen(movntdq_code2));
|
| + NaClValidationStatus status = Validate(0);
|
| + EXPECT_EQ(NaClValidationSucceeded, status);
|
| + EXPECT_EQ(0, memcmp(code_buffer,
|
| + movntdq_code2_post_rewrite,
|
| + strlen(movntdq_code2_post_rewrite)));
|
| +}
|
| +
|
| +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();
|
| +}
|
|
|