From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Kqiti-0003BC-EM for qemu-devel@nongnu.org; Fri, 17 Oct 2008 02:33:18 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Kqite-0003Al-UJ for qemu-devel@nongnu.org; Fri, 17 Oct 2008 02:33:18 -0400 Received: from [199.232.76.173] (port=48858 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kqite-0003Ai-OK for qemu-devel@nongnu.org; Fri, 17 Oct 2008 02:33:14 -0400 Received: from mx20.gnu.org ([199.232.41.8]:16344) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Kqitd-0000CR-PW for qemu-devel@nongnu.org; Fri, 17 Oct 2008 02:33:14 -0400 Received: from nf-out-0910.google.com ([64.233.182.190]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KqitZ-0006UB-1c for qemu-devel@nongnu.org; Fri, 17 Oct 2008 02:33:09 -0400 Received: by nf-out-0910.google.com with SMTP id b2so253973nfb.12 for ; Thu, 16 Oct 2008 23:33:07 -0700 (PDT) From: "Kirill A. Shutemov" Date: Fri, 17 Oct 2008 09:34:24 +0300 Message-Id: <1224225264-8483-2-git-send-email-kirill@shutemov.name> In-Reply-To: <1224225264-8483-1-git-send-email-kirill@shutemov.name> References: <1223892640-15545-13-git-send-email-kirill@shutemov.name> <1224225264-8483-1-git-send-email-kirill@shutemov.name> Subject: [Qemu-devel] [PATCH] linux-user, x86: use target_mmap() to allocate idt, gdt and ldt 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 Cc: "Kirill A. Shutemov" env->*dt.base should fits target address space, so we should use target_mmap to allocate it. Signed-off-by: Kirill A. Shutemov --- linux-user/main.c | 23 +++++++++++++++-------- linux-user/syscall.c | 10 ++++++---- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 25b2867..61d497e 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "qemu.h" #include "qemu-common.h" @@ -283,9 +284,8 @@ static void write_dt(void *ptr, unsigned long addr, unsigned long limit, p[1] = tswap32(e2); } +uint64_t *idt_table; #ifdef TARGET_X86_64 -uint64_t idt_table[512]; - static void set_gate64(void *ptr, unsigned int type, unsigned int dpl, uint64_t addr, unsigned int sel) { @@ -304,8 +304,6 @@ static void set_idt(int n, unsigned int dpl) 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) { @@ -2500,8 +2498,15 @@ int main(int argc, char **argv, char **envp) #endif /* linux interrupt setup */ - env->idt.base = h2g(idt_table); - env->idt.limit = sizeof(idt_table) - 1; +#ifndef TARGET_ABI32 + env->idt.limit = 511; +#else + env->idt.limit = 255; +#endif + env->idt.base = target_mmap(0, sizeof(uint64_t) * (env->idt.limit + 1), + PROT_READ|PROT_WRITE, + MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); + idt_table = g2h(env->idt.base); set_idt(0, 0); set_idt(1, 0); set_idt(2, 0); @@ -2527,9 +2532,11 @@ int main(int argc, char **argv, char **envp) /* linux segment setup */ { uint64_t *gdt_table; - gdt_table = qemu_mallocz(sizeof(uint64_t) * TARGET_GDT_ENTRIES); - env->gdt.base = h2g((unsigned long)gdt_table); + env->gdt.base = target_mmap(0, sizeof(uint64_t) * TARGET_GDT_ENTRIES, + PROT_READ|PROT_WRITE, + MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); env->gdt.limit = sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1; + gdt_table = g2h(env->gdt.base); #ifdef TARGET_ABI32 write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff, DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | diff --git a/linux-user/syscall.c b/linux-user/syscall.c index db3538b..27bd7e1 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -2823,12 +2823,14 @@ static abi_long write_ldt(CPUX86State *env, } /* allocate the LDT */ if (!ldt_table) { - ldt_table = malloc(TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE); - if (!ldt_table) + env->ldt.base = target_mmap(0, TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE, + PROT_READ|PROT_WRITE, + MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); + if (env->ldt.base == -1) return -TARGET_ENOMEM; - memset(ldt_table, 0, TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE); - env->ldt.base = h2g((unsigned long)ldt_table); + memset(g2h(env->ldt.base), 0, TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE); env->ldt.limit = 0xffff; + ldt_table = g2h(env->ldt.base); } /* NOTE: same code as Linux kernel */ -- 1.5.6.5.GIT