Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qv4functiontable_win64.cpp
Go to the documentation of this file.
1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant
4
6
7#include <assembler/MacroAssemblerCodeRef.h>
8
9#include <QtCore/qdebug.h>
10
11#include <qt_windows.h>
12
14
15namespace QV4 {
16
18{
19 UWOP_PUSH_NONVOL = 0, /* info == register number */
20 UWOP_ALLOC_LARGE, /* no info, alloc size in next 2 slots */
21 UWOP_ALLOC_SMALL, /* info == size of allocation / 8 - 1 */
22 UWOP_SET_FPREG, /* no info, FP = RSP + UNWIND_INFO.FPRegOffset*16 */
23 UWOP_SAVE_NONVOL, /* info == register number, offset in next slot */
24 UWOP_SAVE_NONVOL_FAR, /* info == register number, offset in next 2 slots */
25 UWOP_SAVE_XMM128 = 8, /* info == XMM reg number, offset in next slot */
26 UWOP_SAVE_XMM128_FAR, /* info == XMM reg number, offset in next 2 slots */
27 UWOP_PUSH_MACHFRAME /* info == 0: no error-code, 1: error-code */
28};
29
42
44{
45 UnwindCode(UINT8 offset, UnwindOpcode operation, Register info)
47 {}
48
52};
53
64
70
71void generateFunctionTable(Function *, JSC::MacroAssemblerCodeRef *codeRef)
72{
73 ExceptionHandlerRecord *record = reinterpret_cast<ExceptionHandlerRecord *>(
74 codeRef->executableMemory()->exceptionHandlerStart());
75
76 record->info.Version = 1;
77 record->info.Flags = 0;
78 record->info.SizeOfProlog = 4;
79 record->info.CountOfUnwindCodes = 2;
80 record->info.FrameRegister = RBP;
81 record->info.FrameRegisterOffset = 0;
82
83 // Push frame pointer
84 record->info.UnwindCodes[1] = UnwindCode(1, UWOP_PUSH_NONVOL, RBP);
85 // Set frame pointer from stack pointer
86 record->info.UnwindCodes[0] = UnwindCode(4, UWOP_SET_FPREG, NONE);
87
88 const quintptr codeStart = quintptr(codeRef->code().executableAddress());
89 const quintptr codeSize = codeRef->size();
90
91 record->handler.BeginAddress = DWORD(codeStart - quintptr(record));
92 record->handler.EndAddress = DWORD(codeStart + codeSize - quintptr(record));
93 record->handler.UnwindData = offsetof(ExceptionHandlerRecord, info);
94
95 if (!RtlAddFunctionTable(&record->handler, 1, DWORD64(record))) {
96 const unsigned int errorCode = GetLastError();
97 qWarning() << "Failed to install win64 unwind hook. Error code:" << errorCode;
98 }
99}
100
101void destroyFunctionTable(Function *, JSC::MacroAssemblerCodeRef *codeRef)
102{
103 ExceptionHandlerRecord *record = reinterpret_cast<ExceptionHandlerRecord *>(
104 codeRef->executableMemory()->exceptionHandlerStart());
105 if (!RtlDeleteFunctionTable(&record->handler)) {
106 const unsigned int errorCode = GetLastError();
107 qWarning() << "Failed to remove win64 unwind hook. Error code:" << errorCode;
108 }
109}
110
112{
113 return sizeof(ExceptionHandlerRecord);
114}
115
116} // QV4
117
118QT_END_NAMESPACE
Definition qjsvalue.h:23
size_t exceptionHandlerSize()
void generateFunctionTable(Function *function, JSC::MacroAssemblerCodeRef *codeRef)
void destroyFunctionTable(Function *function, JSC::MacroAssemblerCodeRef *codeRef)
UnwindCode(UINT8 offset, UnwindOpcode operation, Register info)