linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH, v3] shmat: introduce flag SHM_MAP_NOT_FIXED
@ 2008-10-07 16:15 Kirill A. Shutemov
  2008-10-07 16:31 ` KOSAKI Motohiro
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Kirill A. Shutemov @ 2008-10-07 16:15 UTC (permalink / raw)
  To: linux-kernel, linux-mm
  Cc: Kirill A. Shutemov, Andi Kleen, Ingo Molnar, Arjan van de Ven,
	Hugh Dickins, KOSAKI Motohiro, Alan Cox, Ulrich Drepper,
	Andrew Morton

If SHM_MAP_NOT_FIXED specified and shmaddr is not NULL, then the kernel takes
shmaddr as a hint about where to place the mapping. The address of the mapping
is returned as the result of the call.

It's similar to mmap() without MAP_FIXED.

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arjan van de Ven <arjan@infradead.org>
Cc: Hugh Dickins <hugh@veritas.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: Ulrich Drepper <drepper@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
 include/linux/shm.h |    2 ++
 ipc/shm.c           |    7 ++++---
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/include/linux/shm.h b/include/linux/shm.h
index eca6235..fd288eb 100644
--- a/include/linux/shm.h
+++ b/include/linux/shm.h
@@ -55,6 +55,8 @@ struct shmid_ds {
 #define	SHM_RND		020000	/* round attach address to SHMLBA boundary */
 #define	SHM_REMAP	040000	/* take-over region on attach */
 #define	SHM_EXEC	0100000	/* execution access */
+#define	SHM_MAP_NOT_FIXED 0200000 /* interpret attach address as a search
+				   * hint */
 
 /* super user shmctl commands */
 #define SHM_LOCK 	11
diff --git a/ipc/shm.c b/ipc/shm.c
index e77ec69..54f3c61 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -819,7 +819,7 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
 	if (shmid < 0)
 		goto out;
 	else if ((addr = (ulong)shmaddr)) {
-		if (addr & (SHMLBA-1)) {
+		if (!(shmflg & SHM_MAP_NOT_FIXED) && (addr & (SHMLBA-1))) {
 			if (shmflg & SHM_RND)
 				addr &= ~(SHMLBA-1);	   /* round down */
 			else
@@ -828,7 +828,8 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
 #endif
 					goto out;
 		}
-		flags = MAP_SHARED | MAP_FIXED;
+		flags = MAP_SHARED |
+				(shmflg & SHM_MAP_NOT_FIXED ? 0 : MAP_FIXED);
 	} else {
 		if ((shmflg & SHM_REMAP))
 			goto out;
@@ -892,7 +893,7 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
 	sfd->vm_ops = NULL;
 
 	down_write(&current->mm->mmap_sem);
-	if (addr && !(shmflg & SHM_REMAP)) {
+	if (addr && !(shmflg & (SHM_REMAP|SHM_MAP_NOT_FIXED))) {
 		err = -EINVAL;
 		if (find_vma_intersection(current->mm, addr, addr + size))
 			goto invalid;
-- 
1.5.6.5.GIT

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2008-10-08 12:46 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-07 16:15 [PATCH, v3] shmat: introduce flag SHM_MAP_NOT_FIXED Kirill A. Shutemov
2008-10-07 16:31 ` KOSAKI Motohiro
2008-10-07 21:10   ` Andi Kleen
2008-10-07 21:38     ` KOSAKI Motohiro
2008-10-07 23:23       ` Andi Kleen
2008-10-07 23:05     ` Alan Cox
2008-10-07 23:20       ` Andi Kleen
2008-10-07 23:40         ` Alan Cox
2008-10-07 23:57           ` Andi Kleen
2008-10-08  8:33             ` Alan Cox
2008-10-08  8:34             ` Alan Cox
2008-10-08  8:43               ` Andi Kleen
2008-10-08  8:58                 ` Alan Cox
2008-10-08  9:11                   ` Andi Kleen
2008-10-08 10:20                     ` Alan Cox
2008-10-08 11:02                       ` Andi Kleen
2008-10-08 12:46                         ` Alan Cox
2008-10-07 16:54 ` Alan Cox
2008-10-08  8:57 ` Michael Kerrisk
2008-10-08  9:35   ` Kirill A. Shutemov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox