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

Side by Side Diff: third_party/WebKit/Source/platform/heap/HeapPage.h

Issue 2716383003: Better distribute the randomness of the Oilpan metadata canary. (Closed)
Patch Set: Rebase. Created 3 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 866
867 inline HeapObjectHeader* HeapObjectHeader::fromPayload(const void* payload) { 867 inline HeapObjectHeader* HeapObjectHeader::fromPayload(const void* payload) {
868 Address addr = reinterpret_cast<Address>(const_cast<void*>(payload)); 868 Address addr = reinterpret_cast<Address>(const_cast<void*>(payload));
869 HeapObjectHeader* header = 869 HeapObjectHeader* header =
870 reinterpret_cast<HeapObjectHeader*>(addr - sizeof(HeapObjectHeader)); 870 reinterpret_cast<HeapObjectHeader*>(addr - sizeof(HeapObjectHeader));
871 ASSERT(header->checkHeader()); 871 ASSERT(header->checkHeader());
872 return header; 872 return header;
873 } 873 }
874 874
875 #if CPU(64BIT) 875 #if CPU(64BIT)
876 ALWAYS_INLINE uint32_t RotateLeft16(uint32_t x) {
877 #if COMPILER(MSVC)
878 return _lrotr(x, 16);
879 #else
880 // http://blog.regehr.org/archives/1063
881 return (x << 16) | (x >> (-16 & 31));
882 #endif
883 }
884
876 inline uint32_t HeapObjectHeader::getMagic() const { 885 inline uint32_t HeapObjectHeader::getMagic() const {
877 const uintptr_t random1 = 886 // Ignore C4319: It is OK to 0-extend into the high-order bits of the uintptr_t
878 ~(reinterpret_cast<uintptr_t>( 887 // on 64-bit, in this case.
879 base::trace_event::MemoryAllocatorDump::kNameSize) >> 888 #if COMPILER(MSVC)
880 16); 889 #pragma warning(push)
890 #pragma warning(disable : 4319)
891 #endif
892
893 const uintptr_t random1 = ~(RotateLeft16(reinterpret_cast<uintptr_t>(
894 base::trace_event::MemoryAllocatorDump::kNameSize)));
881 895
882 #if OS(WIN) 896 #if OS(WIN)
883 const uintptr_t random2 = ~(reinterpret_cast<uintptr_t>(::ReadFile) << 16); 897 const uintptr_t random2 =
898 ~(RotateLeft16(reinterpret_cast<uintptr_t>(::ReadFile)));
884 #elif OS(POSIX) 899 #elif OS(POSIX)
885 const uintptr_t random2 = ~(reinterpret_cast<uintptr_t>(::read) << 16); 900 const uintptr_t random2 =
901 ~(RotateLeft16(reinterpret_cast<uintptr_t>(::read)));
886 #else 902 #else
887 #error OS not supported 903 #error OS not supported
888 #endif 904 #endif
889 905
890 #if CPU(64BIT) 906 #if CPU(64BIT)
891 static_assert(sizeof(uintptr_t) == sizeof(uint64_t), 907 static_assert(sizeof(uintptr_t) == sizeof(uint64_t),
892 "uintptr_t is not uint64_t"); 908 "uintptr_t is not uint64_t");
893 const uint32_t random = static_cast<uint32_t>( 909 const uint32_t random = static_cast<uint32_t>(
894 (random1 & 0x0FFFFULL) | ((random2 >> 32) & 0x0FFFF0000ULL)); 910 (random1 & 0x0FFFFULL) | ((random2 >> 32) & 0x0FFFF0000ULL));
895 #elif CPU(32BIT) 911 #elif CPU(32BIT)
896 // Although we don't use heap metadata canaries on 32-bit due to memory 912 // Although we don't use heap metadata canaries on 32-bit due to memory
897 // pressure, keep this code around just in case we do, someday. 913 // pressure, keep this code around just in case we do, someday.
898 static_assert(sizeof(uintptr_t) == sizeof(uint32_t), 914 static_assert(sizeof(uintptr_t) == sizeof(uint32_t),
899 "uintptr_t is not uint32_t"); 915 "uintptr_t is not uint32_t");
900 const uint32_t random = (random1 & 0x0FFFFUL) | (random2 & 0xFFFF0000UL); 916 const uint32_t random = (random1 & 0x0FFFFUL) | (random2 & 0xFFFF0000UL);
901 #else 917 #else
902 #error architecture not supported 918 #error architecture not supported
903 #endif 919 #endif
904 920
921 #if COMPILER(MSVC)
922 #pragma warning(pop)
923 #endif
924
905 return random; 925 return random;
906 } 926 }
907 #endif 927 #endif // CPU(64BIT)
908 928
909 NO_SANITIZE_ADDRESS inline bool HeapObjectHeader::isWrapperHeaderMarked() 929 NO_SANITIZE_ADDRESS inline bool HeapObjectHeader::isWrapperHeaderMarked()
910 const { 930 const {
911 ASSERT(checkHeader()); 931 ASSERT(checkHeader());
912 return m_encoded & headerWrapperMarkBitMask; 932 return m_encoded & headerWrapperMarkBitMask;
913 } 933 }
914 934
915 NO_SANITIZE_ADDRESS inline void HeapObjectHeader::markWrapperHeader() { 935 NO_SANITIZE_ADDRESS inline void HeapObjectHeader::markWrapperHeader() {
916 ASSERT(checkHeader()); 936 ASSERT(checkHeader());
917 ASSERT(!isWrapperHeaderMarked()); 937 ASSERT(!isWrapperHeaderMarked());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 return outOfLineAllocate(allocationSize, gcInfoIndex); 979 return outOfLineAllocate(allocationSize, gcInfoIndex);
960 } 980 }
961 981
962 inline NormalPageArena* NormalPage::arenaForNormalPage() const { 982 inline NormalPageArena* NormalPage::arenaForNormalPage() const {
963 return static_cast<NormalPageArena*>(arena()); 983 return static_cast<NormalPageArena*>(arena());
964 } 984 }
965 985
966 } // namespace blink 986 } // namespace blink
967 987
968 #endif // HeapPage_h 988 #endif // HeapPage_h
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698