From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KpKNF-00042X-9V for qemu-devel@nongnu.org; Mon, 13 Oct 2008 06:10:01 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KpKNE-00041g-97 for qemu-devel@nongnu.org; Mon, 13 Oct 2008 06:10:00 -0400 Received: from [199.232.76.173] (port=47870 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KpKND-00041Y-RP for qemu-devel@nongnu.org; Mon, 13 Oct 2008 06:09:59 -0400 Received: from mu-out-0910.google.com ([209.85.134.186]:30088) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KpKND-00078e-Hm for qemu-devel@nongnu.org; Mon, 13 Oct 2008 06:09:59 -0400 Received: by mu-out-0910.google.com with SMTP id w1so1897784mue.2 for ; Mon, 13 Oct 2008 03:09:59 -0700 (PDT) From: "Kirill A. Shutemov" Date: Mon, 13 Oct 2008 13:10:40 +0300 Message-Id: <1223892640-15545-13-git-send-email-kirill@shutemov.name> In-Reply-To: <1223892640-15545-12-git-send-email-kirill@shutemov.name> References: <1223892640-15545-1-git-send-email-kirill@shutemov.name> <1223892640-15545-2-git-send-email-kirill@shutemov.name> <1223892640-15545-3-git-send-email-kirill@shutemov.name> <1223892640-15545-4-git-send-email-kirill@shutemov.name> <1223892640-15545-5-git-send-email-kirill@shutemov.name> <1223892640-15545-6-git-send-email-kirill@shutemov.name> <1223892640-15545-7-git-send-email-kirill@shutemov.name> <1223892640-15545-8-git-send-email-kirill@shutemov.name> <1223892640-15545-9-git-send-email-kirill@shutemov.name> <1223892640-15545-10-git-send-email-kirill@shutemov.name> <1223892640-15545-11-git-send-email-kirill@shutemov.name> <1223892640-15545-12-git-send-email-kirill@shutemov.name> Subject: [Qemu-devel] [PATCH] shmat(): use mmap_find_vma to find free memory area 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" , Paul Brook Signed-off-by: Kirill A. Shutemov --- linux-user/syscall.c | 28 ++++++++++++++++++++-------- 1 files changed, 20 insertions(+), 8 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 3fa205f..db3538b 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -2267,25 +2267,37 @@ static inline abi_long do_shmctl(int shmid, int cmd, abi_long buf) static inline abi_long do_shmat(int shmid, abi_ulong shmaddr, int shmflg, unsigned long *raddr) { + abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size); abi_long ret; struct shmid_ds shm_info; int i; - /* SHM_* flags are the same on all linux platforms */ - *raddr = (unsigned long) shmat(shmid, g2h(shmaddr), shmflg); - - if (*raddr == -1) { - return get_errno(*raddr); - } - /* find out the length of the shared memory segment */ ret = get_errno(shmctl(shmid, IPC_STAT, &shm_info)); if (is_error(ret)) { /* can't get length, bail out */ - shmdt((void *) *raddr); return get_errno(ret); } + if (shmaddr) + *raddr = (unsigned long) shmat(shmid, g2h(shmaddr), shmflg); + else { + abi_ulong mmap_start; + + mmap_start = mmap_find_vma(0, shm_info.shm_segsz); + + if (mmap_start == -1) { + errno = ENOMEM; + *raddr = -1; + } else + *raddr = (unsigned long) shmat(shmid, g2h(mmap_start), + shmflg | SHM_REMAP); + } + + if (*raddr == -1) { + return get_errno(*raddr); + } + page_set_flags(h2g(*raddr), h2g(*raddr) + shm_info.shm_segsz, PAGE_VALID | PAGE_READ | ((shmflg & SHM_RDONLY)? 0 : PAGE_WRITE)); -- 1.5.6.5.GIT