mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] Generic is_compat_task helper
@ 2006-02-17  2:52 Kyle McMartin
  2006-02-17  5:49 ` Andrew Morton
  0 siblings, 1 reply; 7+ messages in thread
From: Kyle McMartin @ 2006-02-17  2:52 UTC (permalink / raw)
  To: torvalds; +Cc: akpm, linux-kernel

Implement a generic is_compat_task function. It should only be used
when absolutely necessary. For example, to clean up the per-architecture
tests in drivers/input/evdev.c.

Prototype is such that the existing asm-x86_64 helper needs no change.

Architecture maintainers must add an appropriate implementation to
asm/compat.h, if needed.

Signed-off-by: Kyle McMartin <kyle@parisc-linux.org>

---

Yeah, this can be abused... but, blocks like:

#ifdef CONFIG_X86_64
#  define COMPAT_TEST is_compat_task()
#elif defined(CONFIG_IA64)
#  define COMPAT_TEST IS_IA32_PROCESS(task_pt_regs(current))
#elif defined(CONFIG_S390)
#  define COMPAT_TEST test_thread_flag(TIF_31BIT)
#elif defined(CONFIG_MIPS)
#  define COMPAT_TEST (current->thread.mflags & MF_32BIT_ADDR)
#else
#  define COMPAT_TEST test_thread_flag(TIF_32BIT)
#endif

from drivers/input/evdev.c are worse. This style of block also appeared
in a patch on netdev recently...

I think everyone can agree centralizing this is probably better than
the current state of affairs.

diff --git a/include/asm-parisc/compat.h b/include/asm-parisc/compat.h
index 38b918f..a5eb7cd 100644
--- a/include/asm-parisc/compat.h
+++ b/include/asm-parisc/compat.h
@@ -5,6 +5,7 @@
  */
 #include <linux/types.h>
 #include <linux/sched.h>
+#include <linux/personality.h>
 
 #define COMPAT_USER_HZ 100
 
@@ -144,4 +145,14 @@ static __inline__ void __user *compat_al
 	return (void __user *)regs->gr[30];
 }
 
+static inline int __is_compat_task(struct task_struct *t)
+{
+	return (personality(t->personality) == PER_LINUX32);
+}
+
+static inline int is_compat_task(void)
+{
+	return __is_compat_task(current);
+}
+
 #endif /* _ASM_PARISC_COMPAT_H */
diff --git a/include/linux/compat.h b/include/linux/compat.h
index c9ab2a2..d2e0ea9 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -181,5 +181,12 @@ static inline int compat_timespec_compar
 	return lhs->tv_nsec - rhs->tv_nsec;
 }
 
+#else /* !CONFIG_COMPAT */
+
+static inline int is_compat_task(void)
+{
+	return 0;
+}
+
 #endif /* CONFIG_COMPAT */
 #endif /* _LINUX_COMPAT_H */

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

end of thread, other threads:[~2006-02-17 14:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-17  2:52 [PATCH] Generic is_compat_task helper Kyle McMartin
2006-02-17  5:49 ` Andrew Morton
2006-02-17  5:58   ` Paul Mackerras
2006-02-17  6:01   ` Stephen Rothwell
2006-02-17  7:03   ` David S. Miller
2006-02-17  7:45     ` Issue in using more number of devices with BFS setup in AS4 Srikanth Venkataraman
2006-02-17 14:11   ` [PATCH] Generic is_compat_task helper Kyle McMartin

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

all inboxes | Powered by JetHome®