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
114 114
115#define COMPAT_OFF_T_MAX 0x7fffffff115#define COMPAT_OFF_T_MAX 0x7fffffff
116 116
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
124static inline void __user *compat_ptr(compat_uptr_t uptr)
125{
126 return (void __user *)(unsigned long)uptr;
127}
128
129static inline compat_uptr_t ptr_to_compat(void __user *uptr)
130{
131 return (u32)(unsigned long)uptr;
132}
133
134#define compat_user_stack_pointer() (user_stack_pointer(task_pt_regs(current)))117#define compat_user_stack_pointer() (user_stack_pointer(task_pt_regs(current)))
135#define COMPAT_MINSIGSTKSZ 2048118#define COMPAT_MINSIGSTKSZ 2048
136 119
arch/mips/include/asm/compat.h+0−18
@@ -100,24 +100,6 @@ typedef u32 compat_sigset_word; · 99 unmodified lines
100 100
101#define COMPAT_OFF_T_MAX 0x7fffffff101#define COMPAT_OFF_T_MAX 0x7fffffff
102 102
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
110static 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
116static inline compat_uptr_t ptr_to_compat(void __user *uptr)
117{
118 return (u32)(unsigned long)uptr;
119}
120
121static inline void __user *arch_compat_alloc_user_space(long len)103static inline void __user *arch_compat_alloc_user_space(long len)
122{104{
123 struct pt_regs *regs = (struct pt_regs *)105 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
173#define COMPAT_ELF_NGREG 80173#define COMPAT_ELF_NGREG 80
174typedef compat_ulong_t compat_elf_gregset_t[COMPAT_ELF_NGREG];174typedef compat_ulong_t compat_elf_gregset_t[COMPAT_ELF_NGREG];
175 175
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
183static inline void __user *compat_ptr(compat_uptr_t uptr)
184{
185 return (void __user *)(unsigned long)uptr;
186}
187
188static inline compat_uptr_t ptr_to_compat(void __user *uptr)
189{
190 return (u32)(unsigned long)uptr;
191}
192
193static __inline__ void __user *arch_compat_alloc_user_space(long len)176static __inline__ void __user *arch_compat_alloc_user_space(long len)
194{177{
195 struct pt_regs *regs = &current->thread.regs;178 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
96 96
97#define COMPAT_OFF_T_MAX 0x7fffffff97#define COMPAT_OFF_T_MAX 0x7fffffff
98 98
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
106static inline void __user *compat_ptr(compat_uptr_t uptr)
107{
108 return (void __user *)(unsigned long)uptr;
109}
110
111static inline compat_uptr_t ptr_to_compat(void __user *uptr)
112{
113 return (u32)(unsigned long)uptr;
114}
115
116static inline void __user *arch_compat_alloc_user_space(long len)99static inline void __user *arch_compat_alloc_user_space(long len)
117{100{
118 struct pt_regs *regs = current->thread.regs;101 struct pt_regs *regs = current->thread.regs;
arch/powerpc/oprofile/backtrace.c+1−1
@@ -9,7 +9,7 @@ · 8 unmodified lines
9#include <linux/sched.h>9#include <linux/sched.h>
10#include <asm/processor.h>10#include <asm/processor.h>
11#include <linux/uaccess.h>11#include <linux/uaccess.h>
12#include <asm/compat.h>12#include <linux/compat.h>
13#include <asm/oprofile_impl.h>13#include <asm/oprofile_impl.h>
14 14
15#define STACK_SP(STACK) *(STACK)15#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
177{177{
178 return (void __user *)(unsigned long)(uptr & 0x7fffffffUL);178 return (void __user *)(unsigned long)(uptr & 0x7fffffffUL);
179}179}
180 180#define compat_ptr(uptr) compat_ptr(uptr)
181static inline compat_uptr_t ptr_to_compat(void __user *uptr)
182{
183 return (u32)(unsigned long)uptr;
184}
185 181
186#ifdef CONFIG_COMPAT182#ifdef CONFIG_COMPAT
187 183
arch/sparc/include/asm/compat.h+0−17
@@ -125,23 +125,6 @@ typedef u32 compat_sigset_word; · 124 unmodified lines
125 125
126#define COMPAT_OFF_T_MAX 0x7fffffff126#define COMPAT_OFF_T_MAX 0x7fffffff
127 127
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
135static inline void __user *compat_ptr(compat_uptr_t uptr)
136{
137 return (void __user *)(unsigned long)uptr;
138}
139
140static inline compat_uptr_t ptr_to_compat(void __user *uptr)
141{
142 return (u32)(unsigned long)uptr;
143}
144
145#ifdef CONFIG_COMPAT128#ifdef CONFIG_COMPAT
146static inline void __user *arch_compat_alloc_user_space(long len)129static inline void __user *arch_compat_alloc_user_space(long len)
147{130{
arch/x86/include/asm/compat.h+0−17
@@ -177,23 +177,6 @@ typedef struct user_regs_struct compat_elf_gregset_t; · 176 unmodified lines
177 (!!(task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT))177 (!!(task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT))
178#endif178#endif
179 179
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
187static inline void __user *compat_ptr(compat_uptr_t uptr)
188{
189 return (void __user *)(unsigned long)uptr;
190}
191
192static inline compat_uptr_t ptr_to_compat(void __user *uptr)
193{
194 return (u32)(unsigned long)uptr;
195}
196
197static inline void __user *arch_compat_alloc_user_space(long len)180static inline void __user *arch_compat_alloc_user_space(long len)
198{181{
199 compat_uptr_t sp;182 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
958 958
959#endif /* CONFIG_COMPAT */959#endif /* CONFIG_COMPAT */
960 960
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
968static inline void __user *compat_ptr(compat_uptr_t uptr)
969{
970 return (void __user *)(unsigned long)uptr;
971}
972#endif
973
974static inline compat_uptr_t ptr_to_compat(void __user *uptr)
975{
976 return (u32)(unsigned long)uptr;
977}
978
961#endif /* _LINUX_COMPAT_H */979#endif /* _LINUX_COMPAT_H */