Skip to content

Commit b5a2b79

Browse files
committed
simx86: enable W^X layout
Update cpatch to resolve the fault address. Just that simple now?? Thanks Bart!
1 parent ca878a8 commit b5a2b79

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/base/emu-i386/simx86/codebuf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void InitGenCodeBuf(void)
3939
{
4040
void *addr;
4141

42-
#if HAVE_DECL_MREMAP_MAYMOVE && 0
42+
#if HAVE_DECL_MREMAP_MAYMOVE
4343
int err;
4444

4545
addr = mmap(NULL, CODEBUF_SZ, PROT_NONE,

src/base/emu-i386/simx86/cpatch.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -606,15 +606,15 @@ int Cpatch(sigcontext_t *scp)
606606
#if PROFILE
607607
CpatchTotal++;
608608
#endif
609-
p = eip;
609+
p = GetGenCodeBuf(eip);
610610
if ((*p==0xf2 || *p==0xf3) && (p[1] == 0x66 || p[2] == 0x90) &&
611611
p[3] == 0x90 && p[4] == 0x90) {
612612
unsigned char op;
613613

614614
// rep movs, rep stos, rep lods, rep scas, rep cmps
615615
// we have a sequence: f2/f3 op 90 90 90
616616
// or f2/f3 66 op 90 90 (f2 for cmps/scas only)
617-
if (debug_level('e')>1) e_printf("### REP patch at %p\n",eip);
617+
if (debug_level('e')>1) e_printf("### REP patch at %p\n",p);
618618
op = p[1];
619619
/* as all ops are between 0xa4 and 0xaf we can encode override
620620
prefix as 0x10 and repne as 0x40 */
@@ -659,14 +659,14 @@ int Cpatch(sigcontext_t *scp)
659659
}
660660
if (v==0x2f0488) { // movb %%al,(%%edi,%%ebp,1)
661661
// we have a sequence: 88 04 2f
662-
if (debug_level('e')>1) e_printf("### Byte write patch at %p\n",eip);
662+
if (debug_level('e')>1) e_printf("### Byte write patch at %p\n",p);
663663
JSRPATCH(p,Ofs_stub_wri_8);
664664
return 1;
665665
}
666666
if (v==0x2f0489) { // mov %%{e}ax,(%%edi,%%ebp,1)
667667
// we have a sequence: 89 04 2f
668668
// or 66 89 04 2f
669-
if (debug_level('e')>1) e_printf("### Word/Long write patch at %p\n",eip);
669+
if (debug_level('e')>1) e_printf("### Word/Long write patch at %p\n",p);
670670
if (w16) {
671671
p[-1] = 0x90; JSRPATCH(p,Ofs_stub_wri_16);;
672672
}
@@ -677,14 +677,14 @@ int Cpatch(sigcontext_t *scp)
677677
}
678678
if (v==0x2f048a) { // movb (%%edi,%%ebp,1),%%al
679679
// we have a sequence: 8a 04 2f 90 90 90
680-
if (debug_level('e')>1) e_printf("### Byte read patch at %p\n",eip);
680+
if (debug_level('e')>1) e_printf("### Byte read patch at %p\n",p);
681681
JSRPATCH(p,Ofs_stub_read_8);
682682
return 1;
683683
}
684684
if (v==0x2f048b) { // mov (%%edi,%%ebp,1),%%{e}ax
685685
// we have a sequence: 8b 04 2f
686686
// or 66 8b 04 2f
687-
if (debug_level('e')>1) e_printf("### Word/Long read patch at %p\n",eip);
687+
if (debug_level('e')>1) e_printf("### Word/Long read patch at %p\n",p);
688688
if (w16) {
689689
p[-1] = 0x90; JSRPATCH(p,Ofs_stub_read_16);
690690
}
@@ -700,12 +700,12 @@ int Cpatch(sigcontext_t *scp)
700700
int UnCpatch(unsigned char *eip)
701701
{
702702
unsigned char *p;
703-
p = eip;
703+
p = GetGenCodeBuf(eip);
704704

705-
if (*eip != 0xff) return 1;
705+
if (*p != 0xff) return 1;
706706
if (debug_level('e')) {
707-
e_printf("UnCpatch at %p was %02x%02x%02x%02x%02x\n",eip,
708-
eip[0],eip[1],eip[2],eip[3],eip[4]);
707+
e_printf("UnCpatch at %p was %02x%02x%02x%02x%02x\n",p,
708+
p[0],p[1],p[2],p[3],p[4]);
709709
}
710710
#if PROFILE
711711
UncpatchTotal++;
@@ -742,8 +742,8 @@ int UnCpatch(unsigned char *eip)
742742
}
743743
else return 1;
744744
if (debug_level('e')) {
745-
e_printf("UnCpatched at %p is %02x%02x%02x%02x%02x\n",eip,
746-
eip[0],eip[1],eip[2],eip[3],eip[4]);
745+
e_printf("UnCpatched at %p is %02x%02x%02x%02x%02x\n",p,
746+
p[0],p[1],p[2],p[3],p[4]);
747747
}
748748
return 0;
749749
}

0 commit comments

Comments
 (0)