|
|
1f061d |
commit c7bcd1f2ee2d466fb556bfc2b33c5ab039b0898d
|
|
|
1f061d |
Author: sewardj <sewardj@a5019735-40e9-0310-863c-91ae7b9d1cf9>
|
|
|
1f061d |
Date: Fri Jan 20 09:58:15 2017 +0000
|
|
|
1f061d |
|
|
|
1f061d |
x86-linux: Initialize x86 system GDT on first use. Bug 344139 comment 3.
|
|
|
1f061d |
Patch from Sebastian Lackner, sebastian@fds-team.de.
|
|
|
1f061d |
|
|
|
1f061d |
|
|
|
1f061d |
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16204 a5019735-40e9-0310-863c-91ae7b9d1cf9
|
|
|
1f061d |
|
|
|
1f061d |
diff --git a/coregrind/m_syswrap/syswrap-x86-linux.c b/coregrind/m_syswrap/syswrap-x86-linux.c
|
|
|
1f061d |
index f8c4eb4..2f879d8 100644
|
|
|
1f061d |
--- a/coregrind/m_syswrap/syswrap-x86-linux.c
|
|
|
1f061d |
+++ b/coregrind/m_syswrap/syswrap-x86-linux.c
|
|
|
1f061d |
@@ -294,11 +294,37 @@ void translate_to_hw_format ( /* IN */ vki_modify_ldt_t* inn,
|
|
|
1f061d |
out->LdtEnt.Words.word2 = entry_2;
|
|
|
1f061d |
}
|
|
|
1f061d |
|
|
|
1f061d |
-/* Create a zeroed-out GDT. */
|
|
|
1f061d |
-static VexGuestX86SegDescr* alloc_zeroed_x86_GDT ( void )
|
|
|
1f061d |
+/* Create initial GDT. */
|
|
|
1f061d |
+static VexGuestX86SegDescr* alloc_system_x86_GDT ( void )
|
|
|
1f061d |
{
|
|
|
1f061d |
Int nbytes = VEX_GUEST_X86_GDT_NENT * sizeof(VexGuestX86SegDescr);
|
|
|
1f061d |
- return VG_(calloc)("di.syswrap-x86.azxG.1", nbytes, 1);
|
|
|
1f061d |
+ VexGuestX86SegDescr* gdt = VG_(calloc)("di.syswrap-x86.azxG.1", nbytes, 1);
|
|
|
1f061d |
+ vki_modify_ldt_t info;
|
|
|
1f061d |
+ UShort seg;
|
|
|
1f061d |
+
|
|
|
1f061d |
+ VG_(memset)(&info, 0, sizeof(info));
|
|
|
1f061d |
+ info.entry_number = 0;
|
|
|
1f061d |
+ info.base_addr = 0;
|
|
|
1f061d |
+ info.limit = 0xfffff;
|
|
|
1f061d |
+ info.seg_32bit = 1;
|
|
|
1f061d |
+ info.contents = 0;
|
|
|
1f061d |
+ info.read_exec_only = 0;
|
|
|
1f061d |
+ info.limit_in_pages = 1;
|
|
|
1f061d |
+ info.seg_not_present = 0;
|
|
|
1f061d |
+ info.useable = 0;
|
|
|
1f061d |
+ info.reserved = 0;
|
|
|
1f061d |
+
|
|
|
1f061d |
+ asm volatile("movw %%ds, %0" : : "m" (seg));
|
|
|
1f061d |
+ if (!(seg & 4)) translate_to_hw_format(&info, &gdt[seg >> 3], 0);
|
|
|
1f061d |
+ asm volatile("movw %%ss, %0" : : "m" (seg));
|
|
|
1f061d |
+ if (!(seg & 4)) translate_to_hw_format(&info, &gdt[seg >> 3], 0);
|
|
|
1f061d |
+
|
|
|
1f061d |
+ info.contents = 2;
|
|
|
1f061d |
+
|
|
|
1f061d |
+ asm volatile("movw %%cs, %0" : : "m" (seg));
|
|
|
1f061d |
+ if (!(seg & 4)) translate_to_hw_format(&info, &gdt[seg >> 3], 0);
|
|
|
1f061d |
+
|
|
|
1f061d |
+ return gdt;
|
|
|
1f061d |
}
|
|
|
1f061d |
|
|
|
1f061d |
/* Create a zeroed-out LDT. */
|
|
|
1f061d |
@@ -505,7 +531,7 @@ SysRes ML_(x86_sys_set_thread_area) ( ThreadId tid, vki_modify_ldt_t* info )
|
|
|
1f061d |
|
|
|
1f061d |
/* If the thread doesn't have a GDT, allocate it now. */
|
|
|
1f061d |
if (!gdt) {
|
|
|
1f061d |
- gdt = alloc_zeroed_x86_GDT();
|
|
|
1f061d |
+ gdt = alloc_system_x86_GDT();
|
|
|
1f061d |
VG_(threads)[tid].arch.vex.guest_GDT = (HWord)gdt;
|
|
|
1f061d |
}
|
|
|
1f061d |
|
|
|
1f061d |
@@ -564,7 +590,7 @@ static SysRes sys_get_thread_area ( ThreadId tid, vki_modify_ldt_t* info )
|
|
|
1f061d |
|
|
|
1f061d |
/* If the thread doesn't have a GDT, allocate it now. */
|
|
|
1f061d |
if (!gdt) {
|
|
|
1f061d |
- gdt = alloc_zeroed_x86_GDT();
|
|
|
1f061d |
+ gdt = alloc_system_x86_GDT();
|
|
|
1f061d |
VG_(threads)[tid].arch.vex.guest_GDT = (HWord)gdt;
|
|
|
1f061d |
}
|
|
|
1f061d |
|
|
|
1f061d |
@@ -616,7 +642,7 @@ void ML_(x86_setup_LDT_GDT) ( /*OUT*/ ThreadArchState *child,
|
|
|
1f061d |
child->vex.guest_GDT = (HWord)NULL;
|
|
|
1f061d |
|
|
|
1f061d |
if (parent->vex.guest_GDT != (HWord)NULL) {
|
|
|
1f061d |
- child->vex.guest_GDT = (HWord)alloc_zeroed_x86_GDT();
|
|
|
1f061d |
+ child->vex.guest_GDT = (HWord)alloc_system_x86_GDT();
|
|
|
1f061d |
copy_GDT_from_to( (VexGuestX86SegDescr*)parent->vex.guest_GDT,
|
|
|
1f061d |
(VexGuestX86SegDescr*)child->vex.guest_GDT );
|
|
|
1f061d |
}
|
|
|
1f061d |
commit 5f4041b376f7465cd108ad4d1696b0b8a603a175
|
|
|
1f061d |
Author: sewardj <sewardj@8f6e269a-dfd6-0310-a8e1-e2731360e62c>
|
|
|
1f061d |
Date: Fri Jan 20 10:01:42 2017 +0000
|
|
|
1f061d |
|
|
|
1f061d |
x86: Recognize the SS segment prefix on x86. Bug 344139 comment 4.
|
|
|
1f061d |
Patch from Sebastian Lackner, sebastian@fds-team.de.
|
|
|
1f061d |
|
|
|
1f061d |
|
|
|
1f061d |
git-svn-id: svn://svn.valgrind.org/vex/trunk@3299 8f6e269a-dfd6-0310-a8e1-e2731360e62c
|
|
|
1f061d |
|
|
|
1f061d |
diff --git a/VEX/priv/guest_x86_toIR.c b/VEX/priv/guest_x86_toIR.c
|
|
|
1f061d |
index de09d3a..234d68e 100644
|
|
|
1f061d |
--- a/VEX/priv/guest_x86_toIR.c
|
|
|
1f061d |
+++ b/VEX/priv/guest_x86_toIR.c
|
|
|
1f061d |
@@ -1409,6 +1409,7 @@ const HChar* sorbTxt ( UChar sorb )
|
|
|
1f061d |
case 0x26: return "%es:";
|
|
|
1f061d |
case 0x64: return "%fs:";
|
|
|
1f061d |
case 0x65: return "%gs:";
|
|
|
1f061d |
+ case 0x36: return "%ss:";
|
|
|
1f061d |
default: vpanic("sorbTxt(x86,guest)");
|
|
|
1f061d |
}
|
|
|
1f061d |
}
|
|
|
1f061d |
@@ -1433,6 +1434,7 @@ IRExpr* handleSegOverride ( UChar sorb, IRExpr* virtual )
|
|
|
1f061d |
case 0x26: sreg = R_ES; break;
|
|
|
1f061d |
case 0x64: sreg = R_FS; break;
|
|
|
1f061d |
case 0x65: sreg = R_GS; break;
|
|
|
1f061d |
+ case 0x36: sreg = R_SS; break;
|
|
|
1f061d |
default: vpanic("handleSegOverride(x86,guest)");
|
|
|
1f061d |
}
|
|
|
1f061d |
|
|
|
1f061d |
@@ -8101,7 +8103,7 @@ DisResult disInstr_X86_WRK (
|
|
|
1f061d |
Int sz = 4;
|
|
|
1f061d |
|
|
|
1f061d |
/* sorb holds the segment-override-prefix byte, if any. Zero if no
|
|
|
1f061d |
- prefix has been seen, else one of {0x26, 0x3E, 0x64, 0x65}
|
|
|
1f061d |
+ prefix has been seen, else one of {0x26, 0x36, 0x3E, 0x64, 0x65}
|
|
|
1f061d |
indicating the prefix. */
|
|
|
1f061d |
UChar sorb = 0;
|
|
|
1f061d |
|
|
|
1f061d |
@@ -8255,6 +8257,7 @@ DisResult disInstr_X86_WRK (
|
|
|
1f061d |
case 0x26: /* %ES: */
|
|
|
1f061d |
case 0x64: /* %FS: */
|
|
|
1f061d |
case 0x65: /* %GS: */
|
|
|
1f061d |
+ case 0x36: /* %SS: */
|
|
|
1f061d |
if (sorb != 0)
|
|
|
1f061d |
goto decode_failure; /* only one seg override allowed */
|
|
|
1f061d |
sorb = pre;
|
|
|
1f061d |
@@ -8274,9 +8277,6 @@ DisResult disInstr_X86_WRK (
|
|
|
1f061d |
}
|
|
|
1f061d |
break;
|
|
|
1f061d |
}
|
|
|
1f061d |
- case 0x36: /* %SS: */
|
|
|
1f061d |
- /* SS override cases are not handled */
|
|
|
1f061d |
- goto decode_failure;
|
|
|
1f061d |
default:
|
|
|
1f061d |
goto not_a_prefix;
|
|
|
1f061d |
}
|