Skip to content

Commit 1a33b18

Browse files
arndbdavem330
authored andcommitted
compat: make linux/compat.h available everywhere
Parts of linux/compat.h are under an #ifdef, but we end up using more of those over time, moving things around bit by bit. To get it over with once and for all, make all of this file uncondititonal now so it can be accessed everywhere. There are only a few types left that are in asm/compat.h but not yet in the asm-generic version, so add those in the process. This requires providing a few more types in asm-generic/compat.h that were not already there. The only tricky one is compat_sigset_t, which needs a little help on 32-bit architectures and for x86. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 4431531 commit 1a33b18

File tree

10 files changed

+59
-96
lines changed

10 files changed

+59
-96
lines changed

arch/arm64/include/asm/compat.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#ifndef __ASM_COMPAT_H
66
#define __ASM_COMPAT_H
77

8+
#define compat_mode_t compat_mode_t
9+
typedef u16 compat_mode_t;
10+
811
#include <asm-generic/compat.h>
912

1013
#ifdef CONFIG_COMPAT
@@ -27,13 +30,9 @@ typedef u16 __compat_uid_t;
2730
typedef u16 __compat_gid_t;
2831
typedef u16 __compat_uid16_t;
2932
typedef u16 __compat_gid16_t;
30-
typedef u32 __compat_uid32_t;
31-
typedef u32 __compat_gid32_t;
32-
typedef u16 compat_mode_t;
3333
typedef u32 compat_dev_t;
3434
typedef s32 compat_nlink_t;
3535
typedef u16 compat_ipc_pid_t;
36-
typedef u32 compat_caddr_t;
3736
typedef __kernel_fsid_t compat_fsid_t;
3837

3938
struct compat_stat {
@@ -103,13 +102,6 @@ struct compat_statfs {
103102

104103
#define COMPAT_RLIM_INFINITY 0xffffffff
105104

106-
typedef u32 compat_old_sigset_t;
107-
108-
#define _COMPAT_NSIG 64
109-
#define _COMPAT_NSIG_BPW 32
110-
111-
typedef u32 compat_sigset_word;
112-
113105
#define COMPAT_OFF_T_MAX 0x7fffffff
114106

115107
#define compat_user_stack_pointer() (user_stack_pointer(task_pt_regs(current)))

arch/mips/include/asm/compat.h

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,25 @@
99
#include <asm/page.h>
1010
#include <asm/ptrace.h>
1111

12+
typedef s32 __compat_uid_t;
13+
typedef s32 __compat_gid_t;
14+
typedef __compat_uid_t __compat_uid32_t;
15+
typedef __compat_gid_t __compat_gid32_t;
16+
#define __compat_uid32_t __compat_uid32_t
17+
#define __compat_gid32_t __compat_gid32_t
18+
19+
#define _COMPAT_NSIG 128 /* Don't ask !$@#% ... */
20+
#define _COMPAT_NSIG_BPW 32
21+
typedef u32 compat_sigset_word;
22+
1223
#include <asm-generic/compat.h>
1324

1425
#define COMPAT_USER_HZ 100
1526
#define COMPAT_UTS_MACHINE "mips\0\0\0"
1627

17-
typedef s32 __compat_uid_t;
18-
typedef s32 __compat_gid_t;
19-
typedef __compat_uid_t __compat_uid32_t;
20-
typedef __compat_gid_t __compat_gid32_t;
21-
typedef u32 compat_mode_t;
2228
typedef u32 compat_dev_t;
2329
typedef u32 compat_nlink_t;
2430
typedef s32 compat_ipc_pid_t;
25-
typedef s32 compat_caddr_t;
2631
typedef struct {
2732
s32 val[2];
2833
} compat_fsid_t;
@@ -89,13 +94,6 @@ struct compat_statfs {
8994

9095
#define COMPAT_RLIM_INFINITY 0x7fffffffUL
9196

92-
typedef u32 compat_old_sigset_t; /* at least 32 bits */
93-
94-
#define _COMPAT_NSIG 128 /* Don't ask !$@#% ... */
95-
#define _COMPAT_NSIG_BPW 32
96-
97-
typedef u32 compat_sigset_word;
98-
9997
#define COMPAT_OFF_T_MAX 0x7fffffff
10098

10199
static inline void __user *arch_compat_alloc_user_space(long len)

arch/parisc/include/asm/compat.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,19 @@
88
#include <linux/sched.h>
99
#include <linux/thread_info.h>
1010

11+
#define compat_mode_t compat_mode_t
12+
typedef u16 compat_mode_t;
13+
1114
#include <asm-generic/compat.h>
1215

1316
#define COMPAT_USER_HZ 100
1417
#define COMPAT_UTS_MACHINE "parisc\0\0"
1518

1619
typedef u32 __compat_uid_t;
1720
typedef u32 __compat_gid_t;
18-
typedef u32 __compat_uid32_t;
19-
typedef u32 __compat_gid32_t;
20-
typedef u16 compat_mode_t;
2121
typedef u32 compat_dev_t;
2222
typedef u16 compat_nlink_t;
2323
typedef u16 compat_ipc_pid_t;
24-
typedef u32 compat_caddr_t;
2524

2625
struct compat_stat {
2726
compat_dev_t st_dev; /* dev_t is 32 bits on parisc */
@@ -96,13 +95,6 @@ struct compat_sigcontext {
9695

9796
#define COMPAT_RLIM_INFINITY 0xffffffff
9897

99-
typedef u32 compat_old_sigset_t; /* at least 32 bits */
100-
101-
#define _COMPAT_NSIG 64
102-
#define _COMPAT_NSIG_BPW 32
103-
104-
typedef u32 compat_sigset_word;
105-
10698
#define COMPAT_OFF_T_MAX 0x7fffffff
10799

108100
struct compat_ipc64_perm {

arch/powerpc/include/asm/compat.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,9 @@
1919

2020
typedef u32 __compat_uid_t;
2121
typedef u32 __compat_gid_t;
22-
typedef u32 __compat_uid32_t;
23-
typedef u32 __compat_gid32_t;
24-
typedef u32 compat_mode_t;
2522
typedef u32 compat_dev_t;
2623
typedef s16 compat_nlink_t;
2724
typedef u16 compat_ipc_pid_t;
28-
typedef u32 compat_caddr_t;
2925
typedef __kernel_fsid_t compat_fsid_t;
3026

3127
struct compat_stat {
@@ -85,13 +81,6 @@ struct compat_statfs {
8581

8682
#define COMPAT_RLIM_INFINITY 0xffffffff
8783

88-
typedef u32 compat_old_sigset_t;
89-
90-
#define _COMPAT_NSIG 64
91-
#define _COMPAT_NSIG_BPW 32
92-
93-
typedef u32 compat_sigset_word;
94-
9584
#define COMPAT_OFF_T_MAX 0x7fffffff
9685

9786
static inline void __user *arch_compat_alloc_user_space(long len)

arch/s390/include/asm/compat.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include <linux/sched/task_stack.h>
1010
#include <linux/thread_info.h>
1111

12+
#define compat_mode_t compat_mode_t
13+
typedef u16 compat_mode_t;
14+
1215
#include <asm-generic/compat.h>
1316

1417
#define __TYPE_IS_PTR(t) (!__builtin_types_compatible_p( \
@@ -55,13 +58,9 @@
5558

5659
typedef u16 __compat_uid_t;
5760
typedef u16 __compat_gid_t;
58-
typedef u32 __compat_uid32_t;
59-
typedef u32 __compat_gid32_t;
60-
typedef u16 compat_mode_t;
6161
typedef u16 compat_dev_t;
6262
typedef u16 compat_nlink_t;
6363
typedef u16 compat_ipc_pid_t;
64-
typedef u32 compat_caddr_t;
6564
typedef __kernel_fsid_t compat_fsid_t;
6665

6766
typedef struct {
@@ -155,13 +154,6 @@ struct compat_statfs64 {
155154

156155
#define COMPAT_RLIM_INFINITY 0xffffffff
157156

158-
typedef u32 compat_old_sigset_t; /* at least 32 bits */
159-
160-
#define _COMPAT_NSIG 64
161-
#define _COMPAT_NSIG_BPW 32
162-
163-
typedef u32 compat_sigset_word;
164-
165157
#define COMPAT_OFF_T_MAX 0x7fffffff
166158

167159
/*

arch/sparc/include/asm/compat.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@
66
*/
77
#include <linux/types.h>
88

9+
#define compat_mode_t compat_mode_t
10+
typedef u16 compat_mode_t;
11+
912
#include <asm-generic/compat.h>
1013

1114
#define COMPAT_USER_HZ 100
1215
#define COMPAT_UTS_MACHINE "sparc\0\0"
1316

1417
typedef u16 __compat_uid_t;
1518
typedef u16 __compat_gid_t;
16-
typedef u32 __compat_uid32_t;
17-
typedef u32 __compat_gid32_t;
18-
typedef u16 compat_mode_t;
1919
typedef u16 compat_dev_t;
2020
typedef s16 compat_nlink_t;
2121
typedef u16 compat_ipc_pid_t;
22-
typedef u32 compat_caddr_t;
2322
typedef __kernel_fsid_t compat_fsid_t;
2423

2524
struct compat_stat {
@@ -115,13 +114,6 @@ struct compat_statfs {
115114

116115
#define COMPAT_RLIM_INFINITY 0x7fffffff
117116

118-
typedef u32 compat_old_sigset_t;
119-
120-
#define _COMPAT_NSIG 64
121-
#define _COMPAT_NSIG_BPW 32
122-
123-
typedef u32 compat_sigset_word;
124-
125117
#define COMPAT_OFF_T_MAX 0x7fffffff
126118

127119
#ifdef CONFIG_COMPAT

arch/x86/include/asm/compat.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,19 @@
1212
#include <asm/user32.h>
1313
#include <asm/unistd.h>
1414

15+
#define compat_mode_t compat_mode_t
16+
typedef u16 compat_mode_t;
17+
1518
#include <asm-generic/compat.h>
1619

1720
#define COMPAT_USER_HZ 100
1821
#define COMPAT_UTS_MACHINE "i686\0\0"
1922

2023
typedef u16 __compat_uid_t;
2124
typedef u16 __compat_gid_t;
22-
typedef u32 __compat_uid32_t;
23-
typedef u32 __compat_gid32_t;
24-
typedef u16 compat_mode_t;
2525
typedef u16 compat_dev_t;
2626
typedef u16 compat_nlink_t;
2727
typedef u16 compat_ipc_pid_t;
28-
typedef u32 compat_caddr_t;
2928
typedef __kernel_fsid_t compat_fsid_t;
3029

3130
struct compat_stat {
@@ -92,13 +91,6 @@ struct compat_statfs {
9291

9392
#define COMPAT_RLIM_INFINITY 0xffffffff
9493

95-
typedef u32 compat_old_sigset_t; /* at least 32 bits */
96-
97-
#define _COMPAT_NSIG 64
98-
#define _COMPAT_NSIG_BPW 32
99-
100-
typedef u32 compat_sigset_word;
101-
10294
#define COMPAT_OFF_T_MAX 0x7fffffff
10395

10496
struct compat_ipc64_perm {

arch/x86/include/asm/signal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ typedef struct {
2929
#define SA_X32_ABI 0x01000000u
3030

3131
#ifndef CONFIG_COMPAT
32+
#define compat_sigset_t compat_sigset_t
3233
typedef sigset_t compat_sigset_t;
3334
#endif
3435

include/asm-generic/compat.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,18 @@ typedef u16 compat_ushort_t;
2020
typedef u32 compat_uint_t;
2121
typedef u32 compat_ulong_t;
2222
typedef u32 compat_uptr_t;
23+
typedef u32 compat_caddr_t;
2324
typedef u32 compat_aio_context_t;
25+
typedef u32 compat_old_sigset_t;
26+
27+
#ifndef __compat_uid32_t
28+
typedef u32 __compat_uid32_t;
29+
typedef u32 __compat_gid32_t;
30+
#endif
31+
32+
#ifndef compat_mode_t
33+
typedef u32 compat_mode_t;
34+
#endif
2435

2536
#ifdef CONFIG_COMPAT_FOR_U64_ALIGNMENT
2637
typedef s64 __attribute__((aligned(4))) compat_s64;
@@ -30,4 +41,10 @@ typedef s64 compat_s64;
3041
typedef u64 compat_u64;
3142
#endif
3243

44+
#ifndef _COMPAT_NSIG
45+
typedef u32 compat_sigset_word;
46+
#define _COMPAT_NSIG _NSIG
47+
#define _COMPAT_NSIG_BPW 32
48+
#endif
49+
3350
#endif

include/linux/compat.h

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@
2020
#include <linux/unistd.h>
2121

2222
#include <asm/compat.h>
23-
24-
#ifdef CONFIG_COMPAT
2523
#include <asm/siginfo.h>
2624
#include <asm/signal.h>
27-
#endif
2825

2926
#ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER
3027
/*
@@ -95,8 +92,6 @@ struct compat_iovec {
9592
compat_size_t iov_len;
9693
};
9794

98-
#ifdef CONFIG_COMPAT
99-
10095
#ifndef compat_user_stack_pointer
10196
#define compat_user_stack_pointer() current_user_stack_pointer()
10297
#endif
@@ -131,9 +126,11 @@ struct compat_tms {
131126

132127
#define _COMPAT_NSIG_WORDS (_COMPAT_NSIG / _COMPAT_NSIG_BPW)
133128

129+
#ifndef compat_sigset_t
134130
typedef struct {
135131
compat_sigset_word sig[_COMPAT_NSIG_WORDS];
136132
} compat_sigset_t;
133+
#endif
137134

138135
int set_compat_user_sigmask(const compat_sigset_t __user *umask,
139136
size_t sigsetsize);
@@ -384,6 +381,7 @@ struct compat_keyctl_kdf_params {
384381
__u32 __spare[8];
385382
};
386383

384+
struct compat_stat;
387385
struct compat_statfs;
388386
struct compat_statfs64;
389387
struct compat_old_linux_dirent;
@@ -428,7 +426,7 @@ put_compat_sigset(compat_sigset_t __user *compat, const sigset_t *set,
428426
unsigned int size)
429427
{
430428
/* size <= sizeof(compat_sigset_t) <= sizeof(sigset_t) */
431-
#ifdef __BIG_ENDIAN
429+
#if defined(__BIG_ENDIAN) && defined(CONFIG_64BIT)
432430
compat_sigset_t v;
433431
switch (_NSIG_WORDS) {
434432
case 4: v.sig[7] = (set->sig[3] >> 32); v.sig[6] = set->sig[3];
@@ -929,17 +927,6 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args);
929927

930928
#endif /* CONFIG_ARCH_HAS_SYSCALL_WRAPPER */
931929

932-
933-
/*
934-
* For most but not all architectures, "am I in a compat syscall?" and
935-
* "am I a compat task?" are the same question. For architectures on which
936-
* they aren't the same question, arch code can override in_compat_syscall.
937-
*/
938-
939-
#ifndef in_compat_syscall
940-
static inline bool in_compat_syscall(void) { return is_compat_task(); }
941-
#endif
942-
943930
/**
944931
* ns_to_old_timeval32 - Compat version of ns_to_timeval
945932
* @nsec: the nanoseconds value to be converted
@@ -969,6 +956,17 @@ int kcompat_sys_statfs64(const char __user * pathname, compat_size_t sz,
969956
int kcompat_sys_fstatfs64(unsigned int fd, compat_size_t sz,
970957
struct compat_statfs64 __user * buf);
971958

959+
#ifdef CONFIG_COMPAT
960+
961+
/*
962+
* For most but not all architectures, "am I in a compat syscall?" and
963+
* "am I a compat task?" are the same question. For architectures on which
964+
* they aren't the same question, arch code can override in_compat_syscall.
965+
*/
966+
#ifndef in_compat_syscall
967+
static inline bool in_compat_syscall(void) { return is_compat_task(); }
968+
#endif
969+
972970
#else /* !CONFIG_COMPAT */
973971

974972
#define is_compat_task() (0)

0 commit comments

Comments
 (0)