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