[patch 1/1] compat_alloc_user

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I noticed that is not possible ATM to allocate two or more blocks
of userspace memory. Would a compat_alloc_user() like the one below
make sense (patch untested)?



Signed-off-by: Davide Libenzi <[email protected]>


- Davide



---
 include/asm-ia64/compat.h    |    8 ++++++++
 include/asm-mips/compat.h    |    8 ++++++++
 include/asm-parisc/compat.h  |    8 ++++++++
 include/asm-powerpc/compat.h |    8 ++++++++
 include/asm-s390/compat.h    |    8 ++++++++
 include/asm-sparc64/compat.h |    8 ++++++++
 include/asm-x86_64/compat.h  |    8 ++++++++
 7 files changed, 56 insertions(+)

Index: linux-2.6.mod/include/asm-x86_64/compat.h
===================================================================
--- linux-2.6.mod.orig/include/asm-x86_64/compat.h	2007-06-13 17:48:27.000000000 -0700
+++ linux-2.6.mod/include/asm-x86_64/compat.h	2007-06-13 17:48:32.000000000 -0700
@@ -202,6 +202,14 @@
 	return (void __user *)regs->rsp - len; 
 }
 
+static __inline__ void __user *compat_alloc_user(void __user **prev, long len)
+{
+	void __user *data;
+	data = *prev ? (*prev - len): compat_alloc_user_space(len);
+	*prev = (void __user *) ((unsigned long) data & ~0x7UL);
+	return *prev;
+}
+
 static inline int is_compat_task(void)
 {
 	return current_thread_info()->status & TS_COMPAT;
Index: linux-2.6.mod/include/asm-sparc64/compat.h
===================================================================
--- linux-2.6.mod.orig/include/asm-sparc64/compat.h	2007-06-13 17:48:27.000000000 -0700
+++ linux-2.6.mod/include/asm-sparc64/compat.h	2007-06-13 17:48:32.000000000 -0700
@@ -180,6 +180,14 @@
 	return (void __user *) usp;
 }
 
+static inline void __user *compat_alloc_user(void __user **prev, long len)
+{
+	void __user *data;
+	data = *prev ? (*prev - len): compat_alloc_user_space(len);
+	*prev = (void __user *) ((unsigned long) data & ~0x7UL);
+	return *prev;
+}
+
 struct compat_ipc64_perm {
 	compat_key_t key;
 	__compat_uid32_t uid;
Index: linux-2.6.mod/include/asm-s390/compat.h
===================================================================
--- linux-2.6.mod.orig/include/asm-s390/compat.h	2007-06-13 17:48:27.000000000 -0700
+++ linux-2.6.mod/include/asm-s390/compat.h	2007-06-13 17:48:32.000000000 -0700
@@ -171,6 +171,14 @@
 	return (void __user *) (stack - len);
 }
 
+static inline void __user *compat_alloc_user(void __user **prev, long len)
+{
+	void __user *data;
+	data = *prev ? (*prev - len): compat_alloc_user_space(len);
+	*prev = (void __user *) ((unsigned long) data & ~0x7UL);
+	return *prev;
+}
+
 struct compat_ipc64_perm {
 	compat_key_t key;
 	__compat_uid32_t uid;
Index: linux-2.6.mod/include/asm-powerpc/compat.h
===================================================================
--- linux-2.6.mod.orig/include/asm-powerpc/compat.h	2007-06-13 17:48:27.000000000 -0700
+++ linux-2.6.mod/include/asm-powerpc/compat.h	2007-06-13 17:48:32.000000000 -0700
@@ -146,6 +146,14 @@
 	return (void __user *) (usp - len);
 }
 
+static inline void __user *compat_alloc_user(void __user **prev, long len)
+{
+	void __user *data;
+	data = *prev ? (*prev - len): compat_alloc_user_space(len);
+	*prev = (void __user *) ((unsigned long) data & ~0x7UL);
+	return *prev;
+}
+
 /*
  * ipc64_perm is actually 32/64bit clean but since the compat layer refers to
  * it we may as well define it.
Index: linux-2.6.mod/include/asm-parisc/compat.h
===================================================================
--- linux-2.6.mod.orig/include/asm-parisc/compat.h	2007-06-13 17:48:27.000000000 -0700
+++ linux-2.6.mod/include/asm-parisc/compat.h	2007-06-13 17:48:32.000000000 -0700
@@ -150,6 +150,14 @@
 	return (void __user *)regs->gr[30];
 }
 
+static __inline__ void __user *compat_alloc_user(void __user **prev, long len)
+{
+	void __user *data;
+	data = *prev ? : compat_alloc_user_space(len);
+	*prev = data + ((len + 0x7UL) & ~0x7UL);
+	return data;
+}
+
 static inline int __is_compat_task(struct task_struct *t)
 {
 	return test_ti_thread_flag(task_thread_info(t), TIF_32BIT);
Index: linux-2.6.mod/include/asm-mips/compat.h
===================================================================
--- linux-2.6.mod.orig/include/asm-mips/compat.h	2007-06-13 17:48:27.000000000 -0700
+++ linux-2.6.mod/include/asm-mips/compat.h	2007-06-13 17:48:32.000000000 -0700
@@ -148,6 +148,14 @@
 	return (void __user *) (regs->regs[29] - len);
 }
 
+static inline void __user *compat_alloc_user(void __user **prev, long len)
+{
+	void __user *data;
+	data = *prev ? (*prev - len): compat_alloc_user_space(len);
+	*prev = (void __user *) ((unsigned long) data & ~0x7UL);
+	return *prev;
+}
+
 struct compat_ipc64_perm {
 	compat_key_t key;
 	__compat_uid32_t uid;
Index: linux-2.6.mod/include/asm-ia64/compat.h
===================================================================
--- linux-2.6.mod.orig/include/asm-ia64/compat.h	2007-06-13 17:48:27.000000000 -0700
+++ linux-2.6.mod/include/asm-ia64/compat.h	2007-06-13 17:48:32.000000000 -0700
@@ -202,4 +202,12 @@
 	return (void __user *) (((regs->r12 & 0xffffffff) & -16) - len);
 }
 
+static __inline__ void __user *compat_alloc_user(void __user **prev, long len)
+{
+	void __user *data;
+	data = *prev ? (*prev - len): compat_alloc_user_space(len);
+	*prev = (void __user *) ((unsigned long) data & ~0xfUL;
+	return *prev;
+}
+
 #endif /* _ASM_IA64_COMPAT_H */

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux