LIEF: Library to Instrument Executable Formats
Version 2.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
lief-install
x86_64
static
include
LIEF
runtime
runtime/utils.hpp
Go to the documentation of this file.
1
/* Copyright 2017 - 2026 R. Thomas
2
*
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
* you may not use this file except in compliance with the License.
5
* You may obtain a copy of the License at
6
*
7
* http://www.apache.org/licenses/LICENSE-2.0
8
*
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
* See the License for the specific language governing permissions and
13
* limitations under the License.
14
*/
15
#ifndef LIEF_RUNTIME_UTILS_H
16
#define LIEF_RUNTIME_UTILS_H
17
#include "
LIEF/config.h
"
18
#include <cstdint>
19
20
#if defined(LIEF_RUNTIME_SUPPORT)
21
#include "LIEF/runtime/config.h"
22
#endif
23
24
25
namespace
LIEF::runtime
{
26
27
enum class
PLATFORMS
: uint32_t {
28
NONE = 0,
29
LINUX
,
30
WINDOWS
,
31
ANDROID_
,
32
OSX
,
33
IOS
,
34
};
35
36
enum class
ARCH
: uint32_t {
37
NONE,
38
X86_64,
39
ARM64
,
40
RISCV64
,
41
};
42
44
static
constexpr
bool
is_enabled() {
45
return
lief_runtime_support;
46
}
47
49
static
constexpr
PLATFORMS
platform() {
50
#if !defined(LIEF_RUNTIME_SUPPORT)
51
return
PLATFORMS::NONE
;
52
#else
53
#if defined(LIEF_RUNTIME_PLATFORM_LINUX)
54
return
PLATFORMS::LINUX
;
55
#elif defined(LIEF_RUNTIME_PLATFORM_WINDOWS)
56
return
PLATFORMS::WINDOWS
;
57
#elif defined(LIEF_RUNTIME_PLATFORM_ANDROID)
58
return
PLATFORMS::ANDROID_
;
59
#elif defined(LIEF_RUNTIME_PLATFORM_OSX)
60
return
PLATFORMS::OSX
;
61
#elif defined(LIEF_RUNTIME_PLATFORM_IOS)
62
return
PLATFORMS::IOS
;
63
#else
64
return
PLATFORMS::NONE
;
65
#endif
66
#endif
67
}
68
70
static
constexpr
ARCH
arch() {
71
#if !defined(LIEF_RUNTIME_SUPPORT)
72
return
ARCH::NONE
;
73
#else
74
#if defined(LIEF_RUNTIME_ARCH_ARM64)
75
return
ARCH::ARM64
;
76
#elif defined(LIEF_RUNTIME_ARCH_X86_64)
77
return
ARCH::X86_64
;
78
#elif defined(LIEF_RUNTIME_ARCH_RISCV64)
79
return
ARCH::RISCV64
;
80
#else
81
return
ARCH::NONE
;
82
#endif
83
84
#endif
85
}
86
87
static
inline
constexpr
uintptr_t page_mask(uintptr_t page_size) {
88
return
~(page_size - 1);
89
}
90
91
static
inline
constexpr
uintptr_t page_start(uintptr_t address,
92
uintptr_t page_size) {
93
return
address & page_mask(page_size);
94
}
95
96
static
inline
constexpr
uintptr_t page_align(uintptr_t address,
97
uintptr_t page_size) {
98
return
(address + (page_size - 1)) & page_mask(page_size);
99
}
100
101
static
inline
constexpr
uintptr_t page_offset(uintptr_t address,
102
uintptr_t page_size) {
103
return
(address & ~page_mask(page_size));
104
}
105
106
static
inline
constexpr
uintptr_t page_end(uintptr_t address,
107
uintptr_t page_size) {
108
return
page_start(address + (page_size - 1), page_size);
109
}
110
111
}
112
113
#endif
config.h
LIEF::runtime
Definition
android/Host.hpp:23
LIEF::runtime::ARCH
ARCH
Definition
runtime/utils.hpp:36
LIEF::runtime::ARCH::X86_64
@ X86_64
Definition
runtime/utils.hpp:38
LIEF::runtime::ARCH::RISCV64
@ RISCV64
Definition
runtime/utils.hpp:40
LIEF::runtime::ARCH::NONE
@ NONE
Definition
runtime/utils.hpp:37
LIEF::runtime::ARCH::ARM64
@ ARM64
Definition
runtime/utils.hpp:39
LIEF::runtime::PLATFORMS
PLATFORMS
Definition
runtime/utils.hpp:27
LIEF::runtime::PLATFORMS::OSX
@ OSX
Definition
runtime/utils.hpp:32
LIEF::runtime::PLATFORMS::NONE
@ NONE
Definition
runtime/utils.hpp:28
LIEF::runtime::PLATFORMS::IOS
@ IOS
Definition
runtime/utils.hpp:33
LIEF::runtime::PLATFORMS::WINDOWS
@ WINDOWS
Definition
runtime/utils.hpp:30
LIEF::runtime::PLATFORMS::LINUX
@ LINUX
Definition
runtime/utils.hpp:29
LIEF::runtime::PLATFORMS::ANDROID_
@ ANDROID_
Definition
runtime/utils.hpp:31
Generated by
1.19.0