History

compat: provide compat_ptr() on all architectures

In order to avoid needless #ifdef CONFIG_COMPAT checks, move the compat_ptr() definition to linux/compat.h where it can be seen by any file regardless of the architecture. Only s390 needs a special definition, this can use the self-#define trick we have elsewhere.

Arnd Bergmann committed 6 years ago

Commit 202bf8d1 parent 556d6879 files · +20 −109Browse files

Unified · Split

9 files
  1. arch/arm64/include/asm/compat.h +0 −17
  2. arch/mips/include/asm/compat.h +0 −18
  3. arch/parisc/include/asm/compat.h +0 −17
  4. arch/powerpc/include/asm/compat.h +0 −17
  5. arch/powerpc/oprofile/backtrace.c +1 −1
  6. arch/s390/include/asm/compat.h +1 −5
  7. arch/sparc/include/asm/compat.h +0 −17
  8. arch/x86/include/asm/compat.h +0 −17
  9. include/linux/compat.h +18 −0
arch/arm64/include/asm/compat.h+0−17
@@ -114,23 +114,6 @@ typedef u32 compat_sigset_word; · 113 unmodified lines
114114
115115 #define COMPAT_OFF_T_MAX 0x7fffffff
116116
117−/*
118− * A pointer passed in from user mode. This should not
119− * be used for syscall parameters, just declare them
120− * as pointers because the syscall entry code will have
121− * appropriately converted them already.
122− */
123−
124−static inline void __user *compat_ptr(compat_uptr_t uptr)
125−{
126− return (void __user *)(unsigned long)uptr;
127−}
128−
129−static inline compat_uptr_t ptr_to_compat(void __user *uptr)
130−{
131− return (u32)(unsigned long)uptr;
132−}
133−
134117 #define compat_user_stack_pointer() (user_stack_pointer(task_pt_regs(current)))
135118 #define COMPAT_MINSIGSTKSZ 2048
136119
arch/mips/include/asm/compat.h+0−18
@@ -100,24 +100,6 @@ typedef u32 compat_sigset_word; · 99 unmodified lines
100100
101101 #define COMPAT_OFF_T_MAX 0x7fffffff
102102
103−/*
104− * A pointer passed in from user mode. This should not
105− * be used for syscall parameters, just declare them
106− * as pointers because the syscall entry code will have
107− * appropriately converted them already.
108− */
109−
110−static inline void __user *compat_ptr(compat_uptr_t uptr)
111−{
112− /* cast to a __user pointer via "unsigned long" makes sparse happy */
113− return (void __user *)(unsigned long)(long)uptr;
114−}
115−
116−static inline compat_uptr_t ptr_to_compat(void __user *uptr)
117−{
118− return (u32)(unsigned long)uptr;
119−}
120−
121103 static inline void __user *arch_compat_alloc_user_space(long len)
122104 {
123105 struct pt_regs *regs = (struct pt_regs *)
arch/parisc/include/asm/compat.h+0−17
@@ -173,23 +173,6 @@ struct compat_shmid64_ds { · 172 unmodified lines
173173 #define COMPAT_ELF_NGREG 80
174174 typedef compat_ulong_t compat_elf_gregset_t[COMPAT_ELF_NGREG];
175175
176−/*
177− * A pointer passed in from user mode. This should not
178− * be used for syscall parameters, just declare them
179− * as pointers because the syscall entry code will have
180− * appropriately converted them already.
181− */
182−
183−static inline void __user *compat_ptr(compat_uptr_t uptr)
184−{
185− return (void __user *)(unsigned long)uptr;
186−}
187−
188−static inline compat_uptr_t ptr_to_compat(void __user *uptr)
189−{
190− return (u32)(unsigned long)uptr;
191−}
192−
193176 static __inline__ void __user *arch_compat_alloc_user_space(long len)
194177 {
195178 struct pt_regs *regs = &current->thread.regs;
arch/powerpc/include/asm/compat.h+0−17
@@ -96,23 +96,6 @@ typedef u32 compat_sigset_word; · 95 unmodified lines
9696
9797 #define COMPAT_OFF_T_MAX 0x7fffffff
9898
99−/*
100− * A pointer passed in from user mode. This should not
101− * be used for syscall parameters, just declare them
102− * as pointers because the syscall entry code will have
103− * appropriately converted them already.
104− */
105−
106−static inline void __user *compat_ptr(compat_uptr_t uptr)
107−{
108− return (void __user *)(unsigned long)uptr;
109−}
110−
111−static inline compat_uptr_t ptr_to_compat(void __user *uptr)
112−{
113− return (u32)(unsigned long)uptr;
114−}
115−
11699 static inline void __user *arch_compat_alloc_user_space(long len)
117100 {
118101 struct pt_regs *regs = current->thread.regs;
arch/powerpc/oprofile/backtrace.c+1−1
@@ -9,7 +9,7 @@ · 8 unmodified lines
99 #include <linux/sched.h>
1010 #include <asm/processor.h>
1111 #include <linux/uaccess.h>
12−#include <asm/compat.h>
12+#include <linux/compat.h>
1313 #include <asm/oprofile_impl.h>
1414
1515 #define STACK_SP(STACK) *(STACK)
arch/s390/include/asm/compat.h+1−5
@@ -177,11 +177,7 @@ static inline void __user *compat_ptr(compat_uptr_t uptr) · 176 unmodified lines
177177 {
178178 return (void __user *)(unsigned long)(uptr & 0x7fffffffUL);
179179 }
180−
181−static inline compat_uptr_t ptr_to_compat(void __user *uptr)
182−{
183− return (u32)(unsigned long)uptr;
184−}
180+#define compat_ptr(uptr) compat_ptr(uptr)
185181
186182 #ifdef CONFIG_COMPAT
187183
arch/sparc/include/asm/compat.h+0−17
@@ -125,23 +125,6 @@ typedef u32 compat_sigset_word; · 124 unmodified lines
125125
126126 #define COMPAT_OFF_T_MAX 0x7fffffff
127127
128−/*
129− * A pointer passed in from user mode. This should not
130− * be used for syscall parameters, just declare them
131− * as pointers because the syscall entry code will have
132− * appropriately converted them already.
133− */
134−
135−static inline void __user *compat_ptr(compat_uptr_t uptr)
136−{
137− return (void __user *)(unsigned long)uptr;
138−}
139−
140−static inline compat_uptr_t ptr_to_compat(void __user *uptr)
141−{
142− return (u32)(unsigned long)uptr;
143−}
144−
145128 #ifdef CONFIG_COMPAT
146129 static inline void __user *arch_compat_alloc_user_space(long len)
147130 {
arch/x86/include/asm/compat.h+0−17
@@ -177,23 +177,6 @@ typedef struct user_regs_struct compat_elf_gregset_t; · 176 unmodified lines
177177 (!!(task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT))
178178 #endif
179179
180−/*
181− * A pointer passed in from user mode. This should not
182− * be used for syscall parameters, just declare them
183− * as pointers because the syscall entry code will have
184− * appropriately converted them already.
185− */
186−
187−static inline void __user *compat_ptr(compat_uptr_t uptr)
188−{
189− return (void __user *)(unsigned long)uptr;
190−}
191−
192−static inline compat_uptr_t ptr_to_compat(void __user *uptr)
193−{
194− return (u32)(unsigned long)uptr;
195−}
196−
197180 static inline void __user *arch_compat_alloc_user_space(long len)
198181 {
199182 compat_uptr_t sp;
include/linux/compat.h+18−0
@@ -958,4 +958,22 @@ static inline bool in_compat_syscall(void) { return false; } · 957 unmodified lines
958958
959959 #endif /* CONFIG_COMPAT */
960960
961+/*
962+ * A pointer passed in from user mode. This should not
963+ * be used for syscall parameters, just declare them
964+ * as pointers because the syscall entry code will have
965+ * appropriately converted them already.
966+ */
967+#ifndef compat_ptr
968+static inline void __user *compat_ptr(compat_uptr_t uptr)
969+{
970+ return (void __user *)(unsigned long)uptr;
971+}
972+#endif
973+
974+static inline compat_uptr_t ptr_to_compat(void __user *uptr)
975+{
976+ return (u32)(unsigned long)uptr;
977+}
978+
961979 #endif /* _LINUX_COMPAT_H */