From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KUIGK-0006d1-PE for qemu-devel@nongnu.org; Sat, 16 Aug 2008 05:39:56 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KUIGH-0006ad-Vu for qemu-devel@nongnu.org; Sat, 16 Aug 2008 05:39:55 -0400 Received: from [199.232.76.173] (port=39142 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KUIGG-0006ZR-Ks for qemu-devel@nongnu.org; Sat, 16 Aug 2008 05:39:53 -0400 Received: from fmmailgate02.web.de ([217.72.192.227]:47896) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KUIGG-0001C6-0x for qemu-devel@nongnu.org; Sat, 16 Aug 2008 05:39:52 -0400 Received: from smtp05.web.de (fmsmtp05.dlan.cinetic.de [172.20.4.166]) by fmmailgate02.web.de (Postfix) with ESMTP id 68559E8ED3D6 for ; Sat, 16 Aug 2008 11:39:51 +0200 (CEST) Received: from [88.64.23.108] (helo=[192.168.1.198]) by smtp05.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.109 #226) id 1KUIGF-0006fr-00 for qemu-devel@nongnu.org; Sat, 16 Aug 2008 11:39:51 +0200 Resent-To: qemu-devel@nongnu.org Resent-Message-Id: <48A6A060.5010200@web.de> Message-ID: <48A69E35.6090705@web.de> Date: Sat, 16 Aug 2008 11:30:29 +0200 From: Jan Kiszka MIME-Version: 1.0 References: <48A69B64.7050001@web.de> In-Reply-To: <48A69B64.7050001@web.de> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Sender: jan.kiszka@web.de Subject: [Qemu-devel] [PATCH 3/5] linux-user: Allocate guest-reachable descriptor tables Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 --- 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);