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
qv4stacklimits_p.h
Go to the documentation of this file.
1// Copyright (C) 2022 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
4#ifndef QV4STACKLIMITS_P_H
5#define QV4STACKLIMITS_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <private/qtqmlglobal_p.h>
19
20#ifndef Q_STACK_GROWTH_DIRECTION
21# ifdef Q_PROCESSOR_HPPA
22# define Q_STACK_GROWTH_DIRECTION (1)
23# else
24# define Q_STACK_GROWTH_DIRECTION (-1)
25# endif
26#endif
27
28QT_BEGIN_NAMESPACE
29
30namespace QV4 {
31
32// We may not be able to take the negative of the type
33// used to represent stack size, but we can always add
34// or subtract it to/from a quint8 pointer.
35
36template<typename Size>
37static const void *incrementStackPointer(const void *base, Size amount)
38{
40 return static_cast<const quint8 *>(base) + amount;
41#else
42 return static_cast<const quint8 *>(base) - amount;
43#endif
44}
45
46template<typename Size>
47static void *decrementStackPointer(void *base, Size amount)
48{
50 return static_cast<quint8 *>(base) - amount;
51#else
52 return static_cast<quint8 *>(base) + amount;
53#endif
54}
55
56// Note: This does not return a completely accurate stack pointer.
57// Depending on whether this function is inlined or not, we may get the address of
58// this function's stack frame or the caller's stack frame.
59// Always use a safety margin when determining stack limits.
60inline const void *currentStackPointer()
61{
62 // TODO: How often do we actually need the assembler mess below? Is that worth it?
63
64 void *stackPointer;
65#if defined(Q_CC_GNU) || __has_builtin(__builtin_frame_address)
66 stackPointer = __builtin_frame_address(0);
67#elif defined(Q_CC_MSVC)
68 stackPointer = &stackPointer;
69#elif defined(Q_PROCESSOR_X86_64)
70 __asm__ __volatile__("movq %%rsp, %0" : "=r"(stackPointer) : :);
71#elif defined(Q_PROCESSOR_X86)
72 __asm__ __volatile__("movl %%esp, %0" : "=r"(stackPointer) : :);
73#elif defined(Q_PROCESSOR_ARM_64) && defined(__ILP32__)
74 quint64 stackPointerRegister = 0;
75 __asm__ __volatile__("mov %0, sp" : "=r"(stackPointerRegister) : :);
76 stackPointer = reinterpret_cast<void *>(stackPointerRegister);
77#elif defined(Q_PROCESSOR_ARM_64) || defined(Q_PROCESSOR_ARM_32)
78 __asm__ __volatile__("mov %0, sp" : "=r"(stackPointer) : :);
79#else
80 stackPointer = &stackPointer;
81#endif
82 return stackPointer;
83}
84
86{
87 const void *base = nullptr;
88 const void *softLimit = nullptr;
89 const void *hardLimit = nullptr;
90};
91
93
94} // namespace QV4
95
96QT_END_NAMESPACE
97
98#endif // QV4STACKLIMITS_P_H
Definition qjsvalue.h:23
static void * decrementStackPointer(void *base, Size amount)
StackProperties stackProperties()
static const void * incrementStackPointer(const void *base, Size amount)
const void * currentStackPointer()
#define __has_builtin(x)
#define Q_STACK_GROWTH_DIRECTION