Skip to content

Commit

Permalink
Patch access to the fs:0x28 register...
Browse files Browse the repository at this point in the history
...to read gs:0x28 instead to avoid an 0x28 access error, which cannot be ignored to handle it in a signal handler in lldb
  • Loading branch information
ChristopherHX authored May 15, 2023
1 parent d68c051 commit dc03624
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions linker/linker_phdr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,21 @@ bool ElfReader::LoadSegments() {
DL_ERR("couldn't map \"%s\" segment %zd: %s", name_.c_str(), i, strerror(errno));
return false;
}
#if defined(__APPLE__) && defined(__x86_64__)
// Patch access to the fs:0x28 register .to read gs:0x28 instead to avoid an 0x28 access error
// which cannot be ignored to handle it in a signal handler in lldb
if(phdr->p_flags & PF_X) {
unsigned char seq1[] = { 0x64, 0x48, 0x8B };
unsigned char seq2[] = { 0x25, 0x28, 0x00, 0x00 };
//64 48 8B ?? 25 28 00 00
for(unsigned char* addr = reinterpret_cast<unsigned char*>(seg_page_start), *end = reinterpret_cast<unsigned char*>(seg_page_end) - 8; addr < end; addr++) {
if(memcmp(seq1, addr, sizeof(seq1)) == 0 && memcmp(seq2, addr + sizeof(seq1) + 1, sizeof(seq2)) == 0) {
*addr = 0x65;
addr += sizeof(seq1) + sizeof(seq2);
}
}
}
#endif
}

// if the segment is writable, and does not end on a page boundary,
Expand Down

0 comments on commit dc03624

Please sign in to comment.