4#include <private/qv4stacklimits_p.h>
5#include <private/qobject_p.h>
6#include <private/qthread_p.h>
8#include <QtCore/qfile.h>
15# include <QtCore/qt_windows.h>
16#elif defined(Q_OS_FREEBSD_KERNEL) || defined(Q_OS_OPENBSD)
17# include <pthread_np.h>
18#elif defined(Q_OS_LINUX)
20# include <sys/resource.h>
21# include <sys/syscall.h>
22# if defined(__GLIBC__) && QT_CONFIG(dlopen)
25#elif defined(Q_OS_DARWIN)
26# include <sys/resource.h>
27#elif defined(Q_OS_QNX)
29# include <sys/procfs.h>
30# include <sys/types.h>
32#elif defined(Q_OS_INTEGRITY)
33# include <INTEGRITY.h>
34#elif defined(Q_OS_WASM)
35# include <emscripten/stack.h>
49#elif defined(Q_OS_MACOS)
52#elif defined(Q_OS_ANDROID)
56#elif defined(Q_OS_LINUX)
60#elif defined(Q_OS_QNX)
75template<
typename Size>
78#if Q_STACK_GROWTH_DIRECTION > 0
85template<
typename Size>
88#if Q_STACK_GROWTH_DIRECTION > 0
104#if defined(Q_OS_DARWIN) || defined(Q_OS_LINUX)
111static qsizetype getMainStackSizeFromRlimit()
114 return (getrlimit(RLIMIT_STACK, &
limit) == 0 &&
limit.rlim_cur != RLIM_INFINITY)
120#if defined(Q_OS_INTEGRITY)
124 Address stackLow, stackHigh;
125 CheckSuccess(GetTaskStackLimits(CurrentTask(), &stackLow, &stackHigh));
126# if Q_STACK_GROWTH_DIRECTION < 0
133#elif defined(Q_OS_DARWIN)
137 pthread_t thread = pthread_self();
139 pthread_get_stackaddr_np(thread),
141 ? getMainStackSizeFromRlimit()
142 :
qsizetype(pthread_get_stacksize_np(thread)));
145#elif defined(Q_OS_WIN)
152 PNT_TIB64 pTib =
reinterpret_cast<PNT_TIB64
>(NtCurrentTeb());
154 PNT_TIB pTib =
reinterpret_cast<PNT_TIB
>(NtCurrentTeb());
156 quint8 *stackBase =
reinterpret_cast<quint8 *
>(pTib->StackBase);
160 MEMORY_BASIC_INFORMATION mbi = {};
161 if (!VirtualQuery(&mbi, &mbi,
sizeof(mbi)))
162 qFatal(
"Could not retrieve memory information for stack.");
164 quint8 *stackLimit =
reinterpret_cast<quint8 *
>(mbi.AllocationBase);
168#elif defined(Q_OS_OPENBSD)
183 rc = pthread_stackseg_np(pthread_self, &ss);
184#if Q_STACK_GROWTH_DIRECTION < 0
191#elif defined(Q_OS_QNX)
195 const auto tid = pthread_self();
196 procfs_status status;
199 const int fd =
open(
"/proc/self/ctl", O_RDONLY);
201 qFatal(
"Could not open /proc/self/ctl");
204 if (devctl(
fd, DCMD_PROC_TIDSTATUS, &status,
sizeof(status), 0) != EOK)
205 qFatal(
"Could not query thread status for current thread");
207 if (status.tid != tid)
208 qFatal(
"Thread status query returned garbage");
210#if Q_STACK_GROWTH_DIRECTION < 0
219#elif defined(Q_OS_WASM)
223 const uintptr_t
base = emscripten_stack_get_base();
224 const uintptr_t
end = emscripten_stack_get_end();
235 pthread_t thread = pthread_self();
236 pthread_attr_t sattr;
237 pthread_attr_init(&sattr);
238# if defined(PTHREAD_NP_H) || defined(_PTHREAD_NP_H_) || defined(Q_OS_NETBSD)
239 pthread_attr_get_np(thread, &sattr);
241 pthread_getattr_np(thread, &sattr);
248 int rc = pthread_attr_getstack(&sattr, &stackBase, ®ionSize);
249 pthread_attr_destroy(&sattr);
252 qFatal(
"Cannot find stack base");
254# if Q_STACK_GROWTH_DIRECTION < 0
261#if defined(Q_OS_LINUX)
263static void *stackBaseFromLibc()
265#if defined(__GLIBC__) && QT_CONFIG(dlopen)
266 void **libcStackEnd =
static_cast<void **
>(dlsym(RTLD_DEFAULT,
"__libc_stack_end"));
269 if (
void *stackBase = *libcStackEnd)
280static StackSegment stackSegmentFromProc()
302 if (!
ok ||
base > stackAddr)
321 if (getpid() !=
static_cast<pid_t
>(syscall(SYS_gettid)))
328 const qsizetype stackSize = getMainStackSizeFromRlimit();
333 if (
void *
base = stackBaseFromLibc())
338 const StackSegment
segment = stackSegmentFromProc();
340# if Q_STACK_GROWTH_DIRECTION > 0
341 void *stackBase =
reinterpret_cast<void *
>(
segment.base);
343 void *stackBase =
reinterpret_cast<void *
>(
segment.limit);
qulonglong toULongLong(bool *ok=nullptr, int base=10) const
Returns the string converted to an {unsigned long long} using base base, which is 10 by default and m...
QString sliced(qsizetype pos) const
static QString static QString qsizetype indexOf(QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Combined button and popup list for selecting options.
\qmltype Particle \inqmlmodule QtQuick.Particles
static void * incrementStackPointer(void *base, Size amount)
static void * decrementStackPointer(void *base, Size amount)
static StackProperties createStackProperties(void *base, qsizetype size=PlatformStackSize)
StackProperties stackProperties()
StackProperties stackPropertiesGeneric(qsizetype stackSize=0)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLenum GLsizei length
QScopeGuard< typename std::decay< F >::type > qScopeGuard(F &&f)
[qScopeGuard]
#define QStringLiteral(str)
#define Q_STACK_GROWTH_DIRECTION
file open(QIODevice::ReadOnly)