2022-09-15 23:38:17 +01:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Luau/RegisterX64.h"
|
|
|
|
#include "UnwindBuilder.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace Luau
|
|
|
|
{
|
|
|
|
namespace CodeGen
|
|
|
|
{
|
|
|
|
|
2023-04-14 19:06:22 +01:00
|
|
|
// This struct matches the layout of x64 RUNTIME_FUNCTION from winnt.h
|
|
|
|
struct UnwindFunctionWin
|
|
|
|
{
|
|
|
|
uint32_t beginOffset;
|
|
|
|
uint32_t endOffset;
|
|
|
|
uint32_t unwindInfoOffset;
|
|
|
|
};
|
|
|
|
|
|
|
|
// This struct matches the layout of x64 UNWIND_INFO from ehdata.h
|
|
|
|
struct UnwindInfoWin
|
|
|
|
{
|
|
|
|
uint8_t version : 3;
|
|
|
|
uint8_t flags : 5;
|
|
|
|
uint8_t prologsize;
|
|
|
|
uint8_t unwindcodecount;
|
|
|
|
uint8_t framereg : 4;
|
|
|
|
uint8_t frameregoff : 4;
|
|
|
|
};
|
|
|
|
|
2022-09-15 23:38:17 +01:00
|
|
|
// This struct matches the layout of UNWIND_CODE from ehdata.h
|
|
|
|
struct UnwindCodeWin
|
|
|
|
{
|
|
|
|
uint8_t offset;
|
|
|
|
uint8_t opcode : 4;
|
|
|
|
uint8_t opinfo : 4;
|
|
|
|
};
|
|
|
|
|
|
|
|
class UnwindBuilderWin : public UnwindBuilder
|
|
|
|
{
|
|
|
|
public:
|
2022-10-07 01:23:29 +01:00
|
|
|
void setBeginOffset(size_t beginOffset) override;
|
|
|
|
size_t getBeginOffset() const override;
|
|
|
|
|
2023-05-05 22:52:49 +01:00
|
|
|
void startInfo(Arch arch) override;
|
2023-04-14 19:06:22 +01:00
|
|
|
void startFunction() override;
|
|
|
|
void finishFunction(uint32_t beginOffset, uint32_t endOffset) override;
|
|
|
|
void finishInfo() override;
|
2022-09-15 23:38:17 +01:00
|
|
|
|
2023-05-05 22:52:49 +01:00
|
|
|
void prologueA64(uint32_t prologueSize, uint32_t stackSize, std::initializer_list<A64::RegisterA64> regs) override;
|
2024-08-02 15:30:04 +01:00
|
|
|
void prologueX64(
|
|
|
|
uint32_t prologueSize,
|
|
|
|
uint32_t stackSize,
|
|
|
|
bool setupFrame,
|
|
|
|
std::initializer_list<X64::RegisterX64> gpr,
|
|
|
|
const std::vector<X64::RegisterX64>& simd
|
|
|
|
) override;
|
2023-05-05 22:52:49 +01:00
|
|
|
|
2024-05-26 18:09:09 +01:00
|
|
|
size_t getUnwindInfoSize(size_t blockSize = 0) const override;
|
2022-09-15 23:38:17 +01:00
|
|
|
|
2024-05-26 18:09:09 +01:00
|
|
|
size_t finalize(char* target, size_t offset, void* funcAddress, size_t blockSize) const override;
|
2022-09-15 23:38:17 +01:00
|
|
|
|
|
|
|
private:
|
2022-10-07 01:23:29 +01:00
|
|
|
size_t beginOffset = 0;
|
|
|
|
|
2023-04-14 19:06:22 +01:00
|
|
|
static const unsigned kRawDataLimit = 1024;
|
|
|
|
uint8_t rawData[kRawDataLimit];
|
|
|
|
uint8_t* rawDataPos = rawData;
|
|
|
|
|
|
|
|
std::vector<UnwindFunctionWin> unwindFunctions;
|
|
|
|
|
2022-09-15 23:38:17 +01:00
|
|
|
// Windows unwind codes are written in reverse, so we have to collect them all first
|
|
|
|
std::vector<UnwindCodeWin> unwindCodes;
|
|
|
|
|
|
|
|
uint8_t prologSize = 0;
|
2023-04-14 19:06:22 +01:00
|
|
|
X64::RegisterX64 frameReg = X64::noreg;
|
2022-09-15 23:38:17 +01:00
|
|
|
uint8_t frameRegOffset = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace CodeGen
|
|
|
|
} // namespace Luau
|