This commit is contained in:
John Reiser 2010-02-20 20:39:52 -08:00
commit 17fb86c0f1
8 changed files with 1930 additions and 1938 deletions

View File

@ -1671,6 +1671,9 @@ void PackLinuxElf32::pack1(OutputFile */*fo*/, Filter &/*ft*/)
while (x>>=1) {
++lg2_page;
}
if (hatch_off < 16 && Elf32_Ehdr::EM_ARM==e_machine) {
hatch_off = get_te32(&phdr->p_offset) + get_te32(&phdr->p_memsz);
}
}
}
page_size = 1u<<lg2_page;
@ -2269,10 +2272,10 @@ void PackLinuxElf32::pack4(OutputFile *fo, Filter &ft)
fo->seek(0, SEEK_SET);
if (0!=xct_off) { // shared library
ehdri.e_ident[0+hatch_off] = 0xcd; // INT 0x80 (syscall [munmap])
ehdri.e_ident[1+hatch_off] = 0x80;
ehdri.e_ident[2+hatch_off] = 0x61; // POPA
ehdri.e_ident[3+hatch_off] = 0xc3; // RET
ehdri.e_ident[12] = 0xcd; // INT 0x80 (syscall [munmap])
ehdri.e_ident[13] = 0x80;
ehdri.e_ident[14] = 0x61; // POPA
ehdri.e_ident[15] = 0xc3; // RET
fo->rewrite(&ehdri, sizeof(ehdri));
fo->rewrite(phdri, e_phnum * sizeof(*phdri));
}
@ -2328,11 +2331,11 @@ void PackLinuxElf64::pack4(OutputFile *fo, Filter &ft)
fo->seek(0, SEEK_SET);
if (0!=xct_off) { // shared library
ehdri.e_ident[0+hatch_off] = 0x0f; // syscall [munmap]
ehdri.e_ident[1+hatch_off] = 0x05;
ehdri.e_ident[2+hatch_off] = 0x5f; // pop %rdi (arg1)
ehdri.e_ident[3+hatch_off] = 0x5e; // pop %rsi (arg2)
ehdri.e_ident[4+hatch_off] = 0xc3; // RET
ehdri.e_ident[11] = 0x0f; // syscall [munmap]
ehdri.e_ident[12] = 0x05;
ehdri.e_ident[13] = 0x5f; // pop %rdi (arg1)
ehdri.e_ident[14] = 0x5e; // pop %rsi (arg2)
ehdri.e_ident[15] = 0xc3; // RET
fo->rewrite(&ehdri, sizeof(ehdri));
fo->rewrite(phdri, e_phnum * sizeof(*phdri));
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -39,25 +39,34 @@
__NR_SYSCALL_BASE = 0
.macro do_sys N
mov ip,#\N
swi 0x80 // returns Carry iff error
swi 0x80 // sets Carry iff error
orrcs r0,r0,#(1<<31) // force negative on error; FIXME: needed?
ret
.endm
.macro do_sys7t N
do_sys \N
.endm
#elif defined(ARMEL_EABI4) /*}{*/
__NR_SYSCALL_BASE = 0
.macro do_sys N
mov r12,r7 // save r7 in ip
.macro do_sys7t N
mov r7,#\N // syscall number
swi 0
.endm
.macro do_sys N
mov r12,r7 // save r7 in ip
do_sys7t \N
mov r7,r12 // restore r7 from ip
.endm
.macro do_sys2 N
mov r12,r7 // save r7 in ip
.macro do_sys7t2 N
mov r7, #(\N) & 0xff // syscall number
orr r7,r7,#(\N) &~0xff // high bits
swi 0
.endm
.macro do_sys2 N
mov r12,r7 // save r7 in ip
do_sys7t2 \N
mov r7,r12 // restore r7 from ip
.endm
@ -67,16 +76,22 @@ __NR_SYSCALL_BASE = 0x900000
.macro do_sys N
swi \N
.endm
.macro do_sys7t N
do_sys \N
.endm
.macro do_sys2 N
swi \N
.endm
.macro do_sys7t2 N
do_sys2 \N
.endm
#else /*}{*/
.macro do_sys N
error ARM_OLDABI, ARMEL_EABI4, ARMEL_DARWIN ?
error \N // ARM_OLDABI, ARMEL_EABI4, ARMEL_DARWIN ?
.endm
.macro do_sys2 N
error ARM_OLDABI, ARMEL_EABI4, ARMEL_DARWIN ?
error \N // ARM_OLDABI, ARMEL_EABI4, ARMEL_DARWIN ?
.endm
#endif /*}*/

View File

@ -34,6 +34,7 @@
.section \name
.endm
/* The order of #if-#elif matters: ARMEL_EABI4 takes precedence over ARM_OLDABI */
#if defined(ARMEL_DARWIN) /*{*/
__NR_SYSCALL_BASE = 0
.macro do_sys N
@ -42,6 +43,9 @@ __NR_SYSCALL_BASE = 0
orrcs r0,r0,#(1<<31) // force negative on error; FIXME: needed?
ret
.endm
.macro do_sys7t N
do_sys \N
.endm
.macro do_dcache_flush // In: r0=addr; r1=len
mov r3,#1 // _sys_dcache_flush
@ -57,17 +61,23 @@ __NR_SYSCALL_BASE = 0
#elif defined(ARMEL_EABI4) /*}{*/
__NR_SYSCALL_BASE = 0
.macro do_sys N
mov r12,r7 // save r7 in ip
.macro do_sys7t N
mov r7,#\N // syscall number
swi 0
.endm
.macro do_sys N
mov r12,r7 // save r7 in ip
do_sys7t \N
mov r7,r12 // restore r7 from ip
.endm
.macro do_sys2 N
mov r12,r7 // save r7 in ip
.macro do_sys7t2 N
mov r7, #(\N) & 0xff // syscall number
orr r7,r7,#(\N) &~0xff // high bits
swi 0
.endm
.macro do_sys2 N
mov r12,r7 // save r7 in ip
do_sys7t2 \N
mov r7,r12 // restore r7 from ip
.endm
@ -77,9 +87,15 @@ __NR_SYSCALL_BASE = 0x900000
.macro do_sys N
swi \N
.endm
.macro do_sys7t N
do_sys \N
.endm
.macro do_sys2 N
swi \N
.endm
.macro do_sys7t2 N
do_sys2 \N
.endm
#else /*}{*/
.macro do_sys N

View File

@ -33,6 +33,7 @@
#include "arch/arm/v5a/macros.S"
#define bkpt .long 0xe7f001f0 /* reserved instr; Linux GNU eabi breakpoint */
#define bkpt_th .short 0xde01 /* reserved instr; Linux GNU eabi breakpoint */
sz_Elf32_Ehdr = 13*4
sz_Elf32_Phdr = 8*4
@ -86,15 +87,9 @@ __ARM_NR_cacheflush = 2 + __ARM_NR_BASE
_start: .globl _start
stmdb sp!,{arg1,arg2,arg3, eax,ecx,r6,r7, fp,lr,pc}
o_uinit= (3+4+2)*4
//hatch:
// syscall // munmap
// ldmia sp!,{arg1,arg2,arg3, eax,ecx,r6,r7, fp,lr,pc}
mov fp,sp
sub sp,sp,#4
o_hatch= -1*4
o_uinit= (3+4+2)*4 // pc
bl main // push &f_decompress
f_decompress:
#define LINUX_ARM_CACHEFLUSH 1
@ -180,7 +175,8 @@ main:
mov ecx,esi
lodsl; sub ecx,ecx,eax; //str ecx,[fp,#o_reloc]
lodsl; add eax,ecx,eax; str eax,[fp,#o_uinit] // reloc DT_INIT for step 12
lodsl; add eax,ecx,eax; str eax,[fp,#o_hatch] // reloc &hatch for step 10
lodsl; add eax,ecx,eax; push eax // reloc &hatch for step 10
o_hatch= -1*4
lodsl; add edi,ecx,eax // &p_info; also destination for decompress
add esi,edi,#sz_p_info // &b_info
@ -235,7 +231,7 @@ top_unf:
tst_unf:
cmp len,#0
bne top_unf
mov pc,lr
ret
#undef ptr
#undef len
@ -264,6 +260,9 @@ o_uncpr= -13*4
push esi // src; arglist ready for decompress step 6
p_uncpr= -17*4
and tmp,esi,#3 // length of prefix alignment
add ecx,ecx,#3 // allow suffix alignment
add ecx,ecx,tmp // prefix increases byte length
ldr tmp,[fp,#o_wfrag]; add edx,tmp,ecx,lsr #2 // w_srclen + w_frag
ldr tmp,[fp,#o_uncpr]; bl wlen_subr
ldr tmp,[fp,#o_unflt]; bl wlen_subr
@ -277,17 +276,29 @@ supervise:
mov arg3,#PROT_READ|PROT_WRITE
ldr arg2,[fp,#p_mprot+4] // dstlen
ldr arg1,[fp,#p_mprot ] // dst
do_sys __NR_mmap64; cmn r0,#4096; bcc 0f; bkpt; 0:
mov r6,arg1 // required result
do_sys7t __NR_mmap64; cmp r0,r6; beq 0f; bkpt; 0:
// Restore fragment of page below dst
ldr ecx,[fp,#o_wfrag]
mov edi,r0
//mov edi,r0 // NOP: edi==r0
ldr esi,[fp,#p_unmap]
bl movsl
ldmia sp!,{arg1,arg2,arg3,arg4, eax}
blx eax // decompress
add sp,sp,#4 // toss arg5
bl L620
//hatch:
do_sys7t __NR_munmap
ldmia sp!,{arg1,arg2,arg3, eax,ecx,r6,r7, fp,lr,pc}
L620: // Implant escape hatch at end of .text
ldr eax,[fp,#o_hatch]
ldmia lr,{arg1,arg2,arg3}
stmia eax,{arg1,arg2,arg3}
//p_unflt
ldmia sp!,{arg1,arg2,arg3,arg4, eax}
tst arg4,arg4; beq 0f // 0==ftid ==> no filter
@ -299,17 +310,16 @@ supervise:
ldr arg2,[sp,#1*4] // len
mov arg3,#0
add arg2,arg2,arg1 // hi(dst)
do_sys2 __ARM_NR_cacheflush
add arg2,arg2,#3*4 // len(hatch)
do_sys7t2 __ARM_NR_cacheflush
ldmia sp!,{arg1,arg2}
mov arg3,#PROT_READ|PROT_EXEC
do_sys __NR_mprotect
do_sys7t __NR_mprotect
//p_unmap
//ldmia sp!,{arg1,arg2, pc}
add sp,sp,#-p_unmap
ldmia sp!,{arg1,arg2,arg3, eax,ecx,r6,r7, fp,lr,pc}
ldmia sp!,{arg1,arg2, r3} // r3= &hatch
bx r3
movsl_subr:
ldr ecx,[esi,#-4] // 'bl <over>' instruction word
@ -333,18 +343,24 @@ o_super= -18*4
mov arg3,#PROT_READ|PROT_WRITE|PROT_EXEC
str arg2,[fp,#p_unmap+1*4] // length to unmap
mov arg1,#0 // any addr
do_sys __NR_mmap64; cmn r0,#4096; bcc 0f; bkpt; 0:
do_sys7t __NR_mmap64; cmn r0,#4096; bcc 0f; bkpt; 0:
str r0,[fp,#p_unmap+0*4] // address to unmap
ldr esi,[fp,#p_mprot]
mov edi,r0 // edi= dst
//mov edi,r0 // edi= dst NOP: edi==r0
ldr ecx,[fp,#o_wfrag] // w_fragment
bl movsl // copy the fragment
ldr ecx,[fp,#p_uncpr+1*4] // len
ldr esi,[fp,#p_uncpr+0*4] // src
str edi,[fp,#p_uncpr+0*4] // dst
bl memcpyW // copy compressed data
ldr ecx,[fp,#p_uncpr+1*4] // len
and tmp,esi,#3 // length of prefix alignment
sub esi,esi,tmp // down to word aligned
add ecx,ecx,tmp // prefix increases byte length
add tmp,tmp,edi // skip prefix at destination
str tmp,[fp,#p_uncpr+0*4] // dst
add ecx,ecx,#3 // round up to full words
lsr ecx,ecx,#2
bl movsl // copy all aligned words that contain compressed data
mov edx,edi // lo(dst) of copied code
@ -363,7 +379,7 @@ o_super= -18*4
mov arg2,edi // hi(dst) of copied code
mov arg1,edx // lo(dst) of copied code
mov arg3,#0
do_sys2 __ARM_NR_cacheflush
do_sys7t2 __ARM_NR_cacheflush
pop pc // goto copied supervisor
@ -381,37 +397,6 @@ wlen_subr: // edx+= nwords of inline subr at *tmp
add edx,edx,tmp
ret
// dst (edi) is 4-byte aligned.
// src (esi) is unknown aligned
// cnt (ecx) is bytes
// Round up count to full words.
memcpyW:
add ecx,ecx,#3
lsr ecx,ecx,#2
tst esi,#3; beq movsl // 4-byte aligned
tst esi,#1; beq movsw2 // 2-byte aligned
movsb4:
ldrb tmp,[esi],#1
ldrb r6, [esi],#1
ldrb r12,[esi],#1
ldrb r7, [esi],#1
orr tmp,tmp,r6,lsl #8
orr r12,r12,r7,lsl #8
subs ecx,ecx,#1
orr tmp,tmp,r12,lsl #16
str tmp,[edi],#4
bne movsb4
ret
movsw2:
ldrh tmp,[esi],#2
ldrh r12,[esi],#2
subs ecx,ecx,#1
orr tmp,tmp,r12,lsl #16
str tmp,[edi],#4
bne movsw2
ret
/*__XTHEENDX__*/
/*
vi:ts=8:et:nowrap

View File

@ -2,18 +2,18 @@ file format elf32-littlearm
Sections:
Idx Name Size VMA LMA File off Algn Flags
0 ELFMAINX 00000010 00000000 00000000 00000034 2**0 CONTENTS, RELOC, READONLY
1 NRV_HEAD 00000000 00000000 00000000 00000044 2**0 CONTENTS, READONLY
2 NRV_TAIL 00000000 00000000 00000000 00000044 2**0 CONTENTS, READONLY
3 NRV2E 0000012c 00000000 00000000 00000044 2**0 CONTENTS, RELOC, READONLY
4 NRV2D 00000118 00000000 00000000 00000170 2**0 CONTENTS, RELOC, READONLY
5 NRV2B 000000dc 00000000 00000000 00000288 2**0 CONTENTS, RELOC, READONLY
6 LZMA_ELF00 000000a8 00000000 00000000 00000364 2**0 CONTENTS, RELOC, READONLY
7 LZMA_DEC20 00000938 00000000 00000000 0000040c 2**0 CONTENTS, RELOC, READONLY
8 LZMA_DEC10 00000478 00000000 00000000 00000d44 2**0 CONTENTS, RELOC, READONLY
9 LZMA_DEC30 00000000 00000000 00000000 000011bc 2**0 CONTENTS, READONLY
10 ELFMAINY 00000036 00000000 00000000 000011bc 2**0 CONTENTS, READONLY
11 ELFMAINZ 000002e4 00000000 00000000 000011f2 2**0 CONTENTS, RELOC, READONLY
0 ELFMAINX 0000000c 00000000 00000000 00000034 2**0 CONTENTS, RELOC, READONLY
1 NRV_HEAD 00000000 00000000 00000000 00000040 2**0 CONTENTS, READONLY
2 NRV_TAIL 00000000 00000000 00000000 00000040 2**0 CONTENTS, READONLY
3 NRV2E 0000012c 00000000 00000000 00000040 2**0 CONTENTS, RELOC, READONLY
4 NRV2D 00000118 00000000 00000000 0000016c 2**0 CONTENTS, RELOC, READONLY
5 NRV2B 000000dc 00000000 00000000 00000284 2**0 CONTENTS, RELOC, READONLY
6 LZMA_ELF00 000000a8 00000000 00000000 00000360 2**0 CONTENTS, RELOC, READONLY
7 LZMA_DEC20 00000938 00000000 00000000 00000408 2**0 CONTENTS, RELOC, READONLY
8 LZMA_DEC10 00000478 00000000 00000000 00000d40 2**0 CONTENTS, RELOC, READONLY
9 LZMA_DEC30 00000000 00000000 00000000 000011b8 2**0 CONTENTS, READONLY
10 ELFMAINY 00000036 00000000 00000000 000011b8 2**0 CONTENTS, READONLY
11 ELFMAINZ 000002c0 00000000 00000000 000011ee 2**0 CONTENTS, RELOC, READONLY
SYMBOL TABLE:
00000000 l d NRV2E 00000000 NRV2E
00000000 l d NRV2D 00000000 NRV2D
@ -36,7 +36,7 @@ SYMBOL TABLE:
RELOCATION RECORDS FOR [ELFMAINX]:
OFFSET TYPE VALUE
0000000c R_ARM_PC24 ELFMAINZ
00000008 R_ARM_PC24 ELFMAINZ
RELOCATION RECORDS FOR [NRV2E]:
OFFSET TYPE VALUE
@ -251,21 +251,18 @@ OFFSET TYPE VALUE
000000b8 R_ARM_PC24 ELFMAINZ
000000dc R_ARM_PC24 ELFMAINZ
000000e4 R_ARM_PC24 ELFMAINZ
00000110 R_ARM_PC24 ELFMAINZ
00000118 R_ARM_PC24 ELFMAINZ
0000011c R_ARM_PC24 ELFMAINZ
0000013c R_ARM_PC24 ELFMAINZ
00000150 R_ARM_PC24 ELFMAINZ
00000168 R_ARM_PC24 ELFMAINZ
000001b4 R_ARM_PC24 ELFMAINZ
000001c4 R_ARM_PC24 ELFMAINZ
000001e8 R_ARM_PC24 ELFMAINZ
00000200 R_ARM_PC24 ELFMAINZ
00000124 R_ARM_PC24 ELFMAINZ
00000128 R_ARM_PC24 ELFMAINZ
0000014c R_ARM_PC24 ELFMAINZ
0000015c R_ARM_PC24 ELFMAINZ
0000016c R_ARM_PC24 ELFMAINZ
0000018c R_ARM_PC24 ELFMAINZ
000001dc R_ARM_PC24 ELFMAINZ
000001ec R_ARM_PC24 ELFMAINZ
00000210 R_ARM_PC24 ELFMAINZ
00000220 R_ARM_PC24 ELFMAINZ
0000022c R_ARM_PC24 ELFMAINZ
00000238 R_ARM_PC24 ELFMAINZ
00000290 R_ARM_PC24 ELFMAINZ
00000298 R_ARM_PC24 ELFMAINZ
000002c0 R_ARM_PC24 ELFMAINZ
000002dc R_ARM_PC24 ELFMAINZ
00000224 R_ARM_PC24 ELFMAINZ
0000024c R_ARM_PC24 ELFMAINZ
0000025c R_ARM_PC24 ELFMAINZ
00000268 R_ARM_PC24 ELFMAINZ
00000274 R_ARM_PC24 ELFMAINZ

View File

@ -2,18 +2,18 @@ file format elf32-littlearm
Sections:
Idx Name Size VMA LMA File off Algn Flags
0 ELFMAINX 00000010 00000000 00000000 00000034 2**0 CONTENTS, RELOC, READONLY
1 NRV_HEAD 00000000 00000000 00000000 00000044 2**0 CONTENTS, READONLY
2 NRV_TAIL 00000000 00000000 00000000 00000044 2**0 CONTENTS, READONLY
3 NRV2E 0000013c 00000000 00000000 00000044 2**0 CONTENTS, RELOC, READONLY
4 NRV2D 00000128 00000000 00000000 00000180 2**0 CONTENTS, RELOC, READONLY
5 NRV2B 000000ec 00000000 00000000 000002a8 2**0 CONTENTS, RELOC, READONLY
6 LZMA_ELF00 000000b8 00000000 00000000 00000394 2**0 CONTENTS, RELOC, READONLY
7 LZMA_DEC20 00000938 00000000 00000000 0000044c 2**0 CONTENTS, RELOC, READONLY
8 LZMA_DEC10 00000478 00000000 00000000 00000d84 2**0 CONTENTS, RELOC, READONLY
9 LZMA_DEC30 00000000 00000000 00000000 000011fc 2**0 CONTENTS, READONLY
10 ELFMAINY 0000003e 00000000 00000000 000011fc 2**0 CONTENTS, READONLY
11 ELFMAINZ 00000328 00000000 00000000 0000123a 2**0 CONTENTS, RELOC, READONLY
0 ELFMAINX 0000000c 00000000 00000000 00000034 2**0 CONTENTS, RELOC, READONLY
1 NRV_HEAD 00000000 00000000 00000000 00000040 2**0 CONTENTS, READONLY
2 NRV_TAIL 00000000 00000000 00000000 00000040 2**0 CONTENTS, READONLY
3 NRV2E 0000013c 00000000 00000000 00000040 2**0 CONTENTS, RELOC, READONLY
4 NRV2D 00000128 00000000 00000000 0000017c 2**0 CONTENTS, RELOC, READONLY
5 NRV2B 000000ec 00000000 00000000 000002a4 2**0 CONTENTS, RELOC, READONLY
6 LZMA_ELF00 000000b8 00000000 00000000 00000390 2**0 CONTENTS, RELOC, READONLY
7 LZMA_DEC20 00000938 00000000 00000000 00000448 2**0 CONTENTS, RELOC, READONLY
8 LZMA_DEC10 00000478 00000000 00000000 00000d80 2**0 CONTENTS, RELOC, READONLY
9 LZMA_DEC30 00000000 00000000 00000000 000011f8 2**0 CONTENTS, READONLY
10 ELFMAINY 0000003e 00000000 00000000 000011f8 2**0 CONTENTS, READONLY
11 ELFMAINZ 000002e0 00000000 00000000 00001236 2**0 CONTENTS, RELOC, READONLY
SYMBOL TABLE:
00000000 l d NRV2E 00000000 NRV2E
00000000 l d NRV2D 00000000 NRV2D
@ -36,7 +36,7 @@ SYMBOL TABLE:
RELOCATION RECORDS FOR [ELFMAINX]:
OFFSET TYPE VALUE
0000000c R_ARM_PC24 ELFMAINZ
00000008 R_ARM_PC24 ELFMAINZ
RELOCATION RECORDS FOR [NRV2E]:
OFFSET TYPE VALUE
@ -251,21 +251,18 @@ OFFSET TYPE VALUE
000000b8 R_ARM_PC24 ELFMAINZ
000000dc R_ARM_PC24 ELFMAINZ
000000e4 R_ARM_PC24 ELFMAINZ
00000110 R_ARM_PC24 ELFMAINZ
00000118 R_ARM_PC24 ELFMAINZ
0000011c R_ARM_PC24 ELFMAINZ
00000148 R_ARM_PC24 ELFMAINZ
0000015c R_ARM_PC24 ELFMAINZ
00000174 R_ARM_PC24 ELFMAINZ
000001dc R_ARM_PC24 ELFMAINZ
000001ec R_ARM_PC24 ELFMAINZ
0000021c R_ARM_PC24 ELFMAINZ
00000234 R_ARM_PC24 ELFMAINZ
00000244 R_ARM_PC24 ELFMAINZ
00000254 R_ARM_PC24 ELFMAINZ
00000260 R_ARM_PC24 ELFMAINZ
0000026c R_ARM_PC24 ELFMAINZ
000002d4 R_ARM_PC24 ELFMAINZ
000002dc R_ARM_PC24 ELFMAINZ
00000304 R_ARM_PC24 ELFMAINZ
00000320 R_ARM_PC24 ELFMAINZ
00000124 R_ARM_PC24 ELFMAINZ
00000128 R_ARM_PC24 ELFMAINZ
00000150 R_ARM_PC24 ELFMAINZ
00000160 R_ARM_PC24 ELFMAINZ
00000170 R_ARM_PC24 ELFMAINZ
00000194 R_ARM_PC24 ELFMAINZ
000001f0 R_ARM_PC24 ELFMAINZ
00000200 R_ARM_PC24 ELFMAINZ
00000228 R_ARM_PC24 ELFMAINZ
0000023c R_ARM_PC24 ELFMAINZ
00000264 R_ARM_PC24 ELFMAINZ
00000274 R_ARM_PC24 ELFMAINZ
00000280 R_ARM_PC24 ELFMAINZ
0000028c R_ARM_PC24 ELFMAINZ