Skip to content

Commit

Permalink
compat: provide compat_ptr() on all architectures
Browse files Browse the repository at this point in the history
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.

Reviewed-by: Ben Hutchings <[email protected]>
Signed-off-by: Arnd Bergmann <[email protected]>
  • Loading branch information
arndb committed Jan 3, 2020
1 parent 556d687 commit 202bf8d
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 109 deletions.
17 changes: 0 additions & 17 deletions arch/arm64/include/asm/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,6 @@ typedef u32 compat_sigset_word;

#define COMPAT_OFF_T_MAX 0x7fffffff

/*
* A pointer passed in from user mode. This should not
* be used for syscall parameters, just declare them
* as pointers because the syscall entry code will have
* appropriately converted them already.
*/

static inline void __user *compat_ptr(compat_uptr_t uptr)
{
return (void __user *)(unsigned long)uptr;
}

static inline compat_uptr_t ptr_to_compat(void __user *uptr)
{
return (u32)(unsigned long)uptr;
}

#define compat_user_stack_pointer() (user_stack_pointer(task_pt_regs(current)))
#define COMPAT_MINSIGSTKSZ 2048

Expand Down
18 changes: 0 additions & 18 deletions arch/mips/include/asm/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,6 @@ typedef u32 compat_sigset_word;

#define COMPAT_OFF_T_MAX 0x7fffffff

/*
* A pointer passed in from user mode. This should not
* be used for syscall parameters, just declare them
* as pointers because the syscall entry code will have
* appropriately converted them already.
*/

static inline void __user *compat_ptr(compat_uptr_t uptr)
{
/* cast to a __user pointer via "unsigned long" makes sparse happy */
return (void __user *)(unsigned long)(long)uptr;
}

static inline compat_uptr_t ptr_to_compat(void __user *uptr)
{
return (u32)(unsigned long)uptr;
}

static inline void __user *arch_compat_alloc_user_space(long len)
{
struct pt_regs *regs = (struct pt_regs *)
Expand Down
17 changes: 0 additions & 17 deletions arch/parisc/include/asm/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,23 +173,6 @@ struct compat_shmid64_ds {
#define COMPAT_ELF_NGREG 80
typedef compat_ulong_t compat_elf_gregset_t[COMPAT_ELF_NGREG];

/*
* A pointer passed in from user mode. This should not
* be used for syscall parameters, just declare them
* as pointers because the syscall entry code will have
* appropriately converted them already.
*/

static inline void __user *compat_ptr(compat_uptr_t uptr)
{
return (void __user *)(unsigned long)uptr;
}

static inline compat_uptr_t ptr_to_compat(void __user *uptr)
{
return (u32)(unsigned long)uptr;
}

static __inline__ void __user *arch_compat_alloc_user_space(long len)
{
struct pt_regs *regs = &current->thread.regs;
Expand Down
17 changes: 0 additions & 17 deletions arch/powerpc/include/asm/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,6 @@ typedef u32 compat_sigset_word;

#define COMPAT_OFF_T_MAX 0x7fffffff

/*
* A pointer passed in from user mode. This should not
* be used for syscall parameters, just declare them
* as pointers because the syscall entry code will have
* appropriately converted them already.
*/

static inline void __user *compat_ptr(compat_uptr_t uptr)
{
return (void __user *)(unsigned long)uptr;
}

static inline compat_uptr_t ptr_to_compat(void __user *uptr)
{
return (u32)(unsigned long)uptr;
}

static inline void __user *arch_compat_alloc_user_space(long len)
{
struct pt_regs *regs = current->thread.regs;
Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/oprofile/backtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <linux/sched.h>
#include <asm/processor.h>
#include <linux/uaccess.h>
#include <asm/compat.h>
#include <linux/compat.h>
#include <asm/oprofile_impl.h>

#define STACK_SP(STACK) *(STACK)
Expand Down
6 changes: 1 addition & 5 deletions arch/s390/include/asm/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,7 @@ static inline void __user *compat_ptr(compat_uptr_t uptr)
{
return (void __user *)(unsigned long)(uptr & 0x7fffffffUL);
}

static inline compat_uptr_t ptr_to_compat(void __user *uptr)
{
return (u32)(unsigned long)uptr;
}
#define compat_ptr(uptr) compat_ptr(uptr)

#ifdef CONFIG_COMPAT

Expand Down
17 changes: 0 additions & 17 deletions arch/sparc/include/asm/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,6 @@ typedef u32 compat_sigset_word;

#define COMPAT_OFF_T_MAX 0x7fffffff

/*
* A pointer passed in from user mode. This should not
* be used for syscall parameters, just declare them
* as pointers because the syscall entry code will have
* appropriately converted them already.
*/

static inline void __user *compat_ptr(compat_uptr_t uptr)
{
return (void __user *)(unsigned long)uptr;
}

static inline compat_uptr_t ptr_to_compat(void __user *uptr)
{
return (u32)(unsigned long)uptr;
}

#ifdef CONFIG_COMPAT
static inline void __user *arch_compat_alloc_user_space(long len)
{
Expand Down
17 changes: 0 additions & 17 deletions arch/x86/include/asm/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,23 +177,6 @@ typedef struct user_regs_struct compat_elf_gregset_t;
(!!(task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT))
#endif

/*
* A pointer passed in from user mode. This should not
* be used for syscall parameters, just declare them
* as pointers because the syscall entry code will have
* appropriately converted them already.
*/

static inline void __user *compat_ptr(compat_uptr_t uptr)
{
return (void __user *)(unsigned long)uptr;
}

static inline compat_uptr_t ptr_to_compat(void __user *uptr)
{
return (u32)(unsigned long)uptr;
}

static inline void __user *arch_compat_alloc_user_space(long len)
{
compat_uptr_t sp;
Expand Down
18 changes: 18 additions & 0 deletions include/linux/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -958,4 +958,22 @@ static inline bool in_compat_syscall(void) { return false; }

#endif /* CONFIG_COMPAT */

/*
* A pointer passed in from user mode. This should not
* be used for syscall parameters, just declare them
* as pointers because the syscall entry code will have
* appropriately converted them already.
*/
#ifndef compat_ptr
static inline void __user *compat_ptr(compat_uptr_t uptr)
{
return (void __user *)(unsigned long)uptr;
}
#endif

static inline compat_uptr_t ptr_to_compat(void __user *uptr)
{
return (u32)(unsigned long)uptr;
}

#endif /* _LINUX_COMPAT_H */

0 comments on commit 202bf8d

Please sign in to comment.