Skip to content

Commit 8ed172c

Browse files
committed
Reland [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 8b23a85 commit 8ed172c

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

@@ -708,6 +710,7 @@ ProfileWriterContext readDescriptions() {
708710
uint64_t Size = __lseek(FD, 0, 2 /*SEEK_END*/);
709711
uint8_t *BinContents = reinterpret_cast<uint8_t *>(
710712
__mmap(0, Size, PROT_READ, MAP_PRIVATE, FD, 0));
713+
assert(BinContents != MAP_FAILED, "readDescriptions: Failed to mmap self!");
711714
Result.MMapPtr = BinContents;
712715
Result.MMapSize = Size;
713716
Elf64_Ehdr *Hdr = reinterpret_cast<Elf64_Ehdr *>(BinContents);
@@ -1596,6 +1599,7 @@ extern "C" void __attribute((force_align_arg_pointer)) __bolt_instr_setup() {
15961599
void *Ret =
15971600
__mmap(CountersStart, CountersEnd - CountersStart, PROT_READ | PROT_WRITE,
15981601
MAP_ANONYMOUS | MAP_SHARED | MAP_FIXED, -1, 0);
1602+
assert(Ret != MAP_FAILED, "__bolt_instr_setup: Failed to mmap counters!");
15991603
__bolt_ind_call_counter_func_pointer = __bolt_instr_indirect_call;
16001604
__bolt_ind_tailcall_counter_func_pointer = __bolt_instr_indirect_tailcall;
16011605
// Conservatively reserve 100MiB shared pages

0 commit comments

Comments
 (0)