⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 249221 in webkit


Ignore:
Timestamp:
Aug 28, 2019, 2:24:47 PM (7 years ago)
Author:
mark.lam@apple.com
Message:

Wasm's AirIRGenerator::addLocal() and B3IRGenerator::addLocal() are doing unnecessary overflow checks.
https://bugs.webkit.org/show_bug.cgi?id=201006
<rdar://problem/52053991>

Reviewed by Yusuke Suzuki.

We already ensured that it is not possible to overflow in Wasm::FunctionParser's
parse(). It is unnecessary and misleading to do those overflow checks in
AirIRGenerator and B3IRGenerator. The only check that is necessary is that
m_locals.tryReserveCapacity() is successful, otherwise, we have an out of memory
situation.

This patch changes these unnecessary checks to assertions instead.

  • wasm/WasmAirIRGenerator.cpp:

(JSC::Wasm::AirIRGenerator::addLocal):

  • wasm/WasmB3IRGenerator.cpp:

(JSC::Wasm::B3IRGenerator::addLocal):

  • wasm/WasmValidate.cpp:

(JSC::Wasm::Validate::addLocal):

Location:
trunk/Source/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r249208 r249221  
     12019-08-28  Mark Lam  <mark.lam@apple.com>
     2
     3        Wasm's AirIRGenerator::addLocal() and B3IRGenerator::addLocal() are doing unnecessary overflow checks.
     4        https://bugs.webkit.org/show_bug.cgi?id=201006
     5        <rdar://problem/52053991>
     6
     7        Reviewed by Yusuke Suzuki.
     8
     9        We already ensured that it is not possible to overflow in Wasm::FunctionParser's
     10        parse().  It is unnecessary and misleading to do those overflow checks in
     11        AirIRGenerator and B3IRGenerator.  The only check that is necessary is that
     12        m_locals.tryReserveCapacity() is successful, otherwise, we have an out of memory
     13        situation.
     14
     15        This patch changes these unnecessary checks to assertions instead.
     16
     17        * wasm/WasmAirIRGenerator.cpp:
     18        (JSC::Wasm::AirIRGenerator::addLocal):
     19        * wasm/WasmB3IRGenerator.cpp:
     20        (JSC::Wasm::B3IRGenerator::addLocal):
     21        * wasm/WasmValidate.cpp:
     22        (JSC::Wasm::Validate::addLocal):
     23
    1242019-08-28  Keith Rollin  <krollin@apple.com>
    225
  • trunk/Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp

    r249159 r249221  
    915915auto AirIRGenerator::addLocal(Type type, uint32_t count) -> PartialResult
    916916{
    917     Checked<uint32_t, RecordOverflow> totalBytesChecked = count;
    918     totalBytesChecked += m_locals.size();
    919     uint32_t totalBytes;
    920     WASM_COMPILE_FAIL_IF((totalBytesChecked.safeGet(totalBytes) == CheckedState::DidOverflow) || !m_locals.tryReserveCapacity(totalBytes), "can't allocate memory for ", totalBytes, " locals");
     917    size_t newSize = m_locals.size() + count;
     918    ASSERT(!(CheckedUint32(count) + m_locals.size()).hasOverflowed());
     919    ASSERT(newSize <= maxFunctionLocals);
     920    WASM_COMPILE_FAIL_IF(!m_locals.tryReserveCapacity(newSize), "can't allocate memory for ", newSize, " locals");
    921921
    922922    for (uint32_t i = 0; i < count; ++i) {
  • trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp

    r248878 r249221  
    659659auto B3IRGenerator::addLocal(Type type, uint32_t count) -> PartialResult
    660660{
    661     Checked<uint32_t, RecordOverflow> totalBytesChecked = count;
    662     totalBytesChecked += m_locals.size();
    663     uint32_t totalBytes;
    664     WASM_COMPILE_FAIL_IF((totalBytesChecked.safeGet(totalBytes) == CheckedState::DidOverflow) || !m_locals.tryReserveCapacity(totalBytes), "can't allocate memory for ", totalBytes, " locals");
     661    size_t newSize = m_locals.size() + count;
     662    ASSERT(!(CheckedUint32(count) + m_locals.size()).hasOverflowed());
     663    ASSERT(newSize <= maxFunctionLocals);
     664    WASM_COMPILE_FAIL_IF(!m_locals.tryReserveCapacity(newSize), "can't allocate memory for ", newSize, " locals");
    665665
    666666    for (uint32_t i = 0; i < count; ++i) {
  • trunk/Source/JavaScriptCore/wasm/WasmValidate.cpp

    r248878 r249221  
    250250auto Validate::addLocal(Type type, uint32_t count) -> Result
    251251{
    252     size_t size = m_locals.size() + count;
    253     WASM_VALIDATOR_FAIL_IF(!m_locals.tryReserveCapacity(size), "can't allocate memory for ", size, " locals");
     252    size_t newSize = m_locals.size() + count;
     253    ASSERT(!(CheckedUint32(count) + m_locals.size()).hasOverflowed());
     254    ASSERT(newSize <= maxFunctionLocals);
     255    WASM_VALIDATOR_FAIL_IF(!m_locals.tryReserveCapacity(newSize), "can't allocate memory for ", newSize, " locals");
    254256
    255257    for (uint32_t i = 0; i < count; ++i)
Note: See TracChangeset for help on using the changeset viewer.