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
qemulationdetector_p.h
Go to the documentation of this file.
1
// Copyright (C) 2021 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
QEMULATIONDETECTOR_P_H
5
#
define
QEMULATIONDETECTOR_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
<
QtCore
/
private
/
qglobal_p
.
h
>
19
20
#
if
defined
(
Q_OS_LINUX
)
&&
defined
(
Q_PROCESSOR_ARM
)
21
#
define
SHOULD_CHECK_ARM_ON_X86
22
23
#
include
<
QFileInfo
>
24
25
#
if
QT_CONFIG
(
process
)
&&
QT_CONFIG
(
regularexpression
)
26
#
include
<
QProcess
>
27
#
include
<
QRegularExpression
>
28
#
endif
29
30
#
endif
31
32
QT_BEGIN_NAMESPACE
33
34
// Helper functions for detecting if running emulated
35
namespace
QTestPrivate
{
36
37
#
ifdef
SHOULD_CHECK_ARM_ON_X86
38
static
bool
isX86SpecificFileAvailable
(
void
);
39
static
bool
isReportedArchitectureX86
(
void
);
40
#
endif
41
42
/*
43
* Check if we are running Arm binary on x86 machine.
44
*
45
* Currently this is only able to check on Linux. If not able to
46
* detect, return false.
47
*/
48
[[
maybe_unused
]]
static
bool
isRunningArmOnX86
()
49
{
50
#
ifdef
SHOULD_CHECK_ARM_ON_X86
51
if
(isX86SpecificFileAvailable())
52
return
true
;
53
54
if
(isReportedArchitectureX86())
55
return
true
;
56
#
endif
57
return
false
;
58
}
59
60
#
ifdef
SHOULD_CHECK_ARM_ON_X86
61
/*
62
* Check if we can find a file that's only available on x86
63
*/
64
static
bool
isX86SpecificFileAvailable
()
65
{
66
using
namespace
Qt
::
StringLiterals
;
67
68
// MTRR (Memory Type Range Registers) are a feature of the x86 architecture
69
// and /proc/mtrr is only present (on Linux) for that family.
70
// However, it's an optional kernel feature, so the absence of the file is
71
// not sufficient to conclude we're on real hardware.
72
QFileInfo
mtrr
(u"/proc/mtrr"_s);
73
if
(
mtrr
.
exists
())
74
return
true
;
75
return
false
;
76
}
77
78
/*
79
* Check if architecture reported by the OS is x86
80
*/
81
static
bool
isReportedArchitectureX86
(
void
)
82
{
83
using
namespace
Qt
::
StringLiterals
;
84
85
#
if
QT_CONFIG
(
process
)
&&
QT_CONFIG
(
regularexpression
)
86
QProcess
unamer
;
87
QString
machineString
;
88
89
// Using syscall "uname" is not possible since that would be captured by
90
// QEMU and result would be the architecture being emulated (e.g. armv7l).
91
// By using QProcess we get the architecture used by the host.
92
unamer
.
start
(u"uname -a"_s);
93
if
(!
unamer
.
waitForFinished
()) {
94
return
false
;
95
}
96
machineString
=
QString
::
fromLocal8Bit
(
unamer
.
readAll
());
97
98
// Is our current host cpu x86?
99
if
(
machineString
.
contains
(
QRegularExpression
(u"i386|i686|x86"_s))) {
100
return
true
;
101
}
102
#
endif
103
104
return
false
;
105
}
106
#
endif
// SHOULD_CHECK_ARM_ON_X86
107
108
}
// QTestPrivate namespace
109
110
QT_END_NAMESPACE
111
112
#
endif
QTestPrivate
Definition
qabstractitemmodeltester.h:29
QTestPrivate::isRunningArmOnX86
static bool isRunningArmOnX86()
Definition
qemulationdetector_p.h:48
qtbase
src
testlib
qemulationdetector_p.h
Generated on Mon Mar 10 2025 01:10:32 for Qt by
1.13.2