Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit 30e6ecf

Browse files
committed
[compiler-rt] Fix incorrect handling of indirect load.
Summary: Indirect load are relative offset from RIP. The current trampoline implementation is incorrectly copying these instructions which make some unittests crashing. This patch is not fixing the unittests but it's fixing the crashes. The functions are no longer hooked. Patches will come soon to fix these unittests. Reviewers: rnk Subscribers: llvm-commits, wang0109, chrisha Differential Revision: https://reviews.llvm.org/D22410 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@275892 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent f49accb commit 30e6ecf

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

lib/interception/interception_win.cc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,6 @@ static size_t GetInstructionSize(uptr address) {
410410

411411
case 0xb8: // b8 XX XX XX XX : mov eax, XX XX XX XX
412412
case 0xB9: // b9 XX XX XX XX : mov ecx, XX XX XX XX
413-
case 0xA1: // A1 XX XX XX XX : mov eax, dword ptr ds:[XXXXXXXX]
414413
return 5;
415414

416415
// Cannot overwrite control-instruction. Return 0 to indicate failure.
@@ -453,6 +452,12 @@ static size_t GetInstructionSize(uptr address) {
453452
}
454453

455454
#if SANITIZER_WINDOWS64
455+
switch (*(u8*)address) {
456+
case 0xA1: // A1 XX XX XX XX XX XX XX XX :
457+
// movabs eax, dword ptr ds:[XXXXXXXX]
458+
return 8;
459+
}
460+
456461
switch (*(u16*)address) {
457462
case 0x5040: // push rax
458463
case 0x5140: // push rcx
@@ -500,7 +505,12 @@ static size_t GetInstructionSize(uptr address) {
500505
// mov rax, QWORD PTR [rip + XXXXXXXX]
501506
case 0x25ff48: // 48 ff 25 XX XX XX XX :
502507
// rex.W jmp QWORD PTR [rip + XXXXXXXX]
503-
return 7;
508+
// Instructions having offset relative to 'rip' cannot be copied.
509+
return 0;
510+
511+
case 0x2444c7: // C7 44 24 XX YY YY YY YY
512+
// mov dword ptr [rsp + XX], YYYYYYYY
513+
return 8;
504514
}
505515

506516
switch (*(u32*)(address)) {
@@ -513,6 +523,10 @@ static size_t GetInstructionSize(uptr address) {
513523

514524
#else
515525

526+
switch (*(u8*)address) {
527+
case 0xA1: // A1 XX XX XX XX : mov eax, dword ptr ds:[XXXXXXXX]
528+
return 5;
529+
}
516530
switch (*(u16*)address) {
517531
case 0x458B: // 8B 45 XX : mov eax, dword ptr [ebp + XX]
518532
case 0x5D8B: // 8B 5D XX : mov ebx, dword ptr [ebp + XX]

0 commit comments

Comments
 (0)