Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/CodeGen/include/Luau/UnwindBuilderWin.h
2727 views
1
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
#pragma once
3
4
#include "Luau/RegisterX64.h"
5
#include "UnwindBuilder.h"
6
7
#include <vector>
8
9
namespace Luau
10
{
11
namespace CodeGen
12
{
13
14
// This struct matches the layout of x64 RUNTIME_FUNCTION from winnt.h
15
struct UnwindFunctionWin
16
{
17
uint32_t beginOffset;
18
uint32_t endOffset;
19
uint32_t unwindInfoOffset;
20
};
21
22
// This struct matches the layout of x64 UNWIND_INFO from ehdata.h
23
struct UnwindInfoWin
24
{
25
uint8_t version : 3;
26
uint8_t flags : 5;
27
uint8_t prologsize;
28
uint8_t unwindcodecount;
29
uint8_t framereg : 4;
30
uint8_t frameregoff : 4;
31
};
32
33
// This struct matches the layout of UNWIND_CODE from ehdata.h
34
struct UnwindCodeWin
35
{
36
uint8_t offset;
37
uint8_t opcode : 4;
38
uint8_t opinfo : 4;
39
};
40
41
class UnwindBuilderWin : public UnwindBuilder
42
{
43
public:
44
void setBeginOffset(size_t beginOffset) override;
45
size_t getBeginOffset() const override;
46
47
void startInfo(Arch arch) override;
48
void startFunction() override;
49
void finishFunction(uint32_t beginOffset, uint32_t endOffset) override;
50
void finishInfo() override;
51
52
void prologueA64(uint32_t prologueSize, uint32_t stackSize, std::initializer_list<A64::RegisterA64> regs) override;
53
void prologueX64(
54
uint32_t prologueSize,
55
uint32_t stackSize,
56
bool setupFrame,
57
std::initializer_list<X64::RegisterX64> gpr,
58
const std::vector<X64::RegisterX64>& simd
59
) override;
60
61
size_t getUnwindInfoSize(size_t blockSize = 0) const override;
62
63
size_t finalize(char* target, size_t offset, void* funcAddress, size_t blockSize) const override;
64
65
private:
66
size_t beginOffset = 0;
67
68
static const unsigned kRawDataLimit = 1024;
69
uint8_t rawData[kRawDataLimit];
70
uint8_t* rawDataPos = rawData;
71
72
std::vector<UnwindFunctionWin> unwindFunctions;
73
74
// Windows unwind codes are written in reverse, so we have to collect them all first
75
std::vector<UnwindCodeWin> unwindCodes;
76
77
uint8_t prologSize = 0;
78
X64::RegisterX64 frameReg = X64::noreg;
79
uint8_t frameRegOffset = 0;
80
};
81
82
} // namespace CodeGen
83
} // namespace Luau
84
85