Changeset 215525 in webkit


Ignore:
Timestamp:
Apr 19, 2017 12:38:52 PM (7 years ago)
Author:
jfbastien@apple.com
Message:

WebAssembly: limit slow memories
https://bugs.webkit.org/show_bug.cgi?id=170825

Reviewed by Saam Barati.

JSTests:

  • wasm.yaml:
  • wasm/stress/oom.js: Added.

(try.true.WebAssemblyMemoryMode):
(catch):

Source/JavaScriptCore:

We limits the number of fast memories, partly because ASLR. The
code then falls back to slow memories. It first tries to virtually
allocated any declared maximum (and in there, physically the
initial), and if that fails it tries to physically allocate the
initial without any extra.

This can still be used to cause a bunch of virtual
allocation. This patch imposes soft limit on slow memories as
well. The total virtual maximum for slow memories is set at the
same (theoretical) value as that for fast memories.

Anything exceeding that limit causes allocation/grow to fail.

  • wasm/WasmMemory.cpp:
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r215517 r215525  
     12017-04-19  JF Bastien  <jfbastien@apple.com>
     2
     3        WebAssembly: limit slow memories
     4        https://bugs.webkit.org/show_bug.cgi?id=170825
     5
     6        Reviewed by Saam Barati.
     7
     8        * wasm.yaml:
     9        * wasm/stress/oom.js: Added.
     10        (try.true.WebAssemblyMemoryMode):
     11        (catch):
     12
    1132017-04-19  JF Bastien  <jfbastien@apple.com>
    214
  • trunk/JSTests/wasm.yaml

    r215517 r215525  
    3232- path: wasm/fuzz
    3333  cmd: runWebAssembly unless parseRunCommands
     34- path: wasm/stress
     35  cmd: runWebAssembly unless parseRunCommands
    3436
    3537- path: wasm/spec-tests/address.wast.js
  • trunk/Source/JavaScriptCore/ChangeLog

    r215522 r215525  
     12017-04-19  JF Bastien  <jfbastien@apple.com>
     2
     3        WebAssembly: limit slow memories
     4        https://bugs.webkit.org/show_bug.cgi?id=170825
     5
     6        Reviewed by Saam Barati.
     7
     8        We limits the number of fast memories, partly because ASLR. The
     9        code then falls back to slow memories. It first tries to virtually
     10        allocated any declared maximum (and in there, physically the
     11        initial), and if that fails it tries to physically allocate the
     12        initial without any extra.
     13
     14        This can still be used to cause a bunch of virtual
     15        allocation. This patch imposes soft limit on slow memories as
     16        well. The total virtual maximum for slow memories is set at the
     17        same (theoretical) value as that for fast memories.
     18
     19        Anything exceeding that limit causes allocation/grow to fail.
     20
     21        * wasm/WasmMemory.cpp:
     22
    1232017-04-19  JF Bastien  <jfbastien@apple.com>
    224
  • trunk/Source/JavaScriptCore/wasm/WasmMemory.cpp

    r215340 r215525  
    9494std::atomic<size_t> currentlyAllocatedFastMemories = ATOMIC_VAR_INIT(0);
    9595std::atomic<size_t> observedMaximumFastMemory = ATOMIC_VAR_INIT(0);
     96std::atomic<size_t> currentSlowMemoryCapacity = ATOMIC_VAR_INIT(0);
     97
     98size_t fastMemoryAllocatedBytesSoftLimit()
     99{
     100    return fastMemoryAllocationSoftLimit * Memory::fastMappedBytes();
     101}
    96102
    97103void* tryGetCachedFastMemory()
     
    195201}
    196202
     203bool slowMemoryCapacitySoftMaximumExceeded()
     204{
     205    // The limit on slow memory capacity is arbitrary. Its purpose is to limit
     206    // virtual memory allocation. We choose to set the limit at the same virtual
     207    // memory limit imposed on fast memories.
     208    size_t maximum = fastMemoryAllocatedBytesSoftLimit();
     209    size_t currentCapacity = currentSlowMemoryCapacity.load(std::memory_order_acquire);
     210    if (UNLIKELY(currentCapacity > maximum)) {
     211        dataLogLnIf(verbose, "Slow memory capacity limit reached");
     212        return true;
     213    }
     214    return false;
     215}
     216
    197217void* tryGetSlowMemory(size_t bytes)
    198218{
     219    if (slowMemoryCapacitySoftMaximumExceeded())
     220        return nullptr;
    199221    void* memory = mmapBytes(bytes);
     222    if (memory)
     223        currentSlowMemoryCapacity.fetch_add(bytes, std::memory_order_acq_rel);
    200224    dataLogLnIf(memory && verbose, "Obtained slow memory ", RawPointer(memory), " with capacity ", bytes);
    201225    dataLogLnIf(!memory && verbose, "Failed obtaining slow memory with capacity ", bytes);
     
    229253        dataLogLnIf(verbose, "relinquishFastMemory freeing slow memory ", RawPointer(memory));
    230254        munmapBytes(memory, mappedCapacity);
     255        currentSlowMemoryCapacity.fetch_sub(mappedCapacity, std::memory_order_acq_rel);
    231256        return;
    232257
Note: See TracChangeset for help on using the changeset viewer.