public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC] is_compat_task helper
@ 2006-01-24  0:07 Kyle McMartin
  2006-01-24  0:13 ` Andi Kleen
  0 siblings, 1 reply; 5+ messages in thread
From: Kyle McMartin @ 2006-01-24  0:07 UTC (permalink / raw)
  To: linux-arch

As many people have noticed, there's a growing need for some
generic code to know if a task is being run under 32 on 64 or
other such situations requiring compat conversions. Adding
the is_compat_task() macro provides a nice way to abstract this,
which is currently a mess of #ifdef (CONFIG_ARCH1) #else (CONFIG_ARCH2)
(see drivers/input/evdev.c for example). Arch maintainers are free
to override the default __is_compat_task() macro in their asm/compat.h
headers to be correct for their arch. This provides generic code with a
way to get what it wants, without needing to know ugly per-arch
details.

[Not only does this nicely clean up generic code, it's also useful
 to clean up some ugliness in the per-arch signal, ptrace, etc., code.]

See http://lkml.org/lkml/2006/1/8/170 for an example of generic code
that can be nicely cleaned up this way.

Based on prior work by Carlos O'Donell <carlos@parisc-linux.org>

Signed-off-by: Carlos O'Donell <carlos@parisc-linux.org>
Signed-off-by: Kyle McMartin <kyle@parisc-linux.org>

diff --git a/include/linux/compat.h b/include/linux/compat.h
index f9ca534..1645200 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -6,10 +6,16 @@
  */
 #include <linux/config.h>
 
-#ifdef CONFIG_COMPAT
+#ifndef CONFIG_COMPAT
+
+/* No tasks needing compat if !CONFIG_COMPAT */
+#define __is_compat_task(x)	0
+
+#else
 
 #include <linux/stat.h>
 #include <linux/param.h>	/* for HZ */
+#include <linux/personality.h>	/* Conditional process compat */
 #include <linux/sem.h>
 
 #include <asm/compat.h>
@@ -18,6 +24,11 @@
 #define compat_jiffies_to_clock_t(x)	\
 		(((unsigned long)(x) * COMPAT_USER_HZ) / HZ)
 
+/* Arches may override __is_compat_task from asm/compat.h */
+#ifndef __is_compat_task
+#define __is_compat_task(x)	(personality(x->personality) == PER_LINUX32)
+#endif /* __is_compat_task */
+
 typedef __compat_uid32_t	compat_uid_t;
 typedef __compat_gid32_t	compat_gid_t;
 
@@ -162,4 +173,10 @@ int get_compat_sigevent(struct sigevent 
 		const struct compat_sigevent __user *u_event);
 
 #endif /* CONFIG_COMPAT */
+
+static inline int
+is_compat_task(struct task_struct *task) {
+	return __is_compat_task(task);
+}
+
 #endif /* _LINUX_COMPAT_H */

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

end of thread, other threads:[~2006-01-25 16:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-01-24  0:07 [RFC] is_compat_task helper Kyle McMartin
2006-01-24  0:13 ` Andi Kleen
2006-01-24  0:23   ` Kyle McMartin
2006-01-24  5:07   ` David S. Miller
2006-01-25 16:34     ` Kyle McMartin

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