Skip to contentSkip to conversation

compat-signal-noarch-2004-01-29.patch again

PATCH Andrew Morton 4 participants 9 messages Mar 20, 2004 Generic include/asm header files

lore
Share & tools
lore
#0 lore raw

This patch continues to hang around at Morton manor. last time it was discussed Andi had issues with it and thing petered out.

Can we please wrap this up one ay or the other?

From: "Carlos O'Donell" <[email protected]>

These changes allow 64-bit arches to copy siginfo_t to a 32-bit userspace in a generic fashion. All 64-bit arches with compat 32-bit tasks can take advantage of the generic code. hppa64 already uses this code, with ia64 and ppc64 changes in the works.

Most arches use the asm-generic/siginfo.h definition. For those arches with 64-bit platforms, and requiring compat with 32-bit tasks, we create a generic layer for copying siginfo_t structures to userspace. First we define the required compat_ structures in include/asm-generic/compat_signal.h and in include/linux/compat_siginfo.h. The latter is not in asm-generic, because doing so would require that all arches add an asm/compat_siginfo.h for the generic code to work.

Next we implement a generic compat_copy_siginfo_to_user in kernel/compat_signal.c. To make use of the compat copy routine we add a check in kernel/signal.c to determine if the task requires a compat copy, and if so, call compat_copy_siginfo_to_user instead.

---

 25-akpm/include/asm-generic/compat_signal.h |   25 ++++
 25-akpm/include/asm-ia64/compat.h           |    1 
 25-akpm/include/asm-ppc64/compat.h          |    1 
 25-akpm/include/asm-ppc64/ppc32.h           |   64 ----------
 25-akpm/include/asm-sparc64/compat.h        |    1 
 25-akpm/include/linux/compat.h              |   18 +-
 25-akpm/include/linux/compat_siginfo.h      |  170 ++++++++++++++++++++++++++++
 25-akpm/kernel/Makefile                     |    2 
 25-akpm/kernel/compat_signal.c              |  124 ++++++++++++++++++++
 25-akpm/kernel/signal.c                     |    7 +
 10 files changed, 343 insertions(+), 70 deletions(-)
include/asm-generic/compat_signal.h new file +25 -0
diff -puN /dev/null include/asm-generic/compat_signal.h
@@ -0,0 +1,25 @@
+#ifndef _ASM_GENERIC_COMPAT_SIGNAL_H
+#define _ASM_GENERIC_COMPAT_SIGNAL_H
+
+#ifndef __ASSEMBLY__
+#include <linux/compat.h>
+
+typedef compat_uptr_t compat_sighandler_t;
+
+typedef struct compat_sigaltstack {
+	compat_uptr_t ss_sp;
+	compat_int_t ss_flags;
+	compat_size_t ss_size;
+} compat_stack_t;
+
+/* Most things should be clean enough to redefine this at will, if care
+   is taken to make libc match.  */
+
+struct compat_sigaction {
+	compat_sighandler_t sa_handler;
+	compat_uint_t sa_flags;
+	compat_sigset_t sa_mask;		/* mask last for extensibility */
+};
+
+#endif /* !__ASSEMBLY__ */
+#endif /* !_ASM_GENERIC_COMPAT_SIGNAL_H */
include/linux/compat.h renamed from include/linux/compat.h~compat-signal-noarch-2004-01-29 +12 -6
diff -puN include/linux/compat.h~compat-signal-noarch-2004-01-29 include/linux/compat.h
@@ -6,10 +6,16 @@
  */
 #include <linux/config.h>
 
-#ifdef CONFIG_COMPAT
+#ifndef CONFIG_COMPAT
 
+/* Non-native task requiring compat... doesn't exist */
+#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>
@@ -17,6 +23,11 @@
 #define compat_jiffies_to_clock_t(x)	\
 		(((unsigned long)(x) * COMPAT_USER_HZ) / HZ)
 
+/* Non-native task requiring compat */
+#ifndef HAVE_ARCH_IS_COMPAT_TASK
+#define is_compat_task(x) (x->personality == PER_LINUX32)
+#endif
+
 struct compat_itimerspec { 
 	struct compat_timespec it_interval;
 	struct compat_timespec it_value;
@@ -85,11 +96,6 @@ struct compat_dirent {
 	char		d_name[256];
 };
 
-typedef union compat_sigval {
-	compat_int_t	sival_int;
-	compat_uptr_t	sival_ptr;
-} compat_sigval_t;
-
 long compat_sys_semctl(int first, int second, int third, void __user *uptr);
 long compat_sys_msgsnd(int first, int second, int third, void __user *uptr);
 long compat_sys_msgrcv(int first, int second, int msgtyp, int third,
include/linux/compat_siginfo.h new file +170 -0

170 lines not on this page · raw message

kernel/compat_signal.c new file +124 -0

124 lines not on this page · raw message

kernel/Makefile renamed from kernel/Makefile~compat-signal-noarch-2004-01-29 +1 -1
diff -puN kernel/Makefile~compat-signal-noarch-2004-01-29 kernel/Makefile
@@ -17,7 +17,7 @@ obj-$(CONFIG_MODULES) += module.o
 obj-$(CONFIG_KALLSYMS) += kallsyms.o
 obj-$(CONFIG_PM) += power/
 obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o
-obj-$(CONFIG_COMPAT) += compat.o
+obj-$(CONFIG_COMPAT) += compat.o compat_signal.o
 obj-$(CONFIG_IKCONFIG) += configs.o
 obj-$(CONFIG_IKCONFIG_PROC) += configs.o
 obj-$(CONFIG_STOP_MACHINE) += stop_machine.o
kernel/signal.c renamed from kernel/signal.c~compat-signal-noarch-2004-01-29 +7 -0
diff -puN kernel/signal.c~compat-signal-noarch-2004-01-29 kernel/signal.c
@@ -21,6 +21,7 @@
 #include <linux/binfmts.h>
 #include <linux/security.h>
 #include <linux/ptrace.h>
+#include <linux/compat_siginfo.h>
 #include <asm/param.h>
 #include <asm/uaccess.h>
 #include <asm/siginfo.h>
@@ -2009,6 +2010,12 @@ int copy_siginfo_to_user(siginfo_t __use
 	if (from->si_code < 0)
 		return __copy_to_user(to, from, sizeof(siginfo_t))
 			? -EFAULT : 0;
+
+	/* Use compat_siginfo_t with 32-bit signals */
+	if(is_compat_task(current)){
+		return compat_copy_siginfo_to_user((compat_siginfo_t __user *)to,from);
+	}
+
 	/*
 	 * If you change siginfo_t structure, please be sure
 	 * this code is fixed accordingly.
include/asm-ppc64/compat.h renamed from include/asm-ppc64/compat.h~compat-signal-noarch-2004-01-29 +1 -0
diff -puN include/asm-ppc64/compat.h~compat-signal-noarch-2004-01-29 include/asm-ppc64/compat.h
@@ -25,6 +25,7 @@ typedef u16		compat_ipc_pid_t;
 typedef s32		compat_daddr_t;
 typedef u32		compat_caddr_t;
 typedef __kernel_fsid_t	compat_fsid_t;
+typedef u32		compat_timer_t;
 
 typedef s32		compat_int_t;
 typedef s32		compat_long_t;
include/asm-ppc64/ppc32.h renamed from include/asm-ppc64/ppc32.h~compat-signal-noarch-2004-01-29 +1 -63

82 lines not on this page · raw message

include/asm-ia64/compat.h renamed from include/asm-ia64/compat.h~compat-signal-noarch-2004-01-29 +1 -0
diff -puN include/asm-ia64/compat.h~compat-signal-noarch-2004-01-29 include/asm-ia64/compat.h
@@ -27,6 +27,7 @@ typedef u16		compat_ipc_pid_t;
 typedef s32		compat_daddr_t;
 typedef u32		compat_caddr_t;
 typedef __kernel_fsid_t	compat_fsid_t;
+typedef u32		compat_timer_t;
 
 typedef s32		compat_int_t;
 typedef s32		compat_long_t;
include/asm-sparc64/compat.h renamed from include/asm-sparc64/compat.h~compat-signal-noarch-2004-01-29 +1 -0
diff -puN include/asm-sparc64/compat.h~compat-signal-noarch-2004-01-29 include/asm-sparc64/compat.h
@@ -29,6 +29,7 @@ typedef s32		compat_int_t;
 typedef s32		compat_long_t;
 typedef u32		compat_uint_t;
 typedef u32		compat_ulong_t;
+typedef u32		compat_timer_t;
 
 struct compat_timespec {
 	compat_time_t	tv_sec;

_

#1 lore raw
Quoted 5 lines · On Fri, 19 Mar 2004 21:49:49 -0800 Andrew Morton <[email protected]> wrote:

This patch continues to hang around at Morton manor. last time it was discussed Andi had issues with it and thing petered out.

Can we please wrap this up one ay or the other?

My only issue was the exporting of is_compat_task() to generic linux/compat.h If that is fixed (the code that does the is_compat_task is moved to arch/* again) then the change is fine and I would also likely use it for x86-64.

-Andi

#2 lore raw
Quoted 5 lines · Andi Kleen
Quoted 1 line · On Fri, 19 Mar 2004 21:49:49 -0800 Andrew Morton <[email protected]> wrote:
Quoted 8 lines
Quoted 4 lines

This patch continues to hang around at Morton manor. last time it was discussed Andi had issues with it and thing petered out.

Can we please wrap this up one ay or the other?

My only issue was the exporting of is_compat_task() to generic linux/compat.h If that is fixed (the code that does the is_compat_task is moved to arch/* again) then the change is fine and I would also likely use it for x86-64.

Cannot you define HAVE_ARCH_IS_COMPAT_TASK?

+#ifndef CONFIG_COMPAT

+/* Non-native task requiring compat... doesn't exist */ +#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>
@@ -17,6 +23,11 @@
#define compat_jiffies_to_clock_t(x) \
(((unsigned long)(x) * COMPAT_USER_HZ) / HZ)

+/* Non-native task requiring compat */
+#ifndef HAVE_ARCH_IS_COMPAT_TASK
+#define is_compat_task(x) (x->personality == PER_LINUX32) +#endif
+

#3 lore raw
Quoted 9 lines · On Fri, 19 Mar 2004 22:37:44 -0800 Andrew Morton <[email protected]> wrote:
Quoted 8 lines · Andi Kleen
Quoted 4 lines · On Fri, 19 Mar 2004 21:49:49 -0800 Andrew Morton <[email protected]> wrote:

This patch continues to hang around at Morton manor. last time it was discussed Andi had issues with it and thing petered out.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Can we please wrap this up one ay or the other?

My only issue was the exporting of is_compat_task() to generic linux/compat.h If that is fixed (the code that does the is_compat_task is moved to arch/* again) then the change is fine and I would also likely use it for x86-64.

Cannot you define HAVE_ARCH_IS_COMPAT_TASK?

No. The problem is not in a particular implementation of this for a specific architecture, but in the generic design - it is the wrong direction and will cause hard to fix later design problems.

-Andi

#4 lore raw
Quoted 19 lines · Andi Kleen
Quoted 15 lines · On Fri, 19 Mar 2004 22:37:44 -0800 Andrew Morton <[email protected]> wrote:
Quoted 13 lines · Andi Kleen
Quoted 5 lines · On Fri, 19 Mar 2004 21:49:49 -0800 Andrew Morton <[email protected]> wrote:

This patch continues to hang around at Morton manor. last time it was discussed Andi had issues with it and thing petered out.

Can we please wrap this up one ay or the other?

My only issue was the exporting of is_compat_task() to generic linux/compat.h If that is fixed (the code that does the is_compat_task is moved to arch/* again) then the change is fine and I would also likely use it for x86-64.

Quoted 6 lines
Quoted 1 line

Cannot you define HAVE_ARCH_IS_COMPAT_TASK?

No. The problem is not in a particular implementation of this for a specific architecture, but in the generic design - it is the wrong direction and will cause hard to fix later design problems.

I don't have the time/inclination to muddle through this stuff. I'll drop the patch.

#5 lore raw
In reply to Andi Kleen
Quoted 3 lines · Andi Kleen

No. The problem is not in a particular implementation of this for a specific architecture, but in the generic design - it is the wrong direction and will cause hard to fix later design problems.

You're wrong. Just accept this patch.

Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain
#6 lore raw
Quoted 7 lines · Matthew Wilcox
Quoted 3 lines · Andi Kleen

No. The problem is not in a particular implementation of this for a specific architecture, but in the generic design - it is the wrong direction and will cause hard to fix later design problems.

You're wrong. Just accept this patch.

I can sort-of-see Andi's worry.

The issue appears to be that at some time in the future he will have 64-bit applications using the 32-bit API without PER_LINUX32 set. So the proposed is_compat_task() is meaningless in this context - hence Andi doesn't want is_compat_task() propagated around the place.

This begs the question of how his kernel correctly handle these pseudo-32-bit tasks.

#7 lore raw
Quoted 9 lines · Andrew Morton

I can sort-of-see Andi's worry.

The issue appears to be that at some time in the future he will have 64-bit applications using the 32-bit API without PER_LINUX32 set. So the proposed is_compat_task() is meaningless in this context - hence Andi doesn't want is_compat_task() propagated around the place.

This begs the question of how his kernel correctly handle these pseudo-32-bit tasks.

Well, what we actually want to know is whether to deliver 32- or 64-bit signals to this task. So what if we simply renamed is_compat_task() to task_wants_compat_signals()?

Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain
#8 lore raw
In reply to Andrew Morton
Quoted 9 lines · Andrew Morton

I can sort-of-see Andi's worry.

The issue appears to be that at some time in the future he will have 64-bit applications using the 32-bit API without PER_LINUX32 set. So the proposed is_compat_task() is meaningless in this context - hence Andi doesn't want is_compat_task() propagated around the place.

This begs the question of how his kernel correctly handle these pseudo-32-bit tasks.

Actually, I'd take the opposite view: is_compat_task() abstracts out the job of discovering whether the task is using the 32 bit API on 64 bits.

However it's done on every arch that supports it, there must be always an unequivocal answer to "is this task running 32 bits?" which this macro supplies. I agree it's not always going to be dependent on PER_LINUX32 being set, but providing arch's with a way to override it answers that point, I think.

It's in generic code because there's a standard way of identifying these compat tasks (PER_LINUX32) and it's overrideable for arch's that want to do it in a non-standard way.

James