diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-28 23:33:56 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-28 23:33:56 +0000 |
commit | 47aa4a2169a954cfac4b0f19344e0a1884bdff49 (patch) | |
tree | 4b2a726620571e8a13be912bec6f7ef95fe303d9 /mojo | |
parent | de52676f1dce656fedc1407548fe8d32c61eed81 (diff) | |
download | chromium_src-47aa4a2169a954cfac4b0f19344e0a1884bdff49.zip chromium_src-47aa4a2169a954cfac4b0f19344e0a1884bdff49.tar.gz chromium_src-47aa4a2169a954cfac4b0f19344e0a1884bdff49.tar.bz2 |
Mojo: Fix Options struct alignment checking on Windows.
R=darin@chromium.org
Review URL: https://codereview.chromium.org/422093002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@286026 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo')
-rw-r--r-- | mojo/system/memory.cc | 27 | ||||
-rw-r--r-- | mojo/system/options_validation_unittest.cc | 5 |
2 files changed, 14 insertions, 18 deletions
diff --git a/mojo/system/memory.cc b/mojo/system/memory.cc index 9aa0f78..15f83f4 100644 --- a/mojo/system/memory.cc +++ b/mojo/system/memory.cc @@ -39,20 +39,6 @@ template void MOJO_SYSTEM_IMPL_EXPORT CheckUserPointer<4, 4>( const void*); template void MOJO_SYSTEM_IMPL_EXPORT CheckUserPointer<8, 8>( const void*); -// Notwithstanding the comments above about MSVS, whenever we expect an -// alignment of 8 for something of size 4, it's due to an explicit (e.g., -// #pragma align) alignment specification, which MSVS *does* respect. We want -// this in particular to check that various Options structs are aligned. -#if defined(COMPILER_MSVC) && defined(ARCH_CPU_32_BITS) -template <> -void MOJO_SYSTEM_IMPL_EXPORT CheckUserPointer<4, 8>( - const void* pointer) { - CHECK(pointer && reinterpret_cast<uintptr_t>(pointer) % 8 == 0); -} -#else -template MOJO_SYSTEM_IMPL_EXPORT void CheckUserPointer<4, 8>( - const void*); -#endif template <size_t size, size_t alignment> void MOJO_SYSTEM_IMPL_EXPORT CheckUserPointerWithCount(const void* pointer, @@ -82,8 +68,21 @@ template void MOJO_SYSTEM_IMPL_EXPORT CheckUserPointerWithSize<1>(const void*, size_t); template void MOJO_SYSTEM_IMPL_EXPORT CheckUserPointerWithSize<4>(const void*, size_t); +// Whereas the other |Check...()| functions are usually used with integral typs +// or arrays of integral types, this one is used with Options structs for which +// alignment has been explicitly been specified (using |MOJO_ALIGNAS()|), which +// MSVS *does* respect. +#if defined(COMPILER_MSVC) && defined(ARCH_CPU_32_BITS) +template <> +void MOJO_SYSTEM_IMPL_EXPORT CheckUserPointerWithSize<8>(const void* pointer, + size_t size) { + CHECK(size == 0 || + (!!pointer && reinterpret_cast<uintptr_t>(pointer) % 8 == 0)); +} +#else template void MOJO_SYSTEM_IMPL_EXPORT CheckUserPointerWithSize<8>(const void*, size_t); +#endif } // namespace internal } // namespace system diff --git a/mojo/system/options_validation_unittest.cc b/mojo/system/options_validation_unittest.cc index 615dac80..bf9570a 100644 --- a/mojo/system/options_validation_unittest.cc +++ b/mojo/system/options_validation_unittest.cc @@ -112,8 +112,6 @@ TEST(OptionsValidationTest, InvalidDeath) { { UserOptionsReader<TestOptions> reader( MakeUserPointer(reinterpret_cast<const TestOptions*>(1))); }, kMemoryCheckFailedRegex); -// TODO(vtl): Broken on Windows. Fix this! -#if 0 // Note: The current implementation checks the size only after checking the // alignment versus that required for the |uint32_t| size, so it won't die in // the expected way if you pass, e.g., 4. So we have to manufacture a valid @@ -121,14 +119,13 @@ TEST(OptionsValidationTest, InvalidDeath) { EXPECT_DEATH_IF_SUPPORTED( { uint32_t buffer[100] = {}; - TestOptions* options = (reinterpret_cast<uintptr_t>(buffer) % 4 == 0) ? + TestOptions* options = (reinterpret_cast<uintptr_t>(buffer) % 8 == 0) ? reinterpret_cast<TestOptions*>(&buffer[1]) : reinterpret_cast<TestOptions*>(&buffer[0]); options->struct_size = static_cast<uint32_t>(sizeof(TestOptions)); UserOptionsReader<TestOptions> reader(MakeUserPointer(options)); }, kMemoryCheckFailedRegex); -#endif } } // namespace |