(t *testing.T)
| 658 | } |
| 659 | |
| 660 | func TestComputeBase(t *testing.T) { |
| 661 | realELFOpen := elfOpen |
| 662 | defer func() { |
| 663 | elfOpen = realELFOpen |
| 664 | }() |
| 665 | |
| 666 | tinyExecFile := &elf.File{ |
| 667 | FileHeader: elf.FileHeader{Type: elf.ET_EXEC}, |
| 668 | Progs: []*elf.Prog{ |
| 669 | {ProgHeader: elf.ProgHeader{Type: elf.PT_PHDR, Flags: elf.PF_R | elf.PF_X, Off: 0x40, Vaddr: 0x400040, Paddr: 0x400040, Filesz: 0x1f8, Memsz: 0x1f8, Align: 8}}, |
| 670 | {ProgHeader: elf.ProgHeader{Type: elf.PT_INTERP, Flags: elf.PF_R, Off: 0x238, Vaddr: 0x400238, Paddr: 0x400238, Filesz: 0x1c, Memsz: 0x1c, Align: 1}}, |
| 671 | {ProgHeader: elf.ProgHeader{Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_X, Off: 0, Vaddr: 0, Paddr: 0, Filesz: 0xc80, Memsz: 0xc80, Align: 0x200000}}, |
| 672 | {ProgHeader: elf.ProgHeader{Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_W, Off: 0xc80, Vaddr: 0x200c80, Paddr: 0x200c80, Filesz: 0x1f0, Memsz: 0x1f0, Align: 0x200000}}, |
| 673 | }, |
| 674 | } |
| 675 | tinyBadBSSExecFile := &elf.File{ |
| 676 | FileHeader: elf.FileHeader{Type: elf.ET_EXEC}, |
| 677 | Progs: []*elf.Prog{ |
| 678 | {ProgHeader: elf.ProgHeader{Type: elf.PT_PHDR, Flags: elf.PF_R | elf.PF_X, Off: 0x40, Vaddr: 0x400040, Paddr: 0x400040, Filesz: 0x1f8, Memsz: 0x1f8, Align: 8}}, |
| 679 | {ProgHeader: elf.ProgHeader{Type: elf.PT_INTERP, Flags: elf.PF_R, Off: 0x238, Vaddr: 0x400238, Paddr: 0x400238, Filesz: 0x1c, Memsz: 0x1c, Align: 1}}, |
| 680 | {ProgHeader: elf.ProgHeader{Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_X, Off: 0, Vaddr: 0, Paddr: 0, Filesz: 0xc80, Memsz: 0xc80, Align: 0x200000}}, |
| 681 | {ProgHeader: elf.ProgHeader{Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_W, Off: 0xc80, Vaddr: 0x200c80, Paddr: 0x200c80, Filesz: 0x100, Memsz: 0x1f0, Align: 0x200000}}, |
| 682 | {ProgHeader: elf.ProgHeader{Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_W, Off: 0xd80, Vaddr: 0x400d80, Paddr: 0x400d80, Filesz: 0x90, Memsz: 0x90, Align: 0x200000}}, |
| 683 | }, |
| 684 | } |
| 685 | |
| 686 | for _, tc := range []struct { |
| 687 | desc string |
| 688 | file *elf.File |
| 689 | openErr error |
| 690 | mapping *elfMapping |
| 691 | addr uint64 |
| 692 | wantError bool |
| 693 | wantBase uint64 |
| 694 | wantIsData bool |
| 695 | }{ |
| 696 | { |
| 697 | desc: "no elf mapping, no error", |
| 698 | mapping: nil, |
| 699 | addr: 0x1000, |
| 700 | wantBase: 0, |
| 701 | wantIsData: false, |
| 702 | }, |
| 703 | { |
| 704 | desc: "address outside mapping bounds means error", |
| 705 | file: &elf.File{}, |
| 706 | mapping: &elfMapping{start: 0x2000, limit: 0x5000, offset: 0x1000}, |
| 707 | addr: 0x1000, |
| 708 | wantError: true, |
| 709 | }, |
| 710 | { |
| 711 | desc: "elf.Open failing means error", |
| 712 | file: &elf.File{FileHeader: elf.FileHeader{Type: elf.ET_EXEC}}, |
| 713 | openErr: errors.New("elf.Open failed"), |
| 714 | mapping: &elfMapping{start: 0x2000, limit: 0x5000, offset: 0x1000}, |
| 715 | addr: 0x4000, |
| 716 | wantError: true, |
| 717 | }, |
nothing calls this directly
no test coverage detected
searching dependent graphs…