<commit_before>//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "Backend.h"
#include "ARM64UnwindEncoder.h"

const OpcodeMatcher Arm64UnwindCodeGenerator::MovkOpcode            = { 0x1f800000, 0x12800000 };
const OpcodeMatcher Arm64UnwindCodeGenerator::BlrOpcode             = { 0xfffffc1f, 0xd63f0000 };
const OpcodeMatcher Arm64UnwindCodeGenerator::RetOpcode             = { 0xffffffff, 0xd65f03c0 };
const OpcodeMatcher Arm64UnwindCodeGenerator::SubSpSpX15Uxtx4Opcode = { 0xffffffff, 0xcb2f73ff };

const OpcodeList Arm64UnwindCodeGenerator::PrologOpcodes =
{
    { 0xff8003ff, 0xd10003ff },         // sub sp, sp, #imm
    { 0xffe0ffff, 0xcb4063ff },         // sub sp, sp, reg
    { 0xff8003ff, 0x910003fd },         // add fp, sp, #imm
    { 0xffc003e0, 0xa90003e0 },         // stp rt, rt2, [sp, #offs]
    { 0xffc003e0, 0xa98003e0 },         // stp rt, rt2, [sp, #offs]!
    { 0xffc003e0, 0xf90003e0 },         // str rt, [sp, #offs]
    { 0xffe00fe0, 0xf8000fe0 },         // str rt, [sp, #offs]!
    { 0xffc003e0, 0x6d0003e0 },         // stp dt, dt2, [sp, #offs]
    { 0xffc003e0, 0x6d8003e0 },         // stp dt, dt2, [sp, #offs]!
    { 0xffc003e0, 0xfd0003e0 },         // str dt, [sp, #offs]
    { 0xffe00fe0, 0xfc000fe0 },         // str dt, [sp, #offs]!
};

const OpcodeList Arm64UnwindCodeGenerator::EpilogOpcodes =
{
    { 0xff8003ff, 0x910003ff },         // add sp, sp, #imm
    { 0xffe0ffff, 0x8b4063ff },         // add sp, sp, reg
    { 0xff8003ff, 0xd10003bf },         // sub sp, fp, #imm
    { 0xffc003e0, 0xa94003e0 },         // ldp rt, rt2, [sp, #offs]
    { 0xffc003e0, 0xa8c003e0 },         // ldp rt, rt2, [sp], #offs
    { 0xffc003e0, 0xf94003e0 },         // ldr rt, [sp, #offs]
    { 0xffe00fe0, 0xf84007e0 },         // ldr rt, [sp], #offs
    { 0xffc003e0, 0x6d4003e0 },         // ldp dt, dt2, [sp, #offs]
    { 0xffc003e0, 0x6cc003e0 },         // ldp dt, dt2, [sp], #offs
    { 0xffc003e0, 0xfd4003e0 },         // ldr dt, [sp, #offs]
    { 0xffe00fe0, 0xfc4007e0 },         // ldr dt, [sp], #offs
};


Arm64XdataGenerator::Arm64XdataGenerator()
    : m_xdataBytes(0)
{
}

void Arm64XdataGenerator::SafeAppendDword(DWORD value)
{
    Assert(m_xdataBytes < sizeof(this->m_xdata));
    if (m_xdataBytes < sizeof(this->m_xdata))
    {
        this->m_xdata[this->m_xdataBytes / 4] = value;
    }
    this->m_xdataBytes += 4;
}

void Arm64XdataGenerator::Generate(PULONG prologStart, PULONG prologEnd, PULONG epilogStart, PULONG epilogEnd, PULONG functionEnd, ULONG exceptionHandlerRva, ULONG exceptionData)<commit_msg>ARM64: Fix unwind info pattern for add sp, sp, reg<commit_after>//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "Backend.h"
#include "ARM64UnwindEncoder.h"

const OpcodeMatcher Arm64UnwindCodeGenerator::MovkOpcode            = { 0x1f800000, 0x12800000 };
const OpcodeMatcher Arm64UnwindCodeGenerator::BlrOpcode             = { 0xfffffc1f, 0xd63f0000 };
const OpcodeMatcher Arm64UnwindCodeGenerator::RetOpcode             = { 0xffffffff, 0xd65f03c0 };
const OpcodeMatcher Arm64UnwindCodeGenerator::SubSpSpX15Uxtx4Opcode = { 0xffffffff, 0xcb2f73ff };

const OpcodeList Arm64UnwindCodeGenerator::PrologOpcodes =
{
    { 0xff8003ff, 0xd10003ff },         // sub sp, sp, #imm
    { 0xffe0ffff, 0xcb4063ff },         // sub sp, sp, reg
    { 0xff8003ff, 0x910003fd },         // add fp, sp, #imm
    { 0xffc003e0, 0xa90003e0 },         // stp rt, rt2, [sp, #offs]
    { 0xffc003e0, 0xa98003e0 },         // stp rt, rt2, [sp, #offs]!
    { 0xffc003e0, 0xf90003e0 },         // str rt, [sp, #offs]
    { 0xffe00fe0, 0xf8000fe0 },         // str rt, [sp, #offs]!
    { 0xffc003e0, 0x6d0003e0 },         // stp dt, dt2, [sp, #offs]
    { 0xffc003e0, 0x6d8003e0 },         // stp dt, dt2, [sp, #offs]!
    { 0xffc003e0, 0xfd0003e0 },         // str dt, [sp, #offs]
    { 0xffe00fe0, 0xfc000fe0 },         // str dt, [sp, #offs]!
};

const OpcodeList Arm64UnwindCodeGenerator::EpilogOpcodes =
{
    { 0xff8003ff, 0x910003ff },         // add sp, sp, #imm
    { 0xffe0ffff, 0x8b2063ff },         // add sp, sp, reg
    { 0xff8003ff, 0xd10003bf },         // sub sp, fp, #imm
    { 0xffc003e0, 0xa94003e0 },         // ldp rt, rt2, [sp, #offs]
    { 0xffc003e0, 0xa8c003e0 },         // ldp rt, rt2, [sp], #offs
    { 0xffc003e0, 0xf94003e0 },         // ldr rt, [sp, #offs]
    { 0xffe00fe0, 0xf84007e0 },         // ldr rt, [sp], #offs
    { 0xffc003e0, 0x6d4003e0 },         // ldp dt, dt2, [sp, #offs]
    { 0xffc003e0, 0x6cc003e0 },         // ldp dt, dt2, [sp], #offs
    { 0xffc003e0, 0xfd4003e0 },         // ldr dt, [sp, #offs]
    { 0xffe00fe0, 0xfc4007e0 },         // ldr dt, [sp], #offs
};


Arm64XdataGenerator::Arm64XdataGenerator()
    : m_xdataBytes(0)
{
}

void Arm64XdataGenerator::SafeAppendDword(DWORD value)
{
    Assert(m_xdataBytes < sizeof(this->m_xdata));
    if (m_xdataBytes < sizeof(this->m_xdata))
    {
        this->m_xdata[this->m_xdataBytes / 4] = value;
    }
    this->m_xdataBytes += 4;
}

void Arm64XdataGenerator::Generate(PULONG prologStart, PULONG prologEnd, PULONG epilogStart, PULONG epilogEnd, PULONG functionEnd, ULONG exceptionHandlerRva, ULONG exceptionData)
{'fraction_non_alphanumeric': 0.1963454576797104, 'fraction_numerical': 0.10894673332184106, 'mean_word_length': 2.1026737967914437, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3734677', 'n_tokens_mistral': 2512, 'n_tokens_neox': 2149, 'n_words': 454}