Ignore:
Timestamp:
Jan 2, 2022, 12:20:28 AM (3 years ago)
Author:
[email protected]
Message:

[JSC] Replace UDIS86 with Zydis
https://bugs.webkit.org/show_bug.cgi?id=234765

Reviewed by Michael Saboff.

Source/JavaScriptCore:

UDIS86 is not updated from 2014. Since it is missing relatively new SIMD opcodes,
we cannot disassemble these opcodes when implementing Wasm SIMD.
This patch replaces UDIS86 with Zydis, which is actively developed and used in
SpiderMonkey too. It is under MIT license.

This patch imports Zydis v3.2.1.

  1. Import header and C files of Zydis and Zycore in a flattened manner.
  2. Add directory names to the files (e.g. Zydis/Decoder.c => ZydisDecoder.c) to make it easy to build in JSC build.
  3. Replace header includes from #include <Zydis/XXX.h> to #include "ZydisXXX.h".
  4. Fix compile errors with our stricter compiler flags.
  5. Remove Zycore API files and ZycoreArgParse.[hc] since they are not used.

We didn't add files to Sources.txt since unified builds do not support C files currently.

Source/WTF:

  • wtf/PlatformEnable.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/disassembler/X86Disassembler.cpp

    r261755 r287510  
    2727#include "Disassembler.h"
    2828
    29 #if ENABLE(UDIS86)
     29#if ENABLE(ZYDIS)
    3030
    3131#include "MacroAssemblerCodeRef.h"
    32 #include "UDis86Disassembler.h"
     32#include "Zydis.h"
    3333
    3434namespace JSC {
     
    3636bool tryToDisassemble(const MacroAssemblerCodePtr<DisassemblyPtrTag>& codePtr, size_t size, const char* prefix, PrintStream& out)
    3737{
    38     return tryToDisassembleWithUDis86(codePtr, size, prefix, out);
     38    ZydisDecoder decoder;
     39    ZydisDecoderInit(&decoder, ZYDIS_MACHINE_MODE_LONG_64, ZYDIS_ADDRESS_WIDTH_64);
     40
     41    ZydisFormatter formatter;
     42    ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_ATT);
     43    ZydisFormatterSetProperty(&formatter, ZYDIS_FORMATTER_PROP_FORCE_SIZE, ZYAN_TRUE);
     44    ZydisFormatterSetProperty(&formatter, ZYDIS_FORMATTER_PROP_HEX_UPPERCASE, ZYAN_FALSE);
     45    ZydisFormatterSetProperty(&formatter, ZYDIS_FORMATTER_PROP_ADDR_PADDING_ABSOLUTE, ZYDIS_PADDING_DISABLED);
     46    ZydisFormatterSetProperty(&formatter, ZYDIS_FORMATTER_PROP_ADDR_PADDING_RELATIVE, ZYDIS_PADDING_DISABLED);
     47    ZydisFormatterSetProperty(&formatter, ZYDIS_FORMATTER_PROP_DISP_PADDING, ZYDIS_PADDING_DISABLED);
     48    ZydisFormatterSetProperty(&formatter, ZYDIS_FORMATTER_PROP_IMM_PADDING, ZYDIS_PADDING_DISABLED);
     49
     50    const auto* data = codePtr.dataLocation<unsigned char*>();
     51    ZyanUSize offset = 0;
     52    ZydisDecodedInstruction instruction;
     53    char formatted[1024];
     54    while (ZYAN_SUCCESS(ZydisDecoderDecodeBuffer(&decoder, data + offset, size - offset, &instruction))) {
     55        if (ZYAN_SUCCESS(ZydisFormatterFormatInstruction(&formatter, &instruction, formatted, sizeof(formatted), bitwise_cast<unsigned long long>(data + offset))))
     56            out.printf("%s%#16llx: %s\n", prefix, static_cast<unsigned long long>(bitwise_cast<uintptr_t>(data + offset)), formatted);
     57        else
     58            out.printf("%s%#16llx: failed-to-format\n", prefix, static_cast<unsigned long long>(bitwise_cast<uintptr_t>(data + offset)));
     59        offset += instruction.length;
     60    }
     61
     62    return true;
    3963}
    4064
    4165} // namespace JSC
    4266
    43 #endif // ENABLE(UDIS86)
     67#endif // ENABLE(ZYDIS)
Note: See TracChangeset for help on using the changeset viewer.