Skip to content

Commit 8f7c53e

Browse files
committed
[BOLT][Instrumentation] Add mmap return value assertions
In a very rare case that mmap call fails, we'll at least get a message instead of segfault. Reviewed By: rafauler, Amir Differential Revision: https://reviews.llvm.org/D154056
1 parent f0b45fb commit 8f7c53e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

bolt/runtime/instr.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ class BumpPtrAllocator {
137137
StackBase = reinterpret_cast<uint8_t *>(
138138
__mmap(0, MaxSize, PROT_READ | PROT_WRITE,
139139
(Shared ? MAP_SHARED : MAP_PRIVATE) | MAP_ANONYMOUS, -1, 0));
140+
assert(StackBase != MAP_FAILED,
141+
"BumpPtrAllocator: failed to mmap stack!");
140142
StackSize = 0;
141143
}
142144

@@ -663,6 +665,7 @@ ProfileWriterContext readDescriptions() {
663665
uint64_t Size = __lseek(FD, 0, 2 /*SEEK_END*/);
664666
uint8_t *BinContents = reinterpret_cast<uint8_t *>(
665667
__mmap(0, Size, PROT_READ, MAP_PRIVATE, FD, 0));
668+
assert(BinContents != MAP_FAILED, "readDescriptions: Failed to mmap self!");
666669
Result.MMapPtr = BinContents;
667670
Result.MMapSize = Size;
668671
Elf64_Ehdr *Hdr = reinterpret_cast<Elf64_Ehdr *>(BinContents);
@@ -1551,6 +1554,7 @@ extern "C" void __attribute((force_align_arg_pointer)) __bolt_instr_setup() {
15511554
void *Ret =
15521555
__mmap(CountersStart, CountersEnd - CountersStart, PROT_READ | PROT_WRITE,
15531556
MAP_ANONYMOUS | MAP_SHARED | MAP_FIXED, -1, 0);
1557+
assert(Ret != MAP_FAILED, "__bolt_instr_setup: Failed to mmap counters!");
15541558
__bolt_ind_call_counter_func_pointer = __bolt_instr_indirect_call;
15551559
__bolt_ind_tailcall_counter_func_pointer = __bolt_instr_indirect_tailcall;
15561560
// Conservatively reserve 100MiB shared pages

0 commit comments

Comments
 (0)