Thomas Gleixner | caab277 | 2019-06-03 07:44:50 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Will Deacon | 3dd681d | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2012 ARM Ltd. |
Will Deacon | 3dd681d | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 4 | */ |
| 5 | #ifndef __ASM_COMPAT_H |
| 6 | #define __ASM_COMPAT_H |
| 7 | #ifdef __KERNEL__ |
| 8 | #ifdef CONFIG_COMPAT |
| 9 | |
| 10 | /* |
| 11 | * Architecture specific compatibility types |
| 12 | */ |
| 13 | #include <linux/types.h> |
| 14 | #include <linux/sched.h> |
Ingo Molnar | 68db0cf | 2017-02-08 18:51:37 +0100 | [diff] [blame] | 15 | #include <linux/sched/task_stack.h> |
Will Deacon | 3dd681d | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 16 | |
Arnd Bergmann | fb37397 | 2018-04-18 22:01:26 +0200 | [diff] [blame] | 17 | #include <asm-generic/compat.h> |
| 18 | |
Will Deacon | 3dd681d | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 19 | #define COMPAT_USER_HZ 100 |
Will Deacon | a795a38 | 2013-10-11 14:52:12 +0100 | [diff] [blame] | 20 | #ifdef __AARCH64EB__ |
| 21 | #define COMPAT_UTS_MACHINE "armv8b\0\0" |
| 22 | #else |
Will Deacon | 3dd681d | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 23 | #define COMPAT_UTS_MACHINE "armv8l\0\0" |
Will Deacon | a795a38 | 2013-10-11 14:52:12 +0100 | [diff] [blame] | 24 | #endif |
Will Deacon | 3dd681d | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 25 | |
Victor Kamensky | 971a5b6 | 2014-10-14 06:55:05 +0100 | [diff] [blame] | 26 | typedef u16 __compat_uid_t; |
| 27 | typedef u16 __compat_gid_t; |
Catalin Marinas | f15a2a1 | 2013-04-25 11:23:41 +0100 | [diff] [blame] | 28 | typedef u16 __compat_uid16_t; |
| 29 | typedef u16 __compat_gid16_t; |
Will Deacon | 3dd681d | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 30 | typedef u32 __compat_uid32_t; |
| 31 | typedef u32 __compat_gid32_t; |
Catalin Marinas | f15a2a1 | 2013-04-25 11:23:41 +0100 | [diff] [blame] | 32 | typedef u16 compat_mode_t; |
Will Deacon | 3dd681d | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 33 | typedef u32 compat_dev_t; |
Catalin Marinas | f15a2a1 | 2013-04-25 11:23:41 +0100 | [diff] [blame] | 34 | typedef s32 compat_nlink_t; |
Will Deacon | 3dd681d | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 35 | typedef u16 compat_ipc_pid_t; |
Will Deacon | 3dd681d | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 36 | typedef u32 compat_caddr_t; |
| 37 | typedef __kernel_fsid_t compat_fsid_t; |
Will Deacon | 3dd681d | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 38 | typedef s64 compat_s64; |
Will Deacon | 3dd681d | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 39 | typedef u64 compat_u64; |
| 40 | |
Will Deacon | 3dd681d | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 41 | struct compat_stat { |
Will Deacon | a795a38 | 2013-10-11 14:52:12 +0100 | [diff] [blame] | 42 | #ifdef __AARCH64EB__ |
| 43 | short st_dev; |
| 44 | short __pad1; |
| 45 | #else |
Will Deacon | 3dd681d | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 46 | compat_dev_t st_dev; |
Will Deacon | a795a38 | 2013-10-11 14:52:12 +0100 | [diff] [blame] | 47 | #endif |
Will Deacon | 3dd681d | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 48 | compat_ino_t st_ino; |
| 49 | compat_mode_t st_mode; |
Catalin Marinas | f15a2a1 | 2013-04-25 11:23:41 +0100 | [diff] [blame] | 50 | compat_ushort_t st_nlink; |
| 51 | __compat_uid16_t st_uid; |
| 52 | __compat_gid16_t st_gid; |
Will Deacon | a795a38 | 2013-10-11 14:52:12 +0100 | [diff] [blame] | 53 | #ifdef __AARCH64EB__ |
| 54 | short st_rdev; |
| 55 | short __pad2; |
| 56 | #else |
Will Deacon | 3dd681d | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 57 | compat_dev_t st_rdev; |
Will Deacon | a795a38 | 2013-10-11 14:52:12 +0100 | [diff] [blame] | 58 | #endif |
Will Deacon | 3dd681d | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 59 | compat_off_t st_size; |
| 60 | compat_off_t st_blksize; |
| 61 | compat_off_t st_blocks; |
Arnd Bergmann | 9afc5ee | 2018-07-13 12:52:28 +0200 | [diff] [blame] | 62 | old_time32_t st_atime; |
Catalin Marinas | f15a2a1 | 2013-04-25 11:23:41 +0100 | [diff] [blame] | 63 | compat_ulong_t st_atime_nsec; |
Arnd Bergmann | 9afc5ee | 2018-07-13 12:52:28 +0200 | [diff] [blame] | 64 | old_time32_t st_mtime; |
Catalin Marinas | f15a2a1 | 2013-04-25 11:23:41 +0100 | [diff] [blame] | 65 | compat_ulong_t st_mtime_nsec; |
Arnd Bergmann | 9afc5ee | 2018-07-13 12:52:28 +0200 | [diff] [blame] | 66 | old_time32_t st_ctime; |
Catalin Marinas | f15a2a1 | 2013-04-25 11:23:41 +0100 | [diff] [blame] | 67 | compat_ulong_t st_ctime_nsec; |
| 68 | compat_ulong_t __unused4[2]; |
Will Deacon | 3dd681d | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | struct compat_flock { |
| 72 | short l_type; |
| 73 | short l_whence; |
| 74 | compat_off_t l_start; |
| 75 | compat_off_t l_len; |
| 76 | compat_pid_t l_pid; |
| 77 | }; |
| 78 | |
| 79 | #define F_GETLK64 12 /* using 'struct flock64' */ |
| 80 | #define F_SETLK64 13 |
| 81 | #define F_SETLKW64 14 |
| 82 | |
| 83 | struct compat_flock64 { |
| 84 | short l_type; |
| 85 | short l_whence; |
| 86 | compat_loff_t l_start; |
| 87 | compat_loff_t l_len; |
| 88 | compat_pid_t l_pid; |
| 89 | }; |
| 90 | |
| 91 | struct compat_statfs { |
| 92 | int f_type; |
| 93 | int f_bsize; |
| 94 | int f_blocks; |
| 95 | int f_bfree; |
| 96 | int f_bavail; |
| 97 | int f_files; |
| 98 | int f_ffree; |
| 99 | compat_fsid_t f_fsid; |
| 100 | int f_namelen; /* SunOS ignores this field. */ |
| 101 | int f_frsize; |
| 102 | int f_flags; |
| 103 | int f_spare[4]; |
| 104 | }; |
| 105 | |
| 106 | #define COMPAT_RLIM_INFINITY 0xffffffff |
| 107 | |
| 108 | typedef u32 compat_old_sigset_t; |
| 109 | |
| 110 | #define _COMPAT_NSIG 64 |
| 111 | #define _COMPAT_NSIG_BPW 32 |
| 112 | |
| 113 | typedef u32 compat_sigset_word; |
| 114 | |
| 115 | #define COMPAT_OFF_T_MAX 0x7fffffff |
Will Deacon | 3dd681d | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 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 | */ |
Will Deacon | 3dd681d | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 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 | |
Arnd Bergmann | adc235a | 2015-11-16 17:32:15 +0100 | [diff] [blame] | 134 | #define compat_user_stack_pointer() (user_stack_pointer(task_pt_regs(current))) |
Will Deacon | 2495146 | 2018-09-05 15:34:43 +0100 | [diff] [blame] | 135 | #define COMPAT_MINSIGSTKSZ 2048 |
Al Viro | 9b064fc | 2012-12-14 13:49:35 -0500 | [diff] [blame] | 136 | |
Will Deacon | 3dd681d | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 137 | static inline void __user *arch_compat_alloc_user_space(long len) |
| 138 | { |
Al Viro | 9b064fc | 2012-12-14 13:49:35 -0500 | [diff] [blame] | 139 | return (void __user *)compat_user_stack_pointer() - len; |
Will Deacon | 3dd681d | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | struct compat_ipc64_perm { |
| 143 | compat_key_t key; |
| 144 | __compat_uid32_t uid; |
| 145 | __compat_gid32_t gid; |
| 146 | __compat_uid32_t cuid; |
| 147 | __compat_gid32_t cgid; |
| 148 | unsigned short mode; |
| 149 | unsigned short __pad1; |
| 150 | unsigned short seq; |
| 151 | unsigned short __pad2; |
| 152 | compat_ulong_t unused1; |
| 153 | compat_ulong_t unused2; |
| 154 | }; |
| 155 | |
| 156 | struct compat_semid64_ds { |
| 157 | struct compat_ipc64_perm sem_perm; |
Arnd Bergmann | 83335eb | 2018-04-12 12:34:16 +0200 | [diff] [blame] | 158 | compat_ulong_t sem_otime; |
| 159 | compat_ulong_t sem_otime_high; |
| 160 | compat_ulong_t sem_ctime; |
| 161 | compat_ulong_t sem_ctime_high; |
Will Deacon | 3dd681d | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 162 | compat_ulong_t sem_nsems; |
| 163 | compat_ulong_t __unused3; |
| 164 | compat_ulong_t __unused4; |
| 165 | }; |
| 166 | |
| 167 | struct compat_msqid64_ds { |
| 168 | struct compat_ipc64_perm msg_perm; |
Arnd Bergmann | 83335eb | 2018-04-12 12:34:16 +0200 | [diff] [blame] | 169 | compat_ulong_t msg_stime; |
| 170 | compat_ulong_t msg_stime_high; |
| 171 | compat_ulong_t msg_rtime; |
| 172 | compat_ulong_t msg_rtime_high; |
| 173 | compat_ulong_t msg_ctime; |
| 174 | compat_ulong_t msg_ctime_high; |
Will Deacon | 3dd681d | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 175 | compat_ulong_t msg_cbytes; |
| 176 | compat_ulong_t msg_qnum; |
| 177 | compat_ulong_t msg_qbytes; |
| 178 | compat_pid_t msg_lspid; |
| 179 | compat_pid_t msg_lrpid; |
| 180 | compat_ulong_t __unused4; |
| 181 | compat_ulong_t __unused5; |
| 182 | }; |
| 183 | |
| 184 | struct compat_shmid64_ds { |
| 185 | struct compat_ipc64_perm shm_perm; |
| 186 | compat_size_t shm_segsz; |
Arnd Bergmann | 83335eb | 2018-04-12 12:34:16 +0200 | [diff] [blame] | 187 | compat_ulong_t shm_atime; |
| 188 | compat_ulong_t shm_atime_high; |
| 189 | compat_ulong_t shm_dtime; |
| 190 | compat_ulong_t shm_dtime_high; |
| 191 | compat_ulong_t shm_ctime; |
| 192 | compat_ulong_t shm_ctime_high; |
Will Deacon | 3dd681d | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 193 | compat_pid_t shm_cpid; |
| 194 | compat_pid_t shm_lpid; |
| 195 | compat_ulong_t shm_nattch; |
| 196 | compat_ulong_t __unused4; |
| 197 | compat_ulong_t __unused5; |
| 198 | }; |
| 199 | |
| 200 | static inline int is_compat_task(void) |
| 201 | { |
| 202 | return test_thread_flag(TIF_32BIT); |
| 203 | } |
| 204 | |
| 205 | static inline int is_compat_thread(struct thread_info *thread) |
| 206 | { |
| 207 | return test_ti_thread_flag(thread, TIF_32BIT); |
| 208 | } |
| 209 | |
| 210 | #else /* !CONFIG_COMPAT */ |
| 211 | |
Will Deacon | 3dd681d | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 212 | static inline int is_compat_thread(struct thread_info *thread) |
| 213 | { |
| 214 | return 0; |
| 215 | } |
| 216 | |
| 217 | #endif /* CONFIG_COMPAT */ |
| 218 | #endif /* __KERNEL__ */ |
| 219 | #endif /* __ASM_COMPAT_H */ |