2017-06-01 12:13:05 -07:00
|
|
|
// Copyright 2017 The Crashpad Authors. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2017-09-22 09:14:52 -07:00
|
|
|
#include "util/linux/ptracer.h"
|
2017-06-01 12:13:05 -07:00
|
|
|
|
|
|
|
#include "build/build_config.h"
|
|
|
|
#include "gtest/gtest.h"
|
2017-12-11 10:23:17 -08:00
|
|
|
#include "test/linux/get_tls.h"
|
2017-06-01 12:13:05 -07:00
|
|
|
#include "test/multiprocess.h"
|
|
|
|
#include "util/file/file_io.h"
|
2017-09-22 09:14:52 -07:00
|
|
|
#include "util/linux/scoped_ptrace_attach.h"
|
2017-06-01 12:13:05 -07:00
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
namespace test {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class SameBitnessTest : public Multiprocess {
|
|
|
|
public:
|
|
|
|
SameBitnessTest() : Multiprocess() {}
|
|
|
|
~SameBitnessTest() {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void MultiprocessParent() override {
|
|
|
|
LinuxVMAddress expected_tls;
|
|
|
|
CheckedReadFileExactly(
|
|
|
|
ReadPipeHandle(), &expected_tls, sizeof(expected_tls));
|
|
|
|
|
|
|
|
#if defined(ARCH_CPU_64_BITS)
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr bool am_64_bit = true;
|
2017-06-01 12:13:05 -07:00
|
|
|
#else
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr bool am_64_bit = false;
|
2017-06-01 12:13:05 -07:00
|
|
|
#endif // ARCH_CPU_64_BITS
|
|
|
|
|
2017-09-22 09:14:52 -07:00
|
|
|
ScopedPtraceAttach attach;
|
|
|
|
ASSERT_TRUE(attach.ResetAttach(ChildPID()));
|
|
|
|
|
2017-12-11 10:23:17 -08:00
|
|
|
Ptracer ptracer(am_64_bit, /* can_log= */ true);
|
2017-06-01 12:13:05 -07:00
|
|
|
|
2017-09-22 09:14:52 -07:00
|
|
|
EXPECT_EQ(ptracer.Is64Bit(), am_64_bit);
|
|
|
|
|
|
|
|
ThreadInfo thread_info;
|
|
|
|
ASSERT_TRUE(ptracer.GetThreadInfo(ChildPID(), &thread_info));
|
2017-06-01 12:13:05 -07:00
|
|
|
|
|
|
|
#if defined(ARCH_CPU_X86_64)
|
2017-09-22 09:14:52 -07:00
|
|
|
EXPECT_EQ(thread_info.thread_context.t64.fs_base, expected_tls);
|
2017-06-01 12:13:05 -07:00
|
|
|
#endif // ARCH_CPU_X86_64
|
|
|
|
|
2017-09-22 09:14:52 -07:00
|
|
|
EXPECT_EQ(thread_info.thread_specific_data_address, expected_tls);
|
2017-06-01 12:13:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void MultiprocessChild() override {
|
2017-12-11 10:23:17 -08:00
|
|
|
LinuxVMAddress expected_tls = GetTLS();
|
2017-06-01 12:13:05 -07:00
|
|
|
CheckedWriteFile(WritePipeHandle(), &expected_tls, sizeof(expected_tls));
|
|
|
|
|
|
|
|
CheckedReadFileAtEOF(ReadPipeHandle());
|
|
|
|
}
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(SameBitnessTest);
|
|
|
|
};
|
|
|
|
|
2017-09-22 09:14:52 -07:00
|
|
|
TEST(Ptracer, SameBitness) {
|
2017-06-01 12:13:05 -07:00
|
|
|
SameBitnessTest test;
|
|
|
|
test.Run();
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(jperaza): Test against a process with different bitness.
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
} // namespace test
|
|
|
|
} // namespace crashpad
|