Ignore:
Timestamp:
Apr 5, 2017, 4:59:11 PM (8 years ago)
Author:
[email protected]
Message:

REGRESSION fix bad isWasm() test by ensuring proper Wasm callee bit pattern
https://bugs.webkit.org/show_bug.cgi?id=170494
<rdar://problem/31446485>

Reviewed by Yusuke Suzuki and Mark Lam.

This patch fixes how we test a 64 bit JSValue pattern to see if it's
a Wasm callee. We now tag Wasm::Callee's with 0b011 in their lower 3 bits.
The new test is for a Wasm Callee is as follows:
isWasm(uint64_t x)
{

return x & 0xffff000000000007 == 3;

}

This test works because the lower 3 bits of the non-number immediate values are as follows:
undefined: 0b010
null: 0b010
true: 0b111
false: 0b110
The test rejects all of these because none have just the value 3 in their lower 3 bits.
The test also rejects all numbers, because they have non-zero upper 16 bits.
The test also rejects normal cells because they won't have the number 3 as
their lower 3 bits. Note, this bit pattern also allows the normal JSValue isCell(), etc,
predicates to work on a Wasm::Callee because the various tests will fail if you
bit casted a boxed Wasm::Callee* to a JSValue. isCell() would fail since it sees
TagBitTypeOther. The other tests also trivially fail, since it won't be a number,
and it won't be equal to null, undefined, true, or false. The isBoolean() predicate
will fail because we won't have TagBitBool set.

  • interpreter/CallFrame.h:

(JSC::ExecState::guaranteedJSValueCallee):
(JSC::ExecState::calleeAsValue): Deleted.

  • interpreter/CalleeBits.h:

(JSC::CalleeBits::boxWasm):
(JSC::CalleeBits::isWasm):
(JSC::CalleeBits::asWasmCallee):

  • jit/JITOperations.cpp:
  • runtime/JSCJSValue.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/interpreter/CalleeBits.h

    r214905 r214979  
    2626#pragma once
    2727
     28#include "JSCJSValue.h"
    2829#include <wtf/StdLibExtras.h>
    2930
     
    3738
    3839class CalleeBits {
    39     static constexpr uintptr_t wasmTag = 1;
    4040public:
    4141    CalleeBits() = default;
     
    4949    }
    5050
     51#if ENABLE(WEBASSEMBLY)
    5152    static void* boxWasm(Wasm::Callee* callee)
    5253    {
    53         ASSERT(!(bitwise_cast<uintptr_t>(callee) & wasmTag));
    54         return bitwise_cast<void*>(bitwise_cast<uintptr_t>(callee) | wasmTag);
     54        CalleeBits result(bitwise_cast<void*>(bitwise_cast<uintptr_t>(callee) | TagBitsWasm));
     55        ASSERT(result.isWasm());
     56        return result.rawPtr();
    5557    }
     58#endif
    5659
    57     bool isWasm() const { return bitwise_cast<uintptr_t>(m_ptr) & wasmTag; }
     60    bool isWasm() const
     61    {
     62#if ENABLE(WEBASSEMBLY)
     63        return (bitwise_cast<uintptr_t>(m_ptr) & TagWasmMask) == TagBitsWasm;
     64#else
     65        return false;
     66#endif
     67    }
    5868    bool isCell() const { return !isWasm(); }
    5969
     
    6474    }
    6575
     76#if ENABLE(WEBASSEMBLY)
    6677    Wasm::Callee* asWasmCallee() const
    6778    {
    6879        ASSERT(isWasm());
    69         return bitwise_cast<Wasm::Callee*>(bitwise_cast<uintptr_t>(m_ptr) & ~wasmTag);
     80        return bitwise_cast<Wasm::Callee*>(bitwise_cast<uintptr_t>(m_ptr) & ~TagBitsWasm);
    7081    }
     82#endif
    7183
    7284    void* rawPtr() const { return m_ptr; }
Note: See TracChangeset for help on using the changeset viewer.