aboutsummaryrefslogtreecommitdiff
path: root/bolt
diff options
context:
space:
mode:
authorDenis Revunov <revunov.denis@huawei-partners.com>2023-06-29 11:57:48 +0300
committerDenis Revunov <rnovds@gmail.com>2023-06-30 11:10:08 +0300
commit8b23a853b9fa50be8448ca54e68b2c40279e5a60 (patch)
tree6429efe3314263699413b76b27a533543b020f41 /bolt
parent2feac34aeeaf67943492a5adfe45c3f4767bdfe4 (diff)
downloadllvm-8b23a853b9fa50be8448ca54e68b2c40279e5a60.zip
llvm-8b23a853b9fa50be8448ca54e68b2c40279e5a60.tar.gz
llvm-8b23a853b9fa50be8448ca54e68b2c40279e5a60.tar.bz2
Reland [BOLT][Instrumentation][NFC] define and use mmap flags
Reviewed By: rafauler, Amir Differential Revision: https://reviews.llvm.org/D154056
Diffstat (limited to 'bolt')
-rw-r--r--bolt/runtime/common.h24
-rw-r--r--bolt/runtime/instr.cpp20
2 files changed, 30 insertions, 14 deletions
diff --git a/bolt/runtime/common.h b/bolt/runtime/common.h
index 906ab27..a929115 100644
--- a/bolt/runtime/common.h
+++ b/bolt/runtime/common.h
@@ -82,6 +82,30 @@ typedef int int32_t;
"pop %%rbx\n" \
"pop %%rax\n"
+#define PROT_READ 0x1 /* Page can be read. */
+#define PROT_WRITE 0x2 /* Page can be written. */
+#define PROT_EXEC 0x4 /* Page can be executed. */
+#define PROT_NONE 0x0 /* Page can not be accessed. */
+#define PROT_GROWSDOWN \
+ 0x01000000 /* Extend change to start of \
+ growsdown vma (mprotect only). */
+#define PROT_GROWSUP \
+ 0x02000000 /* Extend change to start of \
+ growsup vma (mprotect only). */
+
+/* Sharing types (must choose one and only one of these). */
+#define MAP_SHARED 0x01 /* Share changes. */
+#define MAP_PRIVATE 0x02 /* Changes are private. */
+#define MAP_FIXED 0x10 /* Interpret addr exactly. */
+
+#if defined(__APPLE__)
+#define MAP_ANONYMOUS 0x1000
+#else
+#define MAP_ANONYMOUS 0x20
+#endif
+
+#define MAP_FAILED ((void *)-1)
+
// Functions that are required by freestanding environment. Compiler may
// generate calls to these implicitly.
extern "C" {
diff --git a/bolt/runtime/instr.cpp b/bolt/runtime/instr.cpp
index cbfc19e..1070980 100644
--- a/bolt/runtime/instr.cpp
+++ b/bolt/runtime/instr.cpp
@@ -134,16 +134,9 @@ public:
Lock L(M);
if (StackBase == nullptr) {
-#if defined(__APPLE__)
- int MAP_PRIVATE_MAP_ANONYMOUS = 0x1002;
-#else
- int MAP_PRIVATE_MAP_ANONYMOUS = 0x22;
-#endif
StackBase = reinterpret_cast<uint8_t *>(
- __mmap(0, MaxSize, 0x3 /* PROT_READ | PROT_WRITE*/,
- Shared ? 0x21 /*MAP_SHARED | MAP_ANONYMOUS*/
- : MAP_PRIVATE_MAP_ANONYMOUS /* MAP_PRIVATE | MAP_ANONYMOUS*/,
- -1, 0));
+ __mmap(0, MaxSize, PROT_READ | PROT_WRITE,
+ (Shared ? MAP_SHARED : MAP_PRIVATE) | MAP_ANONYMOUS, -1, 0));
StackSize = 0;
}
@@ -714,7 +707,7 @@ ProfileWriterContext readDescriptions() {
// mmap our binary to memory
uint64_t Size = __lseek(FD, 0, 2 /*SEEK_END*/);
uint8_t *BinContents = reinterpret_cast<uint8_t *>(
- __mmap(0, Size, 0x1 /* PROT_READ*/, 0x2 /* MAP_PRIVATE*/, FD, 0));
+ __mmap(0, Size, PROT_READ, MAP_PRIVATE, FD, 0));
Result.MMapPtr = BinContents;
Result.MMapSize = Size;
Elf64_Ehdr *Hdr = reinterpret_cast<Elf64_Ehdr *>(BinContents);
@@ -1600,10 +1593,9 @@ extern "C" void __attribute((force_align_arg_pointer)) __bolt_instr_setup() {
assert (CountersEnd > CountersStart, "no counters");
// Maps our counters to be shared instead of private, so we keep counting for
// forked processes
- __mmap(CountersStart, CountersEnd - CountersStart,
- 0x3 /*PROT_READ|PROT_WRITE*/,
- 0x31 /*MAP_ANONYMOUS | MAP_SHARED | MAP_FIXED*/, -1, 0);
-
+ void *Ret =
+ __mmap(CountersStart, CountersEnd - CountersStart, PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_SHARED | MAP_FIXED, -1, 0);
__bolt_ind_call_counter_func_pointer = __bolt_instr_indirect_call;
__bolt_ind_tailcall_counter_func_pointer = __bolt_instr_indirect_tailcall;
// Conservatively reserve 100MiB shared pages