[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 3/5] linux-user: Allocate guest-reachable descriptor
From: |
Jan Kiszka |
Subject: |
[Qemu-devel] [PATCH 3/5] linux-user: Allocate guest-reachable descriptor tables |
Date: |
Sat, 16 Aug 2008 11:30:29 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 |
IDT, GDT and LDTs have to allocated from memory regions also reachable
by the guests. Obtain them via the new qemu_vmalloc_guest_safe service.
Signed-off-by: Jan Kiszka <address@hidden>
---
linux-user/i386/syscall.h | 2 ++
linux-user/main.c | 13 +++++++------
linux-user/syscall.c | 3 ++-
linux-user/x86_64/syscall.h | 2 ++
4 files changed, 13 insertions(+), 7 deletions(-)
Index: b/linux-user/main.c
===================================================================
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -280,9 +280,9 @@ static void write_dt(void *ptr, unsigned
p[1] = tswapl(e2);
}
-#if TARGET_X86_64
-uint64_t idt_table[512];
+uint64_t *idt_table;
+#if TARGET_X86_64
static void set_gate64(void *ptr, unsigned int type, unsigned int dpl,
uint64_t addr, unsigned int sel)
{
@@ -301,8 +301,6 @@ static void set_idt(int n, unsigned int
set_gate64(idt_table + n * 2, 0, dpl, 0, 0);
}
#else
-uint64_t idt_table[256];
-
static void set_gate(void *ptr, unsigned int type, unsigned int dpl,
uint32_t addr, unsigned int sel)
{
@@ -2444,8 +2442,10 @@ int main(int argc, char **argv)
#endif
/* linux interrupt setup */
+ idt_table = qemu_vmalloc_guest_safe(sizeof(uint64_t) * TARGET_IDT_ENTRIES);
+ memset(idt_table, 0, sizeof(uint64_t) * TARGET_IDT_ENTRIES);
env->idt.base = h2g(idt_table);
- env->idt.limit = sizeof(idt_table) - 1;
+ env->idt.limit = sizeof(uint64_t) * TARGET_IDT_ENTRIES - 1;
set_idt(0, 0);
set_idt(1, 0);
set_idt(2, 0);
@@ -2471,7 +2471,8 @@ int main(int argc, char **argv)
/* linux segment setup */
{
uint64_t *gdt_table;
- gdt_table = qemu_mallocz(sizeof(uint64_t) * TARGET_GDT_ENTRIES);
+ gdt_table = qemu_vmalloc_guest_safe(sizeof(uint64_t) *
TARGET_GDT_ENTRIES);
+ memset(gdt_table, 0, sizeof(uint64_t) * TARGET_GDT_ENTRIES);
env->gdt.base = h2g((unsigned long)gdt_table);
env->gdt.limit = sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1;
#ifdef TARGET_ABI32
Index: b/linux-user/i386/syscall.h
===================================================================
--- a/linux-user/i386/syscall.h
+++ b/linux-user/i386/syscall.h
@@ -22,6 +22,8 @@ struct target_pt_regs {
/* ioctls */
+#define TARGET_IDT_ENTRIES 256
+
#define TARGET_LDT_ENTRIES 8192
#define TARGET_LDT_ENTRY_SIZE 8
Index: b/linux-user/x86_64/syscall.h
===================================================================
--- a/linux-user/x86_64/syscall.h
+++ b/linux-user/x86_64/syscall.h
@@ -29,6 +29,8 @@ struct target_pt_regs {
/* top of stack page */
};
+#define TARGET_IDT_ENTRIES 512
+
/* Maximum number of LDT entries supported. */
#define TARGET_LDT_ENTRIES 8192
/* The size of each LDT entry. */
Index: b/linux-user/syscall.c
===================================================================
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2474,7 +2474,8 @@ static abi_long write_ldt(CPUX86State *e
}
/* allocate the LDT */
if (!ldt_table) {
- ldt_table = malloc(TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE);
+ ldt_table = qemu_vmalloc_guest_safe(TARGET_LDT_ENTRIES
+ * TARGET_LDT_ENTRY_SIZE);
if (!ldt_table)
return -TARGET_ENOMEM;
memset(ldt_table, 0, TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE);
- [Qemu-devel] [PATCH 0/5] linux-user: Detect and fix 32-bit guest on 64-bit host issues - v2, Jan Kiszka, 2008/08/16
- [Qemu-devel] [PATCH 1/5] linux-user: Safety belt for h2g, Jan Kiszka, 2008/08/16
- [Qemu-devel] [PATCH 4/5] linux-user: Introduce h2g_valid, Jan Kiszka, 2008/08/16
- [Qemu-devel] [PATCH 2/5] linux-user: Introduce qemu_vmalloc_guest_safe, Jan Kiszka, 2008/08/16
- [Qemu-devel] [PATCH 3/5] linux-user: Allocate guest-reachable descriptor tables,
Jan Kiszka <=
- [Qemu-devel] [PATCH 5/5] linux-user: Fix h2g usage in page_find_alloc, Jan Kiszka, 2008/08/16
- Re: [Qemu-devel] [PATCH 0/5] linux-user: Detect and fix 32-bit guest on 64-bit host issues - v2, Anthony Liguori, 2008/08/21