linux/arch/arm64/include/asm/compat.h
<<
>>
Prefs
   1/*
   2 * Copyright (C) 2012 ARM Ltd.
   3 *
   4 * This program is free software; you can redistribute it and/or modify
   5 * it under the terms of the GNU General Public License version 2 as
   6 * published by the Free Software Foundation.
   7 *
   8 * This program is distributed in the hope that it will be useful,
   9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11 * GNU General Public License for more details.
  12 *
  13 * You should have received a copy of the GNU General Public License
  14 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  15 */
  16#ifndef __ASM_COMPAT_H
  17#define __ASM_COMPAT_H
  18#ifdef __KERNEL__
  19#ifdef CONFIG_COMPAT
  20
  21/*
  22 * Architecture specific compatibility types
  23 */
  24#include <linux/types.h>
  25#include <linux/sched.h>
  26#include <linux/sched/task_stack.h>
  27
  28#define COMPAT_USER_HZ          100
  29#ifdef __AARCH64EB__
  30#define COMPAT_UTS_MACHINE      "armv8b\0\0"
  31#else
  32#define COMPAT_UTS_MACHINE      "armv8l\0\0"
  33#endif
  34
  35typedef u32             compat_size_t;
  36typedef s32             compat_ssize_t;
  37typedef s32             compat_clock_t;
  38typedef s32             compat_pid_t;
  39typedef u16             __compat_uid_t;
  40typedef u16             __compat_gid_t;
  41typedef u16             __compat_uid16_t;
  42typedef u16             __compat_gid16_t;
  43typedef u32             __compat_uid32_t;
  44typedef u32             __compat_gid32_t;
  45typedef u16             compat_mode_t;
  46typedef u32             compat_ino_t;
  47typedef u32             compat_dev_t;
  48typedef s32             compat_off_t;
  49typedef s64             compat_loff_t;
  50typedef s32             compat_nlink_t;
  51typedef u16             compat_ipc_pid_t;
  52typedef s32             compat_daddr_t;
  53typedef u32             compat_caddr_t;
  54typedef __kernel_fsid_t compat_fsid_t;
  55typedef s32             compat_key_t;
  56typedef s32             compat_timer_t;
  57
  58typedef s16             compat_short_t;
  59typedef s32             compat_int_t;
  60typedef s32             compat_long_t;
  61typedef s64             compat_s64;
  62typedef u16             compat_ushort_t;
  63typedef u32             compat_uint_t;
  64typedef u32             compat_ulong_t;
  65typedef u64             compat_u64;
  66typedef u32             compat_uptr_t;
  67
  68struct compat_stat {
  69#ifdef __AARCH64EB__
  70        short           st_dev;
  71        short           __pad1;
  72#else
  73        compat_dev_t    st_dev;
  74#endif
  75        compat_ino_t    st_ino;
  76        compat_mode_t   st_mode;
  77        compat_ushort_t st_nlink;
  78        __compat_uid16_t        st_uid;
  79        __compat_gid16_t        st_gid;
  80#ifdef __AARCH64EB__
  81        short           st_rdev;
  82        short           __pad2;
  83#else
  84        compat_dev_t    st_rdev;
  85#endif
  86        compat_off_t    st_size;
  87        compat_off_t    st_blksize;
  88        compat_off_t    st_blocks;
  89        compat_time_t   st_atime;
  90        compat_ulong_t  st_atime_nsec;
  91        compat_time_t   st_mtime;
  92        compat_ulong_t  st_mtime_nsec;
  93        compat_time_t   st_ctime;
  94        compat_ulong_t  st_ctime_nsec;
  95        compat_ulong_t  __unused4[2];
  96};
  97
  98struct compat_flock {
  99        short           l_type;
 100        short           l_whence;
 101        compat_off_t    l_start;
 102        compat_off_t    l_len;
 103        compat_pid_t    l_pid;
 104};
 105
 106#define F_GETLK64       12      /*  using 'struct flock64' */
 107#define F_SETLK64       13
 108#define F_SETLKW64      14
 109
 110struct compat_flock64 {
 111        short           l_type;
 112        short           l_whence;
 113        compat_loff_t   l_start;
 114        compat_loff_t   l_len;
 115        compat_pid_t    l_pid;
 116};
 117
 118struct compat_statfs {
 119        int             f_type;
 120        int             f_bsize;
 121        int             f_blocks;
 122        int             f_bfree;
 123        int             f_bavail;
 124        int             f_files;
 125        int             f_ffree;
 126        compat_fsid_t   f_fsid;
 127        int             f_namelen;      /* SunOS ignores this field. */
 128        int             f_frsize;
 129        int             f_flags;
 130        int             f_spare[4];
 131};
 132
 133#define COMPAT_RLIM_INFINITY            0xffffffff
 134
 135typedef u32             compat_old_sigset_t;
 136
 137#define _COMPAT_NSIG            64
 138#define _COMPAT_NSIG_BPW        32
 139
 140typedef u32             compat_sigset_word;
 141
 142#define COMPAT_OFF_T_MAX        0x7fffffff
 143
 144/*
 145 * A pointer passed in from user mode. This should not
 146 * be used for syscall parameters, just declare them
 147 * as pointers because the syscall entry code will have
 148 * appropriately converted them already.
 149 */
 150
 151static inline void __user *compat_ptr(compat_uptr_t uptr)
 152{
 153        return (void __user *)(unsigned long)uptr;
 154}
 155
 156static inline compat_uptr_t ptr_to_compat(void __user *uptr)
 157{
 158        return (u32)(unsigned long)uptr;
 159}
 160
 161#define compat_user_stack_pointer() (user_stack_pointer(task_pt_regs(current)))
 162
 163static inline void __user *arch_compat_alloc_user_space(long len)
 164{
 165        return (void __user *)compat_user_stack_pointer() - len;
 166}
 167
 168struct compat_ipc64_perm {
 169        compat_key_t key;
 170        __compat_uid32_t uid;
 171        __compat_gid32_t gid;
 172        __compat_uid32_t cuid;
 173        __compat_gid32_t cgid;
 174        unsigned short mode;
 175        unsigned short __pad1;
 176        unsigned short seq;
 177        unsigned short __pad2;
 178        compat_ulong_t unused1;
 179        compat_ulong_t unused2;
 180};
 181
 182struct compat_semid64_ds {
 183        struct compat_ipc64_perm sem_perm;
 184        compat_ulong_t sem_otime;
 185        compat_ulong_t sem_otime_high;
 186        compat_ulong_t sem_ctime;
 187        compat_ulong_t sem_ctime_high;
 188        compat_ulong_t sem_nsems;
 189        compat_ulong_t __unused3;
 190        compat_ulong_t __unused4;
 191};
 192
 193struct compat_msqid64_ds {
 194        struct compat_ipc64_perm msg_perm;
 195        compat_ulong_t msg_stime;
 196        compat_ulong_t msg_stime_high;
 197        compat_ulong_t msg_rtime;
 198        compat_ulong_t msg_rtime_high;
 199        compat_ulong_t msg_ctime;
 200        compat_ulong_t msg_ctime_high;
 201        compat_ulong_t msg_cbytes;
 202        compat_ulong_t msg_qnum;
 203        compat_ulong_t msg_qbytes;
 204        compat_pid_t   msg_lspid;
 205        compat_pid_t   msg_lrpid;
 206        compat_ulong_t __unused4;
 207        compat_ulong_t __unused5;
 208};
 209
 210struct compat_shmid64_ds {
 211        struct compat_ipc64_perm shm_perm;
 212        compat_size_t  shm_segsz;
 213        compat_ulong_t shm_atime;
 214        compat_ulong_t shm_atime_high;
 215        compat_ulong_t shm_dtime;
 216        compat_ulong_t shm_dtime_high;
 217        compat_ulong_t shm_ctime;
 218        compat_ulong_t shm_ctime_high;
 219        compat_pid_t   shm_cpid;
 220        compat_pid_t   shm_lpid;
 221        compat_ulong_t shm_nattch;
 222        compat_ulong_t __unused4;
 223        compat_ulong_t __unused5;
 224};
 225
 226static inline int is_compat_task(void)
 227{
 228        return test_thread_flag(TIF_32BIT);
 229}
 230
 231static inline int is_compat_thread(struct thread_info *thread)
 232{
 233        return test_ti_thread_flag(thread, TIF_32BIT);
 234}
 235
 236#else /* !CONFIG_COMPAT */
 237
 238static inline int is_compat_thread(struct thread_info *thread)
 239{
 240        return 0;
 241}
 242
 243#endif /* CONFIG_COMPAT */
 244#endif /* __KERNEL__ */
 245#endif /* __ASM_COMPAT_H */
 246