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

Changeset 237470 in webkit


Ignore:
Timestamp:
Oct 26, 2018, 11:51:19 AM (8 years ago)
Author:
Alan Coon
Message:

Cherry-pick r236589. rdar://problem/45285669

Verify the contents of AssemblerBuffer on arm64e
​https://bugs.webkit.org/show_bug.cgi?id=190057
<rdar://problem/38916630>

Reviewed by Mark Lam.

JSTests:

  • stress/regress-189132.js:

Source/JavaScriptCore:

  • assembler/ARM64Assembler.h: (JSC::ARM64Assembler::ARM64Assembler): (JSC::ARM64Assembler::fillNops): (JSC::ARM64Assembler::link): (JSC::ARM64Assembler::linkJumpOrCall): (JSC::ARM64Assembler::linkCompareAndBranch): (JSC::ARM64Assembler::linkConditionalBranch): (JSC::ARM64Assembler::linkTestAndBranch): (JSC::ARM64Assembler::unlinkedCode): Deleted.
  • assembler/ARMAssembler.h: (JSC::ARMAssembler::fillNops):
  • assembler/ARMv7Assembler.h: (JSC::ARMv7Assembler::unlinkedCode): Deleted.
  • assembler/AbstractMacroAssembler.h: (JSC::AbstractMacroAssembler::emitNops): (JSC::AbstractMacroAssembler::AbstractMacroAssembler):
  • assembler/AssemblerBuffer.h: (JSC::ARM64EHash::ARM64EHash): (JSC::ARM64EHash::update): (JSC::ARM64EHash::hash const): (JSC::ARM64EHash::randomSeed const): (JSC::AssemblerBuffer::AssemblerBuffer): (JSC::AssemblerBuffer::putShort): (JSC::AssemblerBuffer::putIntUnchecked): (JSC::AssemblerBuffer::putInt): (JSC::AssemblerBuffer::hash const): (JSC::AssemblerBuffer::data const): (JSC::AssemblerBuffer::putIntegralUnchecked): (JSC::AssemblerBuffer::append): Deleted.
  • assembler/LinkBuffer.cpp: (JSC::LinkBuffer::copyCompactAndLinkCode):
  • assembler/MIPSAssembler.h: (JSC::MIPSAssembler::fillNops):
  • assembler/MacroAssemblerARM64.h: (JSC::MacroAssemblerARM64::jumpsToLink): (JSC::MacroAssemblerARM64::link): (JSC::MacroAssemblerARM64::unlinkedCode): Deleted.
  • assembler/MacroAssemblerARMv7.h: (JSC::MacroAssemblerARMv7::jumpsToLink): (JSC::MacroAssemblerARMv7::unlinkedCode): Deleted.
  • assembler/X86Assembler.h: (JSC::X86Assembler::fillNops):

Source/WTF:

  • wtf/PtrTag.h: (WTF::tagInt):

git-svn-id: ​https://svn.webkit.org/repository/webkit/trunk@236589 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Location:
branches/safari-606-branch
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-606-branch/JSTests/ChangeLog

    r237439 r237470  
     12018-10-23  Kocsen Chung  <kocsen_chung@apple.com>
     2
     3        Cherry-pick r236589. rdar://problem/45285669
     4
     5    Verify the contents of AssemblerBuffer on arm64e
     6    https://bugs.webkit.org/show_bug.cgi?id=190057
     7    <rdar://problem/38916630>
     8   
     9    Reviewed by Mark Lam.
     10   
     11    JSTests:
     12   
     13    * stress/regress-189132.js:
     14   
     15    Source/JavaScriptCore:
     16   
     17    * assembler/ARM64Assembler.h:
     18    (JSC::ARM64Assembler::ARM64Assembler):
     19    (JSC::ARM64Assembler::fillNops):
     20    (JSC::ARM64Assembler::link):
     21    (JSC::ARM64Assembler::linkJumpOrCall):
     22    (JSC::ARM64Assembler::linkCompareAndBranch):
     23    (JSC::ARM64Assembler::linkConditionalBranch):
     24    (JSC::ARM64Assembler::linkTestAndBranch):
     25    (JSC::ARM64Assembler::unlinkedCode): Deleted.
     26    * assembler/ARMAssembler.h:
     27    (JSC::ARMAssembler::fillNops):
     28    * assembler/ARMv7Assembler.h:
     29    (JSC::ARMv7Assembler::unlinkedCode): Deleted.
     30    * assembler/AbstractMacroAssembler.h:
     31    (JSC::AbstractMacroAssembler::emitNops):
     32    (JSC::AbstractMacroAssembler::AbstractMacroAssembler):
     33    * assembler/AssemblerBuffer.h:
     34    (JSC::ARM64EHash::ARM64EHash):
     35    (JSC::ARM64EHash::update):
     36    (JSC::ARM64EHash::hash const):
     37    (JSC::ARM64EHash::randomSeed const):
     38    (JSC::AssemblerBuffer::AssemblerBuffer):
     39    (JSC::AssemblerBuffer::putShort):
     40    (JSC::AssemblerBuffer::putIntUnchecked):
     41    (JSC::AssemblerBuffer::putInt):
     42    (JSC::AssemblerBuffer::hash const):
     43    (JSC::AssemblerBuffer::data const):
     44    (JSC::AssemblerBuffer::putIntegralUnchecked):
     45    (JSC::AssemblerBuffer::append): Deleted.
     46    * assembler/LinkBuffer.cpp:
     47    (JSC::LinkBuffer::copyCompactAndLinkCode):
     48    * assembler/MIPSAssembler.h:
     49    (JSC::MIPSAssembler::fillNops):
     50    * assembler/MacroAssemblerARM64.h:
     51    (JSC::MacroAssemblerARM64::jumpsToLink):
     52    (JSC::MacroAssemblerARM64::link):
     53    (JSC::MacroAssemblerARM64::unlinkedCode): Deleted.
     54    * assembler/MacroAssemblerARMv7.h:
     55    (JSC::MacroAssemblerARMv7::jumpsToLink):
     56    (JSC::MacroAssemblerARMv7::unlinkedCode): Deleted.
     57    * assembler/X86Assembler.h:
     58    (JSC::X86Assembler::fillNops):
     59   
     60    Source/WTF:
     61   
     62    * wtf/PtrTag.h:
     63    (WTF::tagInt):
     64   
     65    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236589 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     66
     67    2018-09-27  Saam barati  <sbarati@apple.com>
     68
     69            Verify the contents of AssemblerBuffer on arm64e
     70            https://bugs.webkit.org/show_bug.cgi?id=190057
     71            <rdar://problem/38916630>
     72
     73            Reviewed by Mark Lam.
     74
     75            * stress/regress-189132.js:
     76
    1772018-10-25  Kocsen Chung  <kocsen_chung@apple.com>
    278
  • branches/safari-606-branch/Source/JavaScriptCore/ChangeLog

    r237439 r237470  
     12018-10-23  Kocsen Chung  <kocsen_chung@apple.com>
     2
     3        Cherry-pick r236589. rdar://problem/45285669
     4
     5    Verify the contents of AssemblerBuffer on arm64e
     6    https://bugs.webkit.org/show_bug.cgi?id=190057
     7    <rdar://problem/38916630>
     8   
     9    Reviewed by Mark Lam.
     10   
     11    JSTests:
     12   
     13    * stress/regress-189132.js:
     14   
     15    Source/JavaScriptCore:
     16   
     17    * assembler/ARM64Assembler.h:
     18    (JSC::ARM64Assembler::ARM64Assembler):
     19    (JSC::ARM64Assembler::fillNops):
     20    (JSC::ARM64Assembler::link):
     21    (JSC::ARM64Assembler::linkJumpOrCall):
     22    (JSC::ARM64Assembler::linkCompareAndBranch):
     23    (JSC::ARM64Assembler::linkConditionalBranch):
     24    (JSC::ARM64Assembler::linkTestAndBranch):
     25    (JSC::ARM64Assembler::unlinkedCode): Deleted.
     26    * assembler/ARMAssembler.h:
     27    (JSC::ARMAssembler::fillNops):
     28    * assembler/ARMv7Assembler.h:
     29    (JSC::ARMv7Assembler::unlinkedCode): Deleted.
     30    * assembler/AbstractMacroAssembler.h:
     31    (JSC::AbstractMacroAssembler::emitNops):
     32    (JSC::AbstractMacroAssembler::AbstractMacroAssembler):
     33    * assembler/AssemblerBuffer.h:
     34    (JSC::ARM64EHash::ARM64EHash):
     35    (JSC::ARM64EHash::update):
     36    (JSC::ARM64EHash::hash const):
     37    (JSC::ARM64EHash::randomSeed const):
     38    (JSC::AssemblerBuffer::AssemblerBuffer):
     39    (JSC::AssemblerBuffer::putShort):
     40    (JSC::AssemblerBuffer::putIntUnchecked):
     41    (JSC::AssemblerBuffer::putInt):
     42    (JSC::AssemblerBuffer::hash const):
     43    (JSC::AssemblerBuffer::data const):
     44    (JSC::AssemblerBuffer::putIntegralUnchecked):
     45    (JSC::AssemblerBuffer::append): Deleted.
     46    * assembler/LinkBuffer.cpp:
     47    (JSC::LinkBuffer::copyCompactAndLinkCode):
     48    * assembler/MIPSAssembler.h:
     49    (JSC::MIPSAssembler::fillNops):
     50    * assembler/MacroAssemblerARM64.h:
     51    (JSC::MacroAssemblerARM64::jumpsToLink):
     52    (JSC::MacroAssemblerARM64::link):
     53    (JSC::MacroAssemblerARM64::unlinkedCode): Deleted.
     54    * assembler/MacroAssemblerARMv7.h:
     55    (JSC::MacroAssemblerARMv7::jumpsToLink):
     56    (JSC::MacroAssemblerARMv7::unlinkedCode): Deleted.
     57    * assembler/X86Assembler.h:
     58    (JSC::X86Assembler::fillNops):
     59   
     60    Source/WTF:
     61   
     62    * wtf/PtrTag.h:
     63    (WTF::tagInt):
     64   
     65    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236589 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     66
     67    2018-09-27  Saam barati  <sbarati@apple.com>
     68
     69            Verify the contents of AssemblerBuffer on arm64e
     70            https://bugs.webkit.org/show_bug.cgi?id=190057
     71            <rdar://problem/38916630>
     72
     73            Reviewed by Mark Lam.
     74
     75            * assembler/ARM64Assembler.h:
     76            (JSC::ARM64Assembler::ARM64Assembler):
     77            (JSC::ARM64Assembler::fillNops):
     78            (JSC::ARM64Assembler::link):
     79            (JSC::ARM64Assembler::linkJumpOrCall):
     80            (JSC::ARM64Assembler::linkCompareAndBranch):
     81            (JSC::ARM64Assembler::linkConditionalBranch):
     82            (JSC::ARM64Assembler::linkTestAndBranch):
     83            (JSC::ARM64Assembler::unlinkedCode): Deleted.
     84            * assembler/ARMAssembler.h:
     85            (JSC::ARMAssembler::fillNops):
     86            * assembler/ARMv7Assembler.h:
     87            (JSC::ARMv7Assembler::unlinkedCode): Deleted.
     88            * assembler/AbstractMacroAssembler.h:
     89            (JSC::AbstractMacroAssembler::emitNops):
     90            (JSC::AbstractMacroAssembler::AbstractMacroAssembler):
     91            * assembler/AssemblerBuffer.h:
     92            (JSC::ARM64EHash::ARM64EHash):
     93            (JSC::ARM64EHash::update):
     94            (JSC::ARM64EHash::hash const):
     95            (JSC::ARM64EHash::randomSeed const):
     96            (JSC::AssemblerBuffer::AssemblerBuffer):
     97            (JSC::AssemblerBuffer::putShort):
     98            (JSC::AssemblerBuffer::putIntUnchecked):
     99            (JSC::AssemblerBuffer::putInt):
     100            (JSC::AssemblerBuffer::hash const):
     101            (JSC::AssemblerBuffer::data const):
     102            (JSC::AssemblerBuffer::putIntegralUnchecked):
     103            (JSC::AssemblerBuffer::append): Deleted.
     104            * assembler/LinkBuffer.cpp:
     105            (JSC::LinkBuffer::copyCompactAndLinkCode):
     106            * assembler/MIPSAssembler.h:
     107            (JSC::MIPSAssembler::fillNops):
     108            * assembler/MacroAssemblerARM64.h:
     109            (JSC::MacroAssemblerARM64::jumpsToLink):
     110            (JSC::MacroAssemblerARM64::link):
     111            (JSC::MacroAssemblerARM64::unlinkedCode): Deleted.
     112            * assembler/MacroAssemblerARMv7.h:
     113            (JSC::MacroAssemblerARMv7::jumpsToLink):
     114            (JSC::MacroAssemblerARMv7::unlinkedCode): Deleted.
     115            * assembler/X86Assembler.h:
     116            (JSC::X86Assembler::fillNops):
     117
    11182018-10-25  Kocsen Chung  <kocsen_chung@apple.com>
    2119
  • branches/safari-606-branch/Source/JavaScriptCore/assembler/ARM64Assembler.h

    r237439 r237470  
    319319
    320320public:
    321     ARM64Assembler()
     321    ARM64Assembler(
     322#if CPU(ARM64E)
     323        unsigned randomNumber
     324#endif
     325        )
    322326        : m_indexOfLastWatchpoint(INT_MIN)
    323327        , m_indexOfTailOfLastWatchpoint(INT_MIN)
     328#if CPU(ARM64E)
     329        , m_buffer(randomNumber)
     330#endif
     331       
    324332    {
    325333    }
    … …  
    15551563    }
    15561564   
    1557     static void fillNops(void* base, size_t size, bool isCopyingToExecutableMemory)
     1565    template <typename CopyFunction>
     1566    static void fillNops(void* base, size_t size, CopyFunction copy)
    15581567    {
    15591568        RELEASE_ASSERT(!(size % sizeof(int32_t)));
    … …  
    15611570        for (int32_t* ptr = static_cast<int32_t*>(base); n--;) {
    15621571            int insn = nopPseudo();
    1563             if (isCopyingToExecutableMemory)
    1564                 performJITMemcpy(ptr++, &insn, sizeof(int));
    1565             else
    1566                 memcpy(ptr++, &insn, sizeof(int));
     1572            copy(ptr++, &insn, sizeof(int));
    15671573        }
    15681574    }
    … …  
    25692575    }
    25702576
    2571     void* unlinkedCode() { return m_buffer.data(); }
    25722577    size_t codeSize() const { return m_buffer.codeSize(); }
    25732578
    … …  
    26072612    }
    26082613
    2609     void linkJump(AssemblerLabel from, void* executableCode, AssemblerLabel to)
    2610     {
    2611         ASSERT(from.isSet());
    2612         ASSERT(to.isSet());
    2613         relinkJumpOrCall<false>(addressOf(from), addressOf(executableCode, from), addressOf(to));
    2614     }
    2615    
    26162614    static void linkJump(void* code, AssemblerLabel from, void* to)
    26172615    {
    … …  
    29662964    }
    29672965
    2968     static void ALWAYS_INLINE link(LinkRecord& record, uint8_t* from, const uint8_t* fromInstruction8, uint8_t* to)
     2966    typedef void* (*CopyFunction)(void*, const void*, size_t);
     2967
     2968    static void ALWAYS_INLINE link(LinkRecord& record, uint8_t* from, const uint8_t* fromInstruction8, uint8_t* to, CopyFunction copy)
    29692969    {
    29702970        const int* fromInstruction = reinterpret_cast<const int*>(fromInstruction8);
    29712971        switch (record.linkType()) {
    29722972        case LinkJumpNoCondition:
    2973             linkJumpOrCall<false>(reinterpret_cast<int*>(from), fromInstruction, to);
     2973            linkJumpOrCall<false>(reinterpret_cast<int*>(from), fromInstruction, to, copy);
    29742974            break;
    29752975        case LinkJumpConditionDirect:
    2976             linkConditionalBranch<true>(record.condition(), reinterpret_cast<int*>(from), fromInstruction, to);
     2976            linkConditionalBranch<true>(record.condition(), reinterpret_cast<int*>(from), fromInstruction, to, copy);
    29772977            break;
    29782978        case LinkJumpCondition:
    2979             linkConditionalBranch<false>(record.condition(), reinterpret_cast<int*>(from) - 1, fromInstruction - 1, to);
     2979            linkConditionalBranch<false>(record.condition(), reinterpret_cast<int*>(from) - 1, fromInstruction - 1, to, copy);
    29802980            break;
    29812981        case LinkJumpCompareAndBranchDirect:
    2982             linkCompareAndBranch<true>(record.condition(), record.is64Bit(), record.compareRegister(), reinterpret_cast<int*>(from), fromInstruction, to);
     2982            linkCompareAndBranch<true>(record.condition(), record.is64Bit(), record.compareRegister(), reinterpret_cast<int*>(from), fromInstruction, to, copy);
    29832983            break;
    29842984        case LinkJumpCompareAndBranch:
    2985             linkCompareAndBranch<false>(record.condition(), record.is64Bit(), record.compareRegister(), reinterpret_cast<int*>(from) - 1, fromInstruction - 1, to);
     2985            linkCompareAndBranch<false>(record.condition(), record.is64Bit(), record.compareRegister(), reinterpret_cast<int*>(from) - 1, fromInstruction - 1, to, copy);
    29862986            break;
    29872987        case LinkJumpTestBitDirect:
    2988             linkTestAndBranch<true>(record.condition(), record.bitNumber(), record.compareRegister(), reinterpret_cast<int*>(from), fromInstruction, to);
     2988            linkTestAndBranch<true>(record.condition(), record.bitNumber(), record.compareRegister(), reinterpret_cast<int*>(from), fromInstruction, to, copy);
    29892989            break;
    29902990        case LinkJumpTestBit:
    2991             linkTestAndBranch<false>(record.condition(), record.bitNumber(), record.compareRegister(), reinterpret_cast<int*>(from) - 1, fromInstruction - 1, to);
     2991            linkTestAndBranch<false>(record.condition(), record.bitNumber(), record.compareRegister(), reinterpret_cast<int*>(from) - 1, fromInstruction - 1, to, copy);
    29922992            break;
    29932993        default:
    … …  
    30313031
    30323032    template<bool isCall>
    3033     static void linkJumpOrCall(int* from, const int* fromInstruction, void* to)
     3033    static void linkJumpOrCall(int* from, const int* fromInstruction, void* to, CopyFunction copy = performJITMemcpy)
    30343034    {
    30353035        bool link;
    … …  
    30473047
    30483048        int insn = unconditionalBranchImmediate(isCall, static_cast<int>(offset));
    3049         performJITMemcpy(from, &insn, sizeof(int));
     3049        copy(from, &insn, sizeof(int));
    30503050    }
    30513051
    30523052    template<bool isDirect>
    3053     static void linkCompareAndBranch(Condition condition, bool is64Bit, RegisterID rt, int* from, const int* fromInstruction, void* to)
     3053    static void linkCompareAndBranch(Condition condition, bool is64Bit, RegisterID rt, int* from, const int* fromInstruction, void* to, CopyFunction copy = performJITMemcpy)
    30543054    {
    30553055        ASSERT(!(reinterpret_cast<intptr_t>(from) & 3));
    … …  
    30633063        if (useDirect || isDirect) {
    30643064            int insn = compareAndBranchImmediate(is64Bit ? Datasize_64 : Datasize_32, condition == ConditionNE, static_cast<int>(offset), rt);
    3065             performJITMemcpy(from, &insn, sizeof(int));
     3065            copy(from, &insn, sizeof(int));
    30663066            if (!isDirect) {
    30673067                insn = nopPseudo();
    3068                 performJITMemcpy(from + 1, &insn, sizeof(int));
     3068                copy(from + 1, &insn, sizeof(int));
    30693069            }
    30703070        } else {
    30713071            int insn = compareAndBranchImmediate(is64Bit ? Datasize_64 : Datasize_32, invert(condition) == ConditionNE, 2, rt);
    3072             performJITMemcpy(from, &insn, sizeof(int));
    3073             linkJumpOrCall<false>(from + 1, fromInstruction + 1, to);
     3072            copy(from, &insn, sizeof(int));
     3073            linkJumpOrCall<false>(from + 1, fromInstruction + 1, to, copy);
    30743074        }
    30753075    }
    30763076
    30773077    template<bool isDirect>
    3078     static void linkConditionalBranch(Condition condition, int* from, const int* fromInstruction, void* to)
     3078    static void linkConditionalBranch(Condition condition, int* from, const int* fromInstruction, void* to, CopyFunction copy = performJITMemcpy)
    30793079    {
    30803080        ASSERT(!(reinterpret_cast<intptr_t>(from) & 3));
    … …  
    30883088        if (useDirect || isDirect) {
    30893089            int insn = conditionalBranchImmediate(static_cast<int>(offset), condition);
    3090             performJITMemcpy(from, &insn, sizeof(int));
     3090            copy(from, &insn, sizeof(int));
    30913091            if (!isDirect) {
    30923092                insn = nopPseudo();
    3093                 performJITMemcpy(from + 1, &insn, sizeof(int));
     3093                copy(from + 1, &insn, sizeof(int));
    30943094            }
    30953095        } else {
    30963096            int insn = conditionalBranchImmediate(2, invert(condition));
    3097             performJITMemcpy(from, &insn, sizeof(int));
    3098             linkJumpOrCall<false>(from + 1, fromInstruction + 1, to);
     3097            copy(from, &insn, sizeof(int));
     3098            linkJumpOrCall<false>(from + 1, fromInstruction + 1, to, copy);
    30993099        }
    31003100    }
    31013101
    31023102    template<bool isDirect>
    3103     static void linkTestAndBranch(Condition condition, unsigned bitNumber, RegisterID rt, int* from, const int* fromInstruction, void* to)
     3103    static void linkTestAndBranch(Condition condition, unsigned bitNumber, RegisterID rt, int* from, const int* fromInstruction, void* to, CopyFunction copy = performJITMemcpy)
    31043104    {
    31053105        ASSERT(!(reinterpret_cast<intptr_t>(from) & 3));
    … …  
    31143114        if (useDirect || isDirect) {
    31153115            int insn = testAndBranchImmediate(condition == ConditionNE, static_cast<int>(bitNumber), static_cast<int>(offset), rt);
    3116             performJITMemcpy(from, &insn, sizeof(int));
     3116            copy(from, &insn, sizeof(int));
    31173117            if (!isDirect) {
    31183118                insn = nopPseudo();
    3119                 performJITMemcpy(from + 1, &insn, sizeof(int));
     3119                copy(from + 1, &insn, sizeof(int));
    31203120            }
    31213121        } else {
    31223122            int insn = testAndBranchImmediate(invert(condition) == ConditionNE, static_cast<int>(bitNumber), 2, rt);
    3123             performJITMemcpy(from, &insn, sizeof(int));
    3124             linkJumpOrCall<false>(from + 1, fromInstruction + 1, to);
     3123            copy(from, &insn, sizeof(int));
     3124            linkJumpOrCall<false>(from + 1, fromInstruction + 1, to, copy);
    31253125        }
    31263126    }
    … …  
    31783178    {
    31793179        return reinterpret_cast<int*>(static_cast<char*>(code) + label.m_offset);
    3180     }
    3181 
    3182     int* addressOf(AssemblerLabel label)
    3183     {
    3184         return addressOf(m_buffer.data(), label);
    31853180    }
    31863181
    … …  
    37603755    }
    37613756
    3762     AssemblerBuffer m_buffer;
    37633757    Vector<LinkRecord, 0, UnsafeVectorOverflow> m_jumpsToLink;
    37643758    int m_indexOfLastWatchpoint;
    37653759    int m_indexOfTailOfLastWatchpoint;
     3760    AssemblerBuffer m_buffer;
    37663761
    37673762public:
  • branches/safari-606-branch/Source/JavaScriptCore/assembler/ARMAssembler.h

    r237439 r237470  
    751751        }
    752752
    753         static void fillNops(void* base, size_t size, bool isCopyingToExecutableMemory)
    754         {
    755             UNUSED_PARAM(isCopyingToExecutableMemory);
     753        template <typename CopyFunction>
     754        static void fillNops(void* base, size_t size, CopyFunction copy)
     755        {
     756            UNUSED_PARAM(copy);
    756757            RELEASE_ASSERT(!(size % sizeof(int32_t)));
    757758
  • branches/safari-606-branch/Source/JavaScriptCore/assembler/ARMv7Assembler.h

    r237439 r237470  
    20562056    }
    20572057
    2058     static void fillNops(void* base, size_t size, bool isCopyingToExecutableMemory)
     2058    template <typename CopyFunction>
     2059    static void fillNops(void* base, size_t size, CopyFunction copy)
    20592060    {
    20602061        RELEASE_ASSERT(!(size % sizeof(int16_t)));
    … …  
    20642065        for (size_t i = 0; i < num32s; i++) {
    20652066            const int32_t insn = nopPseudo32();
    2066             if (isCopyingToExecutableMemory)
    2067                 performJITMemcpy(ptr, &insn, sizeof(int32_t));
    2068             else
    2069                 memcpy(ptr, &insn, sizeof(int32_t));
     2067            copy(ptr, &insn, sizeof(int32_t));
    20702068            ptr += sizeof(int32_t);
    20712069        }
    … …  
    20762074        if (num16s) {
    20772075            const int16_t insn = nopPseudo16();
    2078             if (isCopyingToExecutableMemory)
    2079                 performJITMemcpy(ptr, &insn, sizeof(int16_t));
    2080             else
    2081                 memcpy(ptr, &insn, sizeof(int16_t));
     2076            copy(ptr, &insn, sizeof(int16_t));
    20822077        }
    20832078    }
    … …  
    22462241    }
    22472242
    2248     void* unlinkedCode() { return m_formatter.data(); }
    22492243    size_t codeSize() const { return m_formatter.codeSize(); }
    22502244
  • branches/safari-606-branch/Source/JavaScriptCore/assembler/AbstractMacroAssembler.h

    r237439 r237470  
    863863    }
    864864
    865     AssemblerType m_assembler;
    866    
    867865    template<PtrTag tag>
    868866    static void linkJump(void* code, Jump jump, CodeLocationLabel<tag> target)
    … …  
    963961    void emitNops(size_t memoryToFillWithNopsInBytes)
    964962    {
     963#if CPU(ARM64)
     964        RELEASE_ASSERT(memoryToFillWithNopsInBytes % 4 == 0);
     965        for (unsigned i = 0; i < memoryToFillWithNopsInBytes / 4; ++i)
     966            m_assembler.nop();
     967#else
    965968        AssemblerBuffer& buffer = m_assembler.buffer();
    966969        size_t startCodeSize = buffer.codeSize();
    967970        size_t targetCodeSize = startCodeSize + memoryToFillWithNopsInBytes;
    968971        buffer.ensureSpace(memoryToFillWithNopsInBytes);
    969         bool isCopyingToExecutableMemory = false;
    970         AssemblerType::fillNops(static_cast<char*>(buffer.data()) + startCodeSize, memoryToFillWithNopsInBytes, isCopyingToExecutableMemory);
     972        AssemblerType::fillNops(static_cast<char*>(buffer.data()) + startCodeSize, memoryToFillWithNopsInBytes, memcpy);
    971973        buffer.setCodeSize(targetCodeSize);
     974#endif
    972975    }
    973976
    … …  
    984987    AbstractMacroAssembler()
    985988        : m_randomSource(0)
     989#if CPU(ARM64E)
     990        , m_assembler(random())
     991#else
     992        , m_assembler()
     993#endif
    986994    {
    987995        invalidateAllTempRegisters();
    … …  
    9991007    bool m_randomSourceIsInitialized { false };
    10001008    WeakRandom m_randomSource;
     1009public:
     1010    AssemblerType m_assembler;
     1011protected:
    10011012
    10021013#if ENABLE(DFG_REGISTER_ALLOCATION_VALIDATION)
  • branches/safari-606-branch/Source/JavaScriptCore/assembler/AssemblerBuffer.h

    r237439 r237470  
    3434#include <wtf/Assertions.h>
    3535#include <wtf/FastMalloc.h>
     36#if CPU(ARM64E)
     37#include <wtf/PtrTag.h>
     38#endif
    3639#include <wtf/StdLibExtras.h>
    3740
    3841namespace JSC {
     42
     43    class LinkBuffer;
    3944
    4045    struct AssemblerLabel {
    … …  
    141146    };
    142147
     148#if CPU(ARM64E)
     149    class ARM64EHash {
     150    public:
     151        ARM64EHash(unsigned randomNumber)
     152            : m_hash(randomNumber)
     153            , m_randomSeed(randomNumber)
     154        { }
     155        ALWAYS_INLINE void update(unsigned value, uintptr_t index)
     156        {
     157            m_hash = tagInt((static_cast<uintptr_t>(value) + m_hash) ^ (m_hash >> 32), static_cast<PtrTag>(index));
     158        }
     159        uintptr_t hash() const { return m_hash; }
     160        unsigned randomSeed() const { return m_randomSeed; }
     161    private:
     162        uintptr_t m_hash;
     163        unsigned m_randomSeed;
     164    };
     165#endif
     166
    143167    class AssemblerBuffer {
    144168    public:
    145         AssemblerBuffer()
     169        AssemblerBuffer(
     170#if CPU(ARM64E)
     171            unsigned randomNumber
     172#endif
     173        )
    146174            : m_storage()
    147175            , m_index(0)
     176#if CPU(ARM64E)
     177            , m_hash(randomNumber)
     178#endif
    148179        {
    149180        }
    … …  
    165196        }
    166197
     198#if !CPU(ARM64)
    167199        void putByteUnchecked(int8_t value) { putIntegralUnchecked(value); }
    168200        void putByte(int8_t value) { putIntegral(value); }
    169201        void putShortUnchecked(int16_t value) { putIntegralUnchecked(value); }
    170202        void putShort(int16_t value) { putIntegral(value); }
     203        void putInt64Unchecked(int64_t value) { putIntegralUnchecked(value); }
     204        void putInt64(int64_t value) { putIntegral(value); }
     205#endif
    171206        void putIntUnchecked(int32_t value) { putIntegralUnchecked(value); }
    172207        void putInt(int32_t value) { putIntegral(value); }
    173         void putInt64Unchecked(int64_t value) { putIntegralUnchecked(value); }
    174         void putInt64(int64_t value) { putIntegral(value); }
    175 
    176         void* data() const
    177         {
    178             return m_storage.buffer();
    179         }
    180208
    181209        size_t codeSize() const
    … …  
    184212        }
    185213
     214#if !CPU(ARM64)
    186215        void setCodeSize(size_t index)
    187216        {
    … …  
    192221            ASSERT(m_index <= m_storage.capacity());
    193222        }
     223#endif
    194224
    195225        AssemblerLabel label() const
    … …  
    209239        // LocalWriter *CANNOT* be mixed with other types of access to AssemblerBuffer.
    210240        // AssemblerBuffer cannot be used until its LocalWriter goes out of scope.
     241#if !CPU(ARM64) // If we ever need to use this on arm64e, we would need to make the checksum aware of this.
    211242        class LocalWriter {
    212243        public:
    … …  
    251282#endif
    252283        };
     284#endif // !CPU(ARM64)
     285
     286#if CPU(ARM64E)
     287        ARM64EHash hash() const { return m_hash; }
     288#endif
     289
     290#if !CPU(ARM64) // If we were to define this on arm64e, we'd need a way to update the hash as we write directly into the buffer.
     291        void* data() const { return m_storage.buffer(); }
     292#endif
     293
    253294
    254295    protected:
    … …  
    267308        void putIntegralUnchecked(IntegralType value)
    268309        {
     310#if CPU(ARM64)
     311            static_assert(sizeof(value) == 4, "");
     312#if CPU(ARM64E)
     313            m_hash.update(value, m_index);
     314#endif
     315#endif
    269316            ASSERT(isAvailable(sizeof(IntegralType)));
    270317            *reinterpret_cast_ptr<IntegralType*>(m_storage.buffer() + m_index) = value;
    … …  
    272319        }
    273320
    274         void append(const char* data, int size)
    275         {
    276             if (!isAvailable(size))
    277                 grow(size);
    278 
    279             memcpy(m_storage.buffer() + m_index, data, size);
    280             m_index += size;
    281         }
    282 
     321    private:
    283322        void grow(int extraCapacity = 0)
    284323        {
    … …  
    286325        }
    287326
    288     private:
    289327        NEVER_INLINE void outOfLineGrow()
    290328        {
    … …  
    292330        }
    293331
     332#if !CPU(ARM64)
    294333        friend LocalWriter;
     334#endif
     335        friend LinkBuffer;
    295336
    296337        AssemblerData m_storage;
    297338        unsigned m_index;
     339#if CPU(ARM64E)
     340        ARM64EHash m_hash;
     341#endif
    298342    };
    299343
  • branches/safari-606-branch/Source/JavaScriptCore/assembler/LinkBuffer.cpp

    r237439 r237470  
    110110    uint8_t* inData = reinterpret_cast<uint8_t*>(m_assemblerStorage.buffer());
    111111
     112    uint8_t* codeOutData = m_code.dataLocation<uint8_t*>();
     113#if CPU(ARM64E)
     114    const ARM64EHash assemblerBufferHash = macroAssembler.m_assembler.buffer().hash();
     115    ARM64EHash verifyUncompactedHash(assemblerBufferHash.randomSeed());
     116    uint8_t* outData = codeOutData;
     117#else
    112118    AssemblerData outBuffer(m_size);
    113 
    114119    uint8_t* outData = reinterpret_cast<uint8_t*>(outBuffer.buffer());
    115     uint8_t* codeOutData = m_code.dataLocation<uint8_t*>();
     120#endif
    116121
    117122    int readPtr = 0;
    118123    int writePtr = 0;
    119124    unsigned jumpCount = jumpsToLink.size();
     125
     126#if CPU(ARM64E)
     127    os_thread_self_restrict_rwx_to_rw();
     128#endif
     129
    120130    if (m_shouldPerformBranchCompaction) {
    121131        for (unsigned i = 0; i < jumpCount; ++i) {
    … …  
    131141            ASSERT(!(readPtr % 2));
    132142            ASSERT(!(writePtr % 2));
    133             while (copySource != copyEnd)
    134                 *copyDst++ = *copySource++;
     143#if CPU(ARM64E)
     144            unsigned index = readPtr;
     145#endif
     146            while (copySource != copyEnd) {
     147                InstructionType insn = *copySource++;
     148#if CPU(ARM64E)
     149                static_assert(sizeof(InstructionType) == 4, "");
     150                verifyUncompactedHash.update(insn, index);
     151                index += sizeof(InstructionType);
     152#endif
     153                *copyDst++ = insn;
     154            }
    135155            recordLinkOffsets(m_assemblerStorage, readPtr, jumpsToLink[i].from(), offset);
    136156            readPtr += regionSize;
    … …  
    163183        }
    164184    }
     185
    165186    // Copy everything after the last jump
    166     memcpy(outData + writePtr, inData + readPtr, initialSize - readPtr);
     187    {
     188        InstructionType* dst = bitwise_cast<InstructionType*>(outData + writePtr);
     189        InstructionType* src = bitwise_cast<InstructionType*>(inData + readPtr);
     190        size_t bytes = initialSize - readPtr;
     191
     192        RELEASE_ASSERT(bitwise_cast<uintptr_t>(dst) % sizeof(InstructionType) == 0);
     193        RELEASE_ASSERT(bitwise_cast<uintptr_t>(src) % sizeof(InstructionType) == 0);
     194        RELEASE_ASSERT(bytes % sizeof(InstructionType) == 0);
     195
     196#if CPU(ARM64E)
     197        unsigned index = readPtr;
     198#endif
     199
     200        for (size_t i = 0; i < bytes; i += sizeof(InstructionType)) {
     201            InstructionType insn = *src++;
     202#if CPU(ARM64E)
     203            verifyUncompactedHash.update(insn, index);
     204            index += sizeof(InstructionType);
     205#endif
     206            *dst++ = insn;
     207        }
     208    }
     209
     210#if CPU(ARM64E)
     211    if (verifyUncompactedHash.hash() != assemblerBufferHash.hash()) {
     212        dataLogLn("Hashes don't match: ", RawPointer(bitwise_cast<void*>(verifyUncompactedHash.hash())), " ", RawPointer(bitwise_cast<void*>(assemblerBufferHash.hash())));
     213        dataLogLn("Crashing!");
     214        CRASH();
     215    }
     216#endif
     217
    167218    recordLinkOffsets(m_assemblerStorage, readPtr, initialSize, readPtr - writePtr);
    168219       
    169220    for (unsigned i = 0; i < jumpCount; ++i) {
     221#if CPU(ARM64E)
     222        auto memcpyFunction = memcpy;
     223#else
     224        auto memcpyFunction = performJITMemcpy;
     225#endif
     226
    170227        uint8_t* location = codeOutData + jumpsToLink[i].from();
    171228        uint8_t* target = codeOutData + jumpsToLink[i].to() - executableOffsetFor(jumpsToLink[i].to());
    172         MacroAssembler::link(jumpsToLink[i], outData + jumpsToLink[i].from(), location, target);
    173     }
    174 
    175     jumpsToLink.clear();
     229        MacroAssembler::link(jumpsToLink[i], outData + jumpsToLink[i].from(), location, target, memcpyFunction);
     230    }
    176231
    177232    size_t compactSize = writePtr + initialSize - readPtr;
     233    if (!m_executableMemory) {
     234        size_t nopSizeInBytes = initialSize - compactSize;
     235        MacroAssembler::AssemblerType_T::fillNops(outData + compactSize, nopSizeInBytes, memcpy);
     236    }
     237
     238#if CPU(ARM64E)
     239    os_thread_self_restrict_rwx_to_rx();
     240#endif
     241
    178242    if (m_executableMemory) {
    179243        m_size = compactSize;
    180244        m_executableMemory->shrink(m_size);
    181     } else {
    182         size_t nopSizeInBytes = initialSize - compactSize;
    183         bool isCopyingToExecutableMemory = false;
    184         MacroAssembler::AssemblerType_T::fillNops(outData + compactSize, nopSizeInBytes, isCopyingToExecutableMemory);
    185     }
    186 
     245    }
     246
     247#if !CPU(ARM64E)
     248    ASSERT(codeOutData != outData);
    187249    performJITMemcpy(codeOutData, outData, m_size);
     250#else
     251    ASSERT(codeOutData == outData);
     252#endif
     253
     254    jumpsToLink.clear();
    188255
    189256#if DUMP_LINK_STATISTICS
  • branches/safari-606-branch/Source/JavaScriptCore/assembler/MIPSAssembler.h

    r237439 r237470  
    265265    }
    266266   
    267     static void fillNops(void* base, size_t size, bool isCopyingToExecutableMemory)
    268     {
    269         UNUSED_PARAM(isCopyingToExecutableMemory);
     267    template <typename CopyFunction>
     268    static void fillNops(void* base, size_t size, CopyFunction copy)
     269    {
     270        UNUSED_PARAM(copy);
    270271        RELEASE_ASSERT(!(size % sizeof(int32_t)));
    271272
  • branches/safari-606-branch/Source/JavaScriptCore/assembler/MacroAssemblerARM64.h

    r237439 r237470  
    8080
    8181    Vector<LinkRecord, 0, UnsafeVectorOverflow>& jumpsToLink() { return m_assembler.jumpsToLink(); }
    82     void* unlinkedCode() { return m_assembler.unlinkedCode(); }
    8382    static bool canCompact(JumpType jumpType) { return Assembler::canCompact(jumpType); }
    8483    static JumpLinkType computeJumpType(JumpType jumpType, const uint8_t* from, const uint8_t* to) { return Assembler::computeJumpType(jumpType, from, to); }
    8584    static JumpLinkType computeJumpType(LinkRecord& record, const uint8_t* from, const uint8_t* to) { return Assembler::computeJumpType(record, from, to); }
    8685    static int jumpSizeDelta(JumpType jumpType, JumpLinkType jumpLinkType) { return Assembler::jumpSizeDelta(jumpType, jumpLinkType); }
    87     static void link(LinkRecord& record, uint8_t* from, const uint8_t* fromInstruction, uint8_t* to) { return Assembler::link(record, from, fromInstruction, to); }
     86    template <typename CopyFunction>
     87    static void link(LinkRecord& record, uint8_t* from, const uint8_t* fromInstruction, uint8_t* to, CopyFunction copy) { return Assembler::link(record, from, fromInstruction, to, copy); }
    8888
    8989    static const Scale ScalePtr = TimesEight;
  • branches/safari-606-branch/Source/JavaScriptCore/assembler/MacroAssemblerARMv7.h

    r237439 r237470  
    6666
    6767    Vector<LinkRecord, 0, UnsafeVectorOverflow>& jumpsToLink() { return m_assembler.jumpsToLink(); }
    68     void* unlinkedCode() { return m_assembler.unlinkedCode(); }
    6968    static bool canCompact(JumpType jumpType) { return ARMv7Assembler::canCompact(jumpType); }
    7069    static JumpLinkType computeJumpType(JumpType jumpType, const uint8_t* from, const uint8_t* to) { return ARMv7Assembler::computeJumpType(jumpType, from, to); }
  • branches/safari-606-branch/Source/JavaScriptCore/assembler/X86Assembler.h

    r237439 r237470  
    39033903    }
    39043904
    3905     static void fillNops(void* base, size_t size, bool isCopyingToExecutableMemory)
    3906     {
    3907         UNUSED_PARAM(isCopyingToExecutableMemory);
     3905    template <typename CopyFunction>
     3906    static void fillNops(void* base, size_t size, CopyFunction copy)
     3907    {
     3908        UNUSED_PARAM(copy);
    39083909#if CPU(X86_64)
    39093910        static const uint8_t nops[10][10] = {
  • branches/safari-606-branch/Source/WTF/ChangeLog

    r237439 r237470  
     12018-10-23  Kocsen Chung  <kocsen_chung@apple.com>
     2
     3        Cherry-pick r236589. rdar://problem/45285669
     4
     5    Verify the contents of AssemblerBuffer on arm64e
     6    https://bugs.webkit.org/show_bug.cgi?id=190057
     7    <rdar://problem/38916630>
     8   
     9    Reviewed by Mark Lam.
     10   
     11    JSTests:
     12   
     13    * stress/regress-189132.js:
     14   
     15    Source/JavaScriptCore:
     16   
     17    * assembler/ARM64Assembler.h:
     18    (JSC::ARM64Assembler::ARM64Assembler):
     19    (JSC::ARM64Assembler::fillNops):
     20    (JSC::ARM64Assembler::link):
     21    (JSC::ARM64Assembler::linkJumpOrCall):
     22    (JSC::ARM64Assembler::linkCompareAndBranch):
     23    (JSC::ARM64Assembler::linkConditionalBranch):
     24    (JSC::ARM64Assembler::linkTestAndBranch):
     25    (JSC::ARM64Assembler::unlinkedCode): Deleted.
     26    * assembler/ARMAssembler.h:
     27    (JSC::ARMAssembler::fillNops):
     28    * assembler/ARMv7Assembler.h:
     29    (JSC::ARMv7Assembler::unlinkedCode): Deleted.
     30    * assembler/AbstractMacroAssembler.h:
     31    (JSC::AbstractMacroAssembler::emitNops):
     32    (JSC::AbstractMacroAssembler::AbstractMacroAssembler):
     33    * assembler/AssemblerBuffer.h:
     34    (JSC::ARM64EHash::ARM64EHash):
     35    (JSC::ARM64EHash::update):
     36    (JSC::ARM64EHash::hash const):
     37    (JSC::ARM64EHash::randomSeed const):
     38    (JSC::AssemblerBuffer::AssemblerBuffer):
     39    (JSC::AssemblerBuffer::putShort):
     40    (JSC::AssemblerBuffer::putIntUnchecked):
     41    (JSC::AssemblerBuffer::putInt):
     42    (JSC::AssemblerBuffer::hash const):
     43    (JSC::AssemblerBuffer::data const):
     44    (JSC::AssemblerBuffer::putIntegralUnchecked):
     45    (JSC::AssemblerBuffer::append): Deleted.
     46    * assembler/LinkBuffer.cpp:
     47    (JSC::LinkBuffer::copyCompactAndLinkCode):
     48    * assembler/MIPSAssembler.h:
     49    (JSC::MIPSAssembler::fillNops):
     50    * assembler/MacroAssemblerARM64.h:
     51    (JSC::MacroAssemblerARM64::jumpsToLink):
     52    (JSC::MacroAssemblerARM64::link):
     53    (JSC::MacroAssemblerARM64::unlinkedCode): Deleted.
     54    * assembler/MacroAssemblerARMv7.h:
     55    (JSC::MacroAssemblerARMv7::jumpsToLink):
     56    (JSC::MacroAssemblerARMv7::unlinkedCode): Deleted.
     57    * assembler/X86Assembler.h:
     58    (JSC::X86Assembler::fillNops):
     59   
     60    Source/WTF:
     61   
     62    * wtf/PtrTag.h:
     63    (WTF::tagInt):
     64   
     65    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236589 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     66
     67    2018-09-27  Saam barati  <sbarati@apple.com>
     68
     69            Verify the contents of AssemblerBuffer on arm64e
     70            https://bugs.webkit.org/show_bug.cgi?id=190057
     71            <rdar://problem/38916630>
     72
     73            Reviewed by Mark Lam.
     74
     75            * wtf/PtrTag.h:
     76            (WTF::tagInt):
     77
    1782018-10-25  Kocsen Chung  <kocsen_chung@apple.com>
    279
  • branches/safari-606-branch/Source/WTF/wtf/PtrTag.h

    r237439 r237470  
    148148inline PtrType untagCFunctionPtr(PtrType ptr) { return ptr; }
    149149
     150template <typename IntType>
     151inline IntType tagInt(IntType ptrInt, PtrTag)
     152{
     153    static_assert(sizeof(IntType) == sizeof(uintptr_t), "");
     154    return ptrInt;
     155}
     156
    150157template<typename PtrType> void assertIsCFunctionPtr(PtrType) { }
    151158template<typename PtrType> void assertIsNullOrCFunctionPtr(PtrType) { }
    … …  
    185192using WTF::tagCFunctionPtr;
    186193using WTF::untagCFunctionPtr;
     194using WTF::tagInt;
    187195
    188196using WTF::assertIsCFunctionPtr;
Note: See TracChangeset for help on using the changeset viewer.