From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L7pu6-0007xt-3t for qemu-devel@nongnu.org; Wed, 03 Dec 2008 06:28:26 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L7ptz-0007sJ-R4 for qemu-devel@nongnu.org; Wed, 03 Dec 2008 06:28:22 -0500 Received: from [199.232.76.173] (port=33383 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L7pty-0007rO-96 for qemu-devel@nongnu.org; Wed, 03 Dec 2008 06:28:18 -0500 Received: from ug-out-1314.google.com ([66.249.92.172]:2530) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1L7ptt-0004F6-QQ for qemu-devel@nongnu.org; Wed, 03 Dec 2008 06:28:14 -0500 Received: by ug-out-1314.google.com with SMTP id 29so3354995ugc.36 for ; Wed, 03 Dec 2008 03:28:02 -0800 (PST) From: "Kirill A. Shutemov" Date: Wed, 3 Dec 2008 13:29:49 +0200 Message-Id: <1228303789-25653-14-git-send-email-kirill@shutemov.name> In-Reply-To: <1228303789-25653-13-git-send-email-kirill@shutemov.name> References: <1228303789-25653-1-git-send-email-kirill@shutemov.name> <1228303789-25653-2-git-send-email-kirill@shutemov.name> <1228303789-25653-3-git-send-email-kirill@shutemov.name> <1228303789-25653-4-git-send-email-kirill@shutemov.name> <1228303789-25653-5-git-send-email-kirill@shutemov.name> <1228303789-25653-6-git-send-email-kirill@shutemov.name> <1228303789-25653-7-git-send-email-kirill@shutemov.name> <1228303789-25653-8-git-send-email-kirill@shutemov.name> <1228303789-25653-9-git-send-email-kirill@shutemov.name> <1228303789-25653-10-git-send-email-kirill@shutemov.name> <1228303789-25653-11-git-send-email-kirill@shutemov.name> <1228303789-25653-12-git-send-email-kirill@shutemov.name> <1228303789-25653-13-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" This patch depends on new implementation of mmap_find_vma(). Signed-off-by: Kirill A. Shutemov --- linux-user/syscall.c | 32 ++++++++++++++++++++++++-------- 1 files changed, 24 insertions(+), 8 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index d2f34b9..29765f0 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -2271,25 +2271,40 @@ 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); } + mmap_lock(); + + 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) { + mmap_unlock(); + 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)); @@ -2302,6 +2317,7 @@ static inline abi_long do_shmat(int shmid, abi_ulong shmaddr, int shmflg, } } + mmap_unlock(); return 0; } -- 1.6.0.2.GIT