mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 01:48:05 +00:00
Bug 1305360 - Part 1: Add a mechanism to allow users to opt out of protection for small buffers. r=jandem
This commit is contained in:
parent
9d1424da43
commit
966212c4e6
@ -58,6 +58,13 @@ class PageProtectingVector final
|
||||
*/
|
||||
intptr_t unprotectedBytes;
|
||||
|
||||
/*
|
||||
* The size in bytes that a buffer needs to be before its pages will be
|
||||
* protected. This is intended to reduce churn for small vectors while
|
||||
* still offering protection when they grow large enough.
|
||||
*/
|
||||
size_t protectionLowerBound;
|
||||
|
||||
bool protectionEnabled;
|
||||
bool regionUnprotected;
|
||||
|
||||
@ -65,6 +72,8 @@ class PageProtectingVector final
|
||||
unprotectedBytes += offsetToPage;
|
||||
offsetToPage = (pageSize - (uintptr_t(vector.begin()) & pageMask)) & pageMask;
|
||||
unprotectedBytes -= offsetToPage;
|
||||
protectionEnabled = vector.capacity() >= protectionLowerBound &&
|
||||
vector.capacity() >= pageSize + offsetToPage;
|
||||
}
|
||||
|
||||
void protect() {
|
||||
@ -94,6 +103,10 @@ class PageProtectingVector final
|
||||
protect();
|
||||
}
|
||||
|
||||
void unprotectOldBuffer() {
|
||||
unprotect();
|
||||
}
|
||||
|
||||
bool anyProtected(size_t first, size_t last) {
|
||||
return last >= offsetToPage && first < offsetToPage + protectedBytes;
|
||||
}
|
||||
@ -125,7 +138,7 @@ class PageProtectingVector final
|
||||
|
||||
void emplace(PageProtectingVector* holder) {
|
||||
vector = holder;
|
||||
vector->unprotect();
|
||||
vector->unprotectOldBuffer();
|
||||
}
|
||||
|
||||
explicit AutoUnprotect(PageProtectingVector* holder) {
|
||||
@ -146,23 +159,22 @@ class PageProtectingVector final
|
||||
offsetToPage(0),
|
||||
protectedBytes(0),
|
||||
unprotectedBytes(0),
|
||||
protectionLowerBound(0),
|
||||
protectionEnabled(false),
|
||||
regionUnprotected(false) { updateOffsetToPage(); }
|
||||
regionUnprotected(false) { protectNewBuffer(); }
|
||||
|
||||
~PageProtectingVector() { unprotect(); }
|
||||
~PageProtectingVector() { unprotectOldBuffer(); }
|
||||
|
||||
/* Enable protection for the entire buffer. */
|
||||
void enableProtection() {
|
||||
MOZ_ASSERT(!protectionEnabled);
|
||||
protectionEnabled = true;
|
||||
protectNewBuffer();
|
||||
}
|
||||
|
||||
/* Disable protection for the entire buffer. */
|
||||
void disableProtection() {
|
||||
MOZ_ASSERT(protectionEnabled);
|
||||
unprotect();
|
||||
protectionEnabled = false;
|
||||
/*
|
||||
* Sets the lower bound on the size, in bytes, that this vector's underlying
|
||||
* capacity has to be before its used pages will be protected.
|
||||
*/
|
||||
void setLowerBoundForProtection(size_t bytes) {
|
||||
if (protectionLowerBound != bytes) {
|
||||
unprotectOldBuffer();
|
||||
protectionLowerBound = bytes;
|
||||
protectNewBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -87,6 +87,8 @@ namespace jit {
|
||||
AssemblerBuffer()
|
||||
: m_oom(false)
|
||||
{
|
||||
// Provide memory protection once the buffer starts to get big.
|
||||
m_buffer.setLowerBoundForProtection(32 * 1024);
|
||||
}
|
||||
|
||||
void ensureSpace(size_t space)
|
||||
@ -139,9 +141,6 @@ namespace jit {
|
||||
return m_buffer.begin();
|
||||
}
|
||||
|
||||
void enableBufferProtection() { m_buffer.enableProtection(); }
|
||||
void disableBufferProtection() { m_buffer.disableProtection(); }
|
||||
|
||||
void unprotectDataRegion(size_t firstByteOffset, size_t lastByteOffset) {
|
||||
m_buffer.unprotectRegion(firstByteOffset, lastByteOffset);
|
||||
}
|
||||
|
@ -3851,9 +3851,6 @@ threeByteOpImmSimd("vblendps", VEX_PD, OP3_BLENDPS_VpsWpsIb, ESCAPE_3A, imm, off
|
||||
return m_formatter.append(other.m_formatter.buffer(), other.size());
|
||||
}
|
||||
|
||||
void enableBufferProtection() { m_formatter.enableBufferProtection(); }
|
||||
void disableBufferProtection() { m_formatter.disableBufferProtection(); }
|
||||
|
||||
void unprotectDataRegion(size_t firstByteOffset, size_t lastByteOffset) {
|
||||
m_formatter.unprotectDataRegion(firstByteOffset, lastByteOffset);
|
||||
}
|
||||
@ -5132,9 +5129,6 @@ threeByteOpImmSimd("vblendps", VEX_PD, OP3_BLENDPS_VpsWpsIb, ESCAPE_3A, imm, off
|
||||
return m_buffer.append(values, size);
|
||||
}
|
||||
|
||||
void enableBufferProtection() { m_buffer.enableBufferProtection(); }
|
||||
void disableBufferProtection() { m_buffer.disableBufferProtection(); }
|
||||
|
||||
void unprotectDataRegion(size_t firstByteOffset, size_t lastByteOffset) {
|
||||
m_buffer.unprotectDataRegion(firstByteOffset, lastByteOffset);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user