diff options
author | wolfbeast <mcwerewolf@gmail.com> | 2018-04-19 12:08:25 +0200 |
---|---|---|
committer | wolfbeast <mcwerewolf@gmail.com> | 2018-04-19 12:08:25 +0200 |
commit | d7df65954a585e97ccee21fa9cb50cb116efddcc (patch) | |
tree | 9ed9a1f46f5d2e8373dcab553bad55b54bb8103b /js/src/jit/x86-shared/AssemblerBuffer-x86-shared.h | |
parent | ba71cc45fef6dfaecef8f5edf65ce1f1ff457624 (diff) | |
parent | 9135a11e8c8f0837738fd976b28d36a53fd1de27 (diff) | |
download | UXP-d7df65954a585e97ccee21fa9cb50cb116efddcc.tar UXP-d7df65954a585e97ccee21fa9cb50cb116efddcc.tar.gz UXP-d7df65954a585e97ccee21fa9cb50cb116efddcc.tar.lz UXP-d7df65954a585e97ccee21fa9cb50cb116efddcc.tar.xz UXP-d7df65954a585e97ccee21fa9cb50cb116efddcc.zip |
Merge branch 'ported-upstream'
Diffstat (limited to 'js/src/jit/x86-shared/AssemblerBuffer-x86-shared.h')
-rw-r--r-- | js/src/jit/x86-shared/AssemblerBuffer-x86-shared.h | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/js/src/jit/x86-shared/AssemblerBuffer-x86-shared.h b/js/src/jit/x86-shared/AssemblerBuffer-x86-shared.h index 8cb557784..fe678fc7d 100644 --- a/js/src/jit/x86-shared/AssemblerBuffer-x86-shared.h +++ b/js/src/jit/x86-shared/AssemblerBuffer-x86-shared.h @@ -68,6 +68,33 @@ namespace js { namespace jit { + // AllocPolicy for AssemblerBuffer. OOMs when trying to allocate more than + // MaxCodeBytesPerProcess bytes. Use private inheritance to make sure we + // explicitly have to expose SystemAllocPolicy methods. + class AssemblerBufferAllocPolicy : private SystemAllocPolicy + { + public: + using SystemAllocPolicy::checkSimulatedOOM; + using SystemAllocPolicy::reportAllocOverflow; + using SystemAllocPolicy::free_; + + template <typename T> T* pod_realloc(T* p, size_t oldSize, size_t newSize) { + static_assert(sizeof(T) == 1, + "AssemblerBufferAllocPolicy should only be used with byte vectors"); + MOZ_ASSERT(oldSize <= MaxCodeBytesPerProcess); + if (MOZ_UNLIKELY(newSize > MaxCodeBytesPerProcess)) + return nullptr; + return SystemAllocPolicy::pod_realloc<T>(p, oldSize, newSize); + } + template <typename T> T* pod_malloc(size_t numElems) { + static_assert(sizeof(T) == 1, + "AssemblerBufferAllocPolicy should only be used with byte vectors"); + if (MOZ_UNLIKELY(numElems > MaxCodeBytesPerProcess)) + return nullptr; + return SystemAllocPolicy::pod_malloc<T>(numElems); + } + }; + class AssemblerBuffer { template<size_t size, typename T> @@ -93,6 +120,9 @@ namespace jit { void ensureSpace(size_t space) { + // This should only be called with small |space| values to ensure + // we don't overflow below. + MOZ_ASSERT(space <= 16); if (MOZ_UNLIKELY(!m_buffer.reserve(m_buffer.length() + space))) oomDetected(); } @@ -168,7 +198,7 @@ namespace jit { m_buffer.clear(); } - PageProtectingVector<unsigned char, 256, SystemAllocPolicy> m_buffer; + PageProtectingVector<unsigned char, 256, AssemblerBufferAllocPolicy> m_buffer; bool m_oom; }; |