Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Side by Side Diff: lib/Target/X86/MCTargetDesc/X86MCNaClExpander.cpp

Issue 1274223003: Auto-sandboxing: Switch to automatic scratch register invalidation (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 //===- X86MCNaClExpander.cpp ------------------------------------*- C++ -*-===// 1 //===- X86MCNaClExpander.cpp ------------------------------------*- C++ -*-===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // The LLVM Compiler Infrastructure
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // This file implements the X86MCNaClExpander class, the X86 specific 10 // This file implements the X86MCNaClExpander class, the X86 specific
(...skipping 21 matching lines...) Expand all
32 unsigned getReg64(unsigned Reg); 32 unsigned getReg64(unsigned Reg);
33 33
34 static unsigned demoteOpcode(unsigned Reg); 34 static unsigned demoteOpcode(unsigned Reg);
35 35
36 static bool isAbsoluteReg(unsigned Reg) { 36 static bool isAbsoluteReg(unsigned Reg) {
37 Reg = getReg64(Reg); // Normalize to 64 bits 37 Reg = getReg64(Reg); // Normalize to 64 bits
38 return (Reg == X86::R15 || Reg == X86::RSP || Reg == X86::RBP || 38 return (Reg == X86::R15 || Reg == X86::RSP || Reg == X86::RBP ||
39 Reg == X86::RIP); 39 Reg == X86::RIP);
40 } 40 }
41 41
42 bool X86::X86MCNaClExpander::isValidScratchRegister(unsigned Reg) const {
43 // TODO(dschuff): Check the register class.
44 if (isAbsoluteReg(Reg))
45 return false;
46 return true;
47 }
48
49
42 static void PushReturnAddress(const llvm::MCSubtargetInfo &STI, 50 static void PushReturnAddress(const llvm::MCSubtargetInfo &STI,
43 MCContext &Context, MCStreamer &Out, 51 MCContext &Context, MCStreamer &Out,
44 MCSymbol *RetTarget) { 52 MCSymbol *RetTarget) {
45 const MCExpr *RetTargetExpr = MCSymbolRefExpr::Create(RetTarget, Context); 53 const MCExpr *RetTargetExpr = MCSymbolRefExpr::Create(RetTarget, Context);
46 if (Context.getObjectFileInfo()->getRelocM() == Reloc::PIC_) { 54 if (Context.getObjectFileInfo()->getRelocM() == Reloc::PIC_) {
47 // Calculate return_addr 55 // Calculate return_addr
48 // The return address should not be calculated into R11 because if the push 56 // The return address should not be calculated into R11 because if the push
49 // instruction ends up at the start of a bundle, an attacker could arrange 57 // instruction ends up at the start of a bundle, an attacker could arrange
50 // an indirect jump to it, which would push the full jump target 58 // an indirect jump to it, which would push the full jump target
51 // (which itself was calculated into r11) onto the stack. 59 // (which itself was calculated into r11) onto the stack.
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 const MCSubtargetInfo &STI, 566 const MCSubtargetInfo &STI,
559 bool EmitPrefixes) { 567 bool EmitPrefixes) {
560 if (EmitPrefixes) { 568 if (EmitPrefixes) {
561 for (const MCInst &Prefix : Prefixes) 569 for (const MCInst &Prefix : Prefixes)
562 Out.EmitInstruction(Prefix, STI); 570 Out.EmitInstruction(Prefix, STI);
563 Prefixes.clear(); 571 Prefixes.clear();
564 } 572 }
565 Out.EmitInstruction(Inst, STI); 573 Out.EmitInstruction(Inst, STI);
566 } 574 }
567 575
576
568 void X86::X86MCNaClExpander::doExpandInst(const MCInst &Inst, MCStreamer &Out, 577 void X86::X86MCNaClExpander::doExpandInst(const MCInst &Inst, MCStreamer &Out,
569 const MCSubtargetInfo &STI, 578 const MCSubtargetInfo &STI,
570 bool EmitPrefixes) { 579 bool EmitPrefixes) {
571 580
581
572 // Explicitly IGNORE all pseudo instructions, these will be handled in the 582 // Explicitly IGNORE all pseudo instructions, these will be handled in the
573 // older customExpandInst code 583 // older customExpandInst code
574 switch (Inst.getOpcode()) { 584 switch (Inst.getOpcode()) {
575 case X86::CALLpcrel32: 585 case X86::CALLpcrel32:
576 case X86::CALL64pcrel32: 586 case X86::CALL64pcrel32:
577 case X86::NACL_CALL64d: 587 case X86::NACL_CALL64d:
578 case X86::NACL_CALL32r: 588 case X86::NACL_CALL32r:
579 case X86::NACL_CALL64r: 589 case X86::NACL_CALL64r:
580 case X86::NACL_JMP32r: 590 case X86::NACL_JMP32r:
581 case X86::NACL_JMP64r: 591 case X86::NACL_JMP64r:
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 } 638 }
629 } 639 }
630 640
631 bool X86::X86MCNaClExpander::expandInst(const MCInst &Inst, MCStreamer &Out, 641 bool X86::X86MCNaClExpander::expandInst(const MCInst &Inst, MCStreamer &Out,
632 const MCSubtargetInfo &STI) { 642 const MCSubtargetInfo &STI) {
633 if (Guard) 643 if (Guard)
634 return false; 644 return false;
635 Guard = true; 645 Guard = true;
636 646
637 doExpandInst(Inst, Out, STI, true); 647 doExpandInst(Inst, Out, STI, true);
648 invalidateScratchRegs(Inst);
638 649
639 Guard = false; 650 Guard = false;
640 return true; 651 return true;
641 } 652 }
642 653
643 static unsigned demoteOpcode(unsigned Opcode) { 654 static unsigned demoteOpcode(unsigned Opcode) {
644 switch (Opcode) { 655 switch (Opcode) {
645 case X86::ADC64rr: 656 case X86::ADC64rr:
646 return X86::ADC32rr; 657 return X86::ADC32rr;
647 case X86::ADC64ri8: 658 case X86::ADC64ri8:
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 case X86::XOR64ri8: 1190 case X86::XOR64ri8:
1180 return X86::XOR32ri8; 1191 return X86::XOR32ri8;
1181 case X86::XOR64ri32: 1192 case X86::XOR64ri32:
1182 return X86::XOR32ri; 1193 return X86::XOR32ri;
1183 case X86::XOR64rm: 1194 case X86::XOR64rm:
1184 return X86::XOR32rm; 1195 return X86::XOR32rm;
1185 default: 1196 default:
1186 return Opcode; 1197 return Opcode;
1187 } 1198 }
1188 } 1199 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698