~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/compat.h

Version: ~ [ linux-5.14-rc3 ] ~ [ linux-5.13.5 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.53 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.135 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.198 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.240 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.276 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.276 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 #ifndef _LINUX_COMPAT_H
  3 #define _LINUX_COMPAT_H
  4 /*
  5  * These are the type definitions for the architecture specific
  6  * syscall compatibility layer.
  7  */
  8 
  9 #include <linux/types.h>
 10 
 11 #ifdef CONFIG_COMPAT
 12 
 13 #include <linux/stat.h>
 14 #include <linux/param.h>        /* for HZ */
 15 #include <linux/sem.h>
 16 #include <linux/socket.h>
 17 #include <linux/if.h>
 18 #include <linux/fs.h>
 19 #include <linux/aio_abi.h>      /* for aio_context_t */
 20 #include <linux/uaccess.h>
 21 #include <linux/unistd.h>
 22 
 23 #include <asm/compat.h>
 24 #include <asm/siginfo.h>
 25 #include <asm/signal.h>
 26 
 27 #ifndef COMPAT_USE_64BIT_TIME
 28 #define COMPAT_USE_64BIT_TIME 0
 29 #endif
 30 
 31 #ifndef __SC_DELOUSE
 32 #define __SC_DELOUSE(t,v) ((__force t)(unsigned long)(v))
 33 #endif
 34 
 35 #define COMPAT_SYSCALL_DEFINE0(name) \
 36         asmlinkage long compat_sys_##name(void)
 37 
 38 #define COMPAT_SYSCALL_DEFINE1(name, ...) \
 39         COMPAT_SYSCALL_DEFINEx(1, _##name, __VA_ARGS__)
 40 #define COMPAT_SYSCALL_DEFINE2(name, ...) \
 41         COMPAT_SYSCALL_DEFINEx(2, _##name, __VA_ARGS__)
 42 #define COMPAT_SYSCALL_DEFINE3(name, ...) \
 43         COMPAT_SYSCALL_DEFINEx(3, _##name, __VA_ARGS__)
 44 #define COMPAT_SYSCALL_DEFINE4(name, ...) \
 45         COMPAT_SYSCALL_DEFINEx(4, _##name, __VA_ARGS__)
 46 #define COMPAT_SYSCALL_DEFINE5(name, ...) \
 47         COMPAT_SYSCALL_DEFINEx(5, _##name, __VA_ARGS__)
 48 #define COMPAT_SYSCALL_DEFINE6(name, ...) \
 49         COMPAT_SYSCALL_DEFINEx(6, _##name, __VA_ARGS__)
 50 
 51 #define COMPAT_SYSCALL_DEFINEx(x, name, ...)                            \
 52         asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))\
 53                 __attribute__((alias(__stringify(compat_SyS##name))));  \
 54         static inline long C_SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__));\
 55         asmlinkage long compat_SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__));\
 56         asmlinkage long compat_SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__))\
 57         {                                                               \
 58                 return C_SYSC##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__)); \
 59         }                                                               \
 60         static inline long C_SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__))
 61 
 62 #ifndef compat_user_stack_pointer
 63 #define compat_user_stack_pointer() current_user_stack_pointer()
 64 #endif
 65 #ifndef compat_sigaltstack      /* we'll need that for MIPS */
 66 typedef struct compat_sigaltstack {
 67         compat_uptr_t                   ss_sp;
 68         int                             ss_flags;
 69         compat_size_t                   ss_size;
 70 } compat_stack_t;
 71 #endif
 72 
 73 #define compat_jiffies_to_clock_t(x)    \
 74                 (((unsigned long)(x) * COMPAT_USER_HZ) / HZ)
 75 
 76 typedef __compat_uid32_t        compat_uid_t;
 77 typedef __compat_gid32_t        compat_gid_t;
 78 
 79 typedef compat_ulong_t          compat_aio_context_t;
 80 
 81 struct compat_sel_arg_struct;
 82 struct rusage;
 83 
 84 struct compat_itimerspec {
 85         struct compat_timespec it_interval;
 86         struct compat_timespec it_value;
 87 };
 88 
 89 struct compat_utimbuf {
 90         compat_time_t           actime;
 91         compat_time_t           modtime;
 92 };
 93 
 94 struct compat_itimerval {
 95         struct compat_timeval   it_interval;
 96         struct compat_timeval   it_value;
 97 };
 98 
 99 struct itimerval;
100 int get_compat_itimerval(struct itimerval *, const struct compat_itimerval __user *);
101 int put_compat_itimerval(struct compat_itimerval __user *, const struct itimerval *);
102 
103 struct compat_tms {
104         compat_clock_t          tms_utime;
105         compat_clock_t          tms_stime;
106         compat_clock_t          tms_cutime;
107         compat_clock_t          tms_cstime;
108 };
109 
110 struct compat_timex {
111         compat_uint_t modes;
112         compat_long_t offset;
113         compat_long_t freq;
114         compat_long_t maxerror;
115         compat_long_t esterror;
116         compat_int_t status;
117         compat_long_t constant;
118         compat_long_t precision;
119         compat_long_t tolerance;
120         struct compat_timeval time;
121         compat_long_t tick;
122         compat_long_t ppsfreq;
123         compat_long_t jitter;
124         compat_int_t shift;
125         compat_long_t stabil;
126         compat_long_t jitcnt;
127         compat_long_t calcnt;
128         compat_long_t errcnt;
129         compat_long_t stbcnt;
130         compat_int_t tai;
131 
132         compat_int_t:32; compat_int_t:32; compat_int_t:32; compat_int_t:32;
133         compat_int_t:32; compat_int_t:32; compat_int_t:32; compat_int_t:32;
134         compat_int_t:32; compat_int_t:32; compat_int_t:32;
135 };
136 
137 struct timex;
138 int compat_get_timex(struct timex *, const struct compat_timex __user *);
139 int compat_put_timex(struct compat_timex __user *, const struct timex *);
140 
141 #define _COMPAT_NSIG_WORDS      (_COMPAT_NSIG / _COMPAT_NSIG_BPW)
142 
143 typedef struct {
144         compat_sigset_word      sig[_COMPAT_NSIG_WORDS];
145 } compat_sigset_t;
146 
147 struct compat_sigaction {
148 #ifndef __ARCH_HAS_IRIX_SIGACTION
149         compat_uptr_t                   sa_handler;
150         compat_ulong_t                  sa_flags;
151 #else
152         compat_uint_t                   sa_flags;
153         compat_uptr_t                   sa_handler;
154 #endif
155 #ifdef __ARCH_HAS_SA_RESTORER
156         compat_uptr_t                   sa_restorer;
157 #endif
158         compat_sigset_t                 sa_mask __packed;
159 };
160 
161 typedef union compat_sigval {
162         compat_int_t    sival_int;
163         compat_uptr_t   sival_ptr;
164 } compat_sigval_t;
165 
166 typedef struct compat_siginfo {
167         int si_signo;
168 #ifndef __ARCH_HAS_SWAPPED_SIGINFO
169         int si_errno;
170         int si_code;
171 #else
172         int si_code;
173         int si_errno;
174 #endif
175 
176         union {
177                 int _pad[128/sizeof(int) - 3];
178 
179                 /* kill() */
180                 struct {
181                         compat_pid_t _pid;      /* sender's pid */
182                         __compat_uid32_t _uid;  /* sender's uid */
183                 } _kill;
184 
185                 /* POSIX.1b timers */
186                 struct {
187                         compat_timer_t _tid;    /* timer id */
188                         int _overrun;           /* overrun count */
189                         compat_sigval_t _sigval;        /* same as below */
190                 } _timer;
191 
192                 /* POSIX.1b signals */
193                 struct {
194                         compat_pid_t _pid;      /* sender's pid */
195                         __compat_uid32_t _uid;  /* sender's uid */
196                         compat_sigval_t _sigval;
197                 } _rt;
198 
199                 /* SIGCHLD */
200                 struct {
201                         compat_pid_t _pid;      /* which child */
202                         __compat_uid32_t _uid;  /* sender's uid */
203                         int _status;            /* exit code */
204                         compat_clock_t _utime;
205                         compat_clock_t _stime;
206                 } _sigchld;
207 
208 #ifdef CONFIG_X86_X32_ABI
209                 /* SIGCHLD (x32 version) */
210                 struct {
211                         compat_pid_t _pid;      /* which child */
212                         __compat_uid32_t _uid;  /* sender's uid */
213                         int _status;            /* exit code */
214                         compat_s64 _utime;
215                         compat_s64 _stime;
216                 } _sigchld_x32;
217 #endif
218 
219                 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */
220                 struct {
221                         compat_uptr_t _addr;    /* faulting insn/memory ref. */
222 #ifdef __ARCH_SI_TRAPNO
223                         int _trapno;    /* TRAP # which caused the signal */
224 #endif
225 #define __COMPAT_ADDR_BND_PKEY_PAD  (__alignof__(compat_uptr_t) < sizeof(short) ? \
226                                      sizeof(short) : __alignof__(compat_uptr_t))
227                         union {
228                                 /*
229                                  * used when si_code=BUS_MCEERR_AR or
230                                  * used when si_code=BUS_MCEERR_AO
231                                  */
232                                 short int _addr_lsb;    /* Valid LSB of the reported address. */
233                                 /* used when si_code=SEGV_BNDERR */
234                                 struct {
235                                         char _dummy_bnd[__COMPAT_ADDR_BND_PKEY_PAD];
236                                         compat_uptr_t _lower;
237                                         compat_uptr_t _upper;
238                                 } _addr_bnd;
239                                 /* used when si_code=SEGV_PKUERR */
240                                 struct {
241                                         char _dummy_pkey[__COMPAT_ADDR_BND_PKEY_PAD];
242                                         u32 _pkey;
243                                 } _addr_pkey;
244                         };
245                 } _sigfault;
246 
247                 /* SIGPOLL */
248                 struct {
249                         compat_long_t _band;    /* POLL_IN, POLL_OUT, POLL_MSG */
250                         int _fd;
251                 } _sigpoll;
252 
253                 struct {
254                         compat_uptr_t _call_addr; /* calling user insn */
255                         int _syscall;   /* triggering system call number */
256                         unsigned int _arch;     /* AUDIT_ARCH_* of syscall */
257                 } _sigsys;
258         } _sifields;
259 } compat_siginfo_t;
260 
261 /*
262  * These functions operate on 32- or 64-bit specs depending on
263  * COMPAT_USE_64BIT_TIME, hence the void user pointer arguments.
264  */
265 extern int compat_get_timespec(struct timespec *, const void __user *);
266 extern int compat_put_timespec(const struct timespec *, void __user *);
267 extern int compat_get_timeval(struct timeval *, const void __user *);
268 extern int compat_put_timeval(const struct timeval *, void __user *);
269 extern int compat_get_timespec64(struct timespec64 *, const void __user *);
270 extern int compat_put_timespec64(const struct timespec64 *, void __user *);
271 extern int get_compat_itimerspec64(struct itimerspec64 *its,
272                         const struct compat_itimerspec __user *uits);
273 extern int put_compat_itimerspec64(const struct itimerspec64 *its,
274                         struct compat_itimerspec __user *uits);
275 
276 struct compat_iovec {
277         compat_uptr_t   iov_base;
278         compat_size_t   iov_len;
279 };
280 
281 struct compat_rlimit {
282         compat_ulong_t  rlim_cur;
283         compat_ulong_t  rlim_max;
284 };
285 
286 struct compat_rusage {
287         struct compat_timeval ru_utime;
288         struct compat_timeval ru_stime;
289         compat_long_t   ru_maxrss;
290         compat_long_t   ru_ixrss;
291         compat_long_t   ru_idrss;
292         compat_long_t   ru_isrss;
293         compat_long_t   ru_minflt;
294         compat_long_t   ru_majflt;
295         compat_long_t   ru_nswap;
296         compat_long_t   ru_inblock;
297         compat_long_t   ru_oublock;
298         compat_long_t   ru_msgsnd;
299         compat_long_t   ru_msgrcv;
300         compat_long_t   ru_nsignals;
301         compat_long_t   ru_nvcsw;
302         compat_long_t   ru_nivcsw;
303 };
304 
305 extern int put_compat_rusage(const struct rusage *,
306                              struct compat_rusage __user *);
307 
308 struct compat_siginfo;
309 
310 extern asmlinkage long compat_sys_waitid(int, compat_pid_t,
311                 struct compat_siginfo __user *, int,
312                 struct compat_rusage __user *);
313 
314 struct compat_dirent {
315         u32             d_ino;
316         compat_off_t    d_off;
317         u16             d_reclen;
318         char            d_name[256];
319 };
320 
321 struct compat_ustat {
322         compat_daddr_t          f_tfree;
323         compat_ino_t            f_tinode;
324         char                    f_fname[6];
325         char                    f_fpack[6];
326 };
327 
328 #define COMPAT_SIGEV_PAD_SIZE   ((SIGEV_MAX_SIZE/sizeof(int)) - 3)
329 
330 typedef struct compat_sigevent {
331         compat_sigval_t sigev_value;
332         compat_int_t sigev_signo;
333         compat_int_t sigev_notify;
334         union {
335                 compat_int_t _pad[COMPAT_SIGEV_PAD_SIZE];
336                 compat_int_t _tid;
337 
338                 struct {
339                         compat_uptr_t _function;
340                         compat_uptr_t _attribute;
341                 } _sigev_thread;
342         } _sigev_un;
343 } compat_sigevent_t;
344 
345 struct compat_ifmap {
346         compat_ulong_t mem_start;
347         compat_ulong_t mem_end;
348         unsigned short base_addr;
349         unsigned char irq;
350         unsigned char dma;
351         unsigned char port;
352 };
353 
354 struct compat_if_settings {
355         unsigned int type;      /* Type of physical device or protocol */
356         unsigned int size;      /* Size of the data allocated by the caller */
357         compat_uptr_t ifs_ifsu; /* union of pointers */
358 };
359 
360 struct compat_ifreq {
361         union {
362                 char    ifrn_name[IFNAMSIZ];    /* if name, e.g. "en0" */
363         } ifr_ifrn;
364         union {
365                 struct  sockaddr ifru_addr;
366                 struct  sockaddr ifru_dstaddr;
367                 struct  sockaddr ifru_broadaddr;
368                 struct  sockaddr ifru_netmask;
369                 struct  sockaddr ifru_hwaddr;
370                 short   ifru_flags;
371                 compat_int_t    ifru_ivalue;
372                 compat_int_t    ifru_mtu;
373                 struct  compat_ifmap ifru_map;
374                 char    ifru_slave[IFNAMSIZ];   /* Just fits the size */
375                 char    ifru_newname[IFNAMSIZ];
376                 compat_caddr_t  ifru_data;
377                 struct  compat_if_settings ifru_settings;
378         } ifr_ifru;
379 };
380 
381 struct compat_ifconf {
382         compat_int_t    ifc_len;                /* size of buffer */
383         compat_caddr_t  ifcbuf;
384 };
385 
386 struct compat_robust_list {
387         compat_uptr_t                   next;
388 };
389 
390 struct compat_robust_list_head {
391         struct compat_robust_list       list;
392         compat_long_t                   futex_offset;
393         compat_uptr_t                   list_op_pending;
394 };
395 
396 #ifdef CONFIG_COMPAT_OLD_SIGACTION
397 struct compat_old_sigaction {
398         compat_uptr_t                   sa_handler;
399         compat_old_sigset_t             sa_mask;
400         compat_ulong_t                  sa_flags;
401         compat_uptr_t                   sa_restorer;
402 };
403 #endif
404 
405 struct compat_keyctl_kdf_params {
406         compat_uptr_t hashname;
407         compat_uptr_t otherinfo;
408         __u32 otherinfolen;
409         __u32 __spare[8];
410 };
411 
412 struct compat_statfs;
413 struct compat_statfs64;
414 struct compat_old_linux_dirent;
415 struct compat_linux_dirent;
416 struct linux_dirent64;
417 struct compat_msghdr;
418 struct compat_mmsghdr;
419 struct compat_sysinfo;
420 struct compat_sysctl_args;
421 struct compat_kexec_segment;
422 struct compat_mq_attr;
423 struct compat_msgbuf;
424 
425 extern void compat_exit_robust_list(struct task_struct *curr);
426 
427 asmlinkage long
428 compat_sys_set_robust_list(struct compat_robust_list_head __user *head,
429                            compat_size_t len);
430 asmlinkage long
431 compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
432                            compat_size_t __user *len_ptr);
433 
434 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
435 asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
436 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
437 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
438                 compat_ssize_t msgsz, int msgflg);
439 asmlinkage long compat_sys_msgrcv(int msqid, compat_uptr_t msgp,
440                 compat_ssize_t msgsz, compat_long_t msgtyp, int msgflg);
441 long compat_sys_msgctl(int first, int second, void __user *uptr);
442 long compat_sys_shmctl(int first, int second, void __user *uptr);
443 long compat_sys_semtimedop(int semid, struct sembuf __user *tsems,
444                 unsigned nsems, const struct compat_timespec __user *timeout);
445 asmlinkage long compat_sys_keyctl(u32 option,
446                               u32 arg2, u32 arg3, u32 arg4, u32 arg5);
447 asmlinkage long compat_sys_ustat(unsigned dev, struct compat_ustat __user *u32);
448 
449 asmlinkage ssize_t compat_sys_readv(compat_ulong_t fd,
450                 const struct compat_iovec __user *vec, compat_ulong_t vlen);
451 asmlinkage ssize_t compat_sys_writev(compat_ulong_t fd,
452                 const struct compat_iovec __user *vec, compat_ulong_t vlen);
453 asmlinkage ssize_t compat_sys_preadv(compat_ulong_t fd,
454                 const struct compat_iovec __user *vec,
455                 compat_ulong_t vlen, u32 pos_low, u32 pos_high);
456 asmlinkage ssize_t compat_sys_pwritev(compat_ulong_t fd,
457                 const struct compat_iovec __user *vec,
458                 compat_ulong_t vlen, u32 pos_low, u32 pos_high);
459 asmlinkage ssize_t compat_sys_preadv2(compat_ulong_t fd,
460                 const struct compat_iovec __user *vec,
461                 compat_ulong_t vlen, u32 pos_low, u32 pos_high, rwf_t flags);
462 asmlinkage ssize_t compat_sys_pwritev2(compat_ulong_t fd,
463                 const struct compat_iovec __user *vec,
464                 compat_ulong_t vlen, u32 pos_low, u32 pos_high, rwf_t flags);
465 
466 #ifdef __ARCH_WANT_COMPAT_SYS_PREADV64
467 asmlinkage long compat_sys_preadv64(unsigned long fd,
468                 const struct compat_iovec __user *vec,
469                 unsigned long vlen, loff_t pos);
470 #endif
471 
472 #ifdef __ARCH_WANT_COMPAT_SYS_PWRITEV64
473 asmlinkage long compat_sys_pwritev64(unsigned long fd,
474                 const struct compat_iovec __user *vec,
475                 unsigned long vlen, loff_t pos);
476 #endif
477 
478 #ifdef __ARCH_WANT_COMPAT_SYS_PREADV64V2
479 asmlinkage long  compat_sys_readv64v2(unsigned long fd,
480                 const struct compat_iovec __user *vec,
481                 unsigned long vlen, loff_t pos, rwf_t flags);
482 #endif
483 
484 #ifdef __ARCH_WANT_COMPAT_SYS_PWRITEV64V2
485 asmlinkage long compat_sys_pwritev64v2(unsigned long fd,
486                 const struct compat_iovec __user *vec,
487                 unsigned long vlen, loff_t pos, rwf_t flags);
488 #endif
489 
490 asmlinkage long compat_sys_lseek(unsigned int, compat_off_t, unsigned int);
491 
492 asmlinkage long compat_sys_execve(const char __user *filename, const compat_uptr_t __user *argv,
493                      const compat_uptr_t __user *envp);
494 asmlinkage long compat_sys_execveat(int dfd, const char __user *filename,
495                      const compat_uptr_t __user *argv,
496                      const compat_uptr_t __user *envp, int flags);
497 
498 asmlinkage long compat_sys_select(int n, compat_ulong_t __user *inp,
499                 compat_ulong_t __user *outp, compat_ulong_t __user *exp,
500                 struct compat_timeval __user *tvp);
501 
502 asmlinkage long compat_sys_old_select(struct compat_sel_arg_struct __user *arg);
503 
504 asmlinkage long compat_sys_wait4(compat_pid_t pid,
505                                  compat_uint_t __user *stat_addr, int options,
506                                  struct compat_rusage __user *ru);
507 
508 #define BITS_PER_COMPAT_LONG    (8*sizeof(compat_long_t))
509 
510 #define BITS_TO_COMPAT_LONGS(bits) DIV_ROUND_UP(bits, BITS_PER_COMPAT_LONG)
511 
512 long compat_get_bitmap(unsigned long *mask, const compat_ulong_t __user *umask,
513                        unsigned long bitmap_size);
514 long compat_put_bitmap(compat_ulong_t __user *umask, unsigned long *mask,
515                        unsigned long bitmap_size);
516 int copy_siginfo_from_user32(siginfo_t *to, const struct compat_siginfo __user *from);
517 int copy_siginfo_to_user32(struct compat_siginfo __user *to, const siginfo_t *from);
518 int get_compat_sigevent(struct sigevent *event,
519                 const struct compat_sigevent __user *u_event);
520 long compat_sys_rt_tgsigqueueinfo(compat_pid_t tgid, compat_pid_t pid, int sig,
521                                   struct compat_siginfo __user *uinfo);
522 #ifdef CONFIG_COMPAT_OLD_SIGACTION
523 asmlinkage long compat_sys_sigaction(int sig,
524                                    const struct compat_old_sigaction __user *act,
525                                    struct compat_old_sigaction __user *oact);
526 #endif
527 
528 static inline int compat_timeval_compare(struct compat_timeval *lhs,
529                                         struct compat_timeval *rhs)
530 {
531         if (lhs->tv_sec < rhs->tv_sec)
532                 return -1;
533         if (lhs->tv_sec > rhs->tv_sec)
534                 return 1;
535         return lhs->tv_usec - rhs->tv_usec;
536 }
537 
538 static inline int compat_timespec_compare(struct compat_timespec *lhs,
539                                         struct compat_timespec *rhs)
540 {
541         if (lhs->tv_sec < rhs->tv_sec)
542                 return -1;
543         if (lhs->tv_sec > rhs->tv_sec)
544                 return 1;
545         return lhs->tv_nsec - rhs->tv_nsec;
546 }
547 
548 asmlinkage long compat_sys_gettimeofday(struct compat_timeval __user *tv,
549                 struct timezone __user *tz);
550 asmlinkage long compat_sys_settimeofday(struct compat_timeval __user *tv,
551                 struct timezone __user *tz);
552 
553 asmlinkage long compat_sys_adjtimex(struct compat_timex __user *utp);
554 
555 extern int get_compat_sigset(sigset_t *set, const compat_sigset_t __user *compat);
556 
557 /*
558  * Defined inline such that size can be compile time constant, which avoids
559  * CONFIG_HARDENED_USERCOPY complaining about copies from task_struct
560  */
561 static inline int
562 put_compat_sigset(compat_sigset_t __user *compat, const sigset_t *set,
563                   unsigned int size)
564 {
565         /* size <= sizeof(compat_sigset_t) <= sizeof(sigset_t) */
566 #ifdef __BIG_ENDIAN
567         compat_sigset_t v;
568         switch (_NSIG_WORDS) {
569         case 4: v.sig[7] = (set->sig[3] >> 32); v.sig[6] = set->sig[3];
570         case 3: v.sig[5] = (set->sig[2] >> 32); v.sig[4] = set->sig[2];
571         case 2: v.sig[3] = (set->sig[1] >> 32); v.sig[2] = set->sig[1];
572         case 1: v.sig[1] = (set->sig[0] >> 32); v.sig[0] = set->sig[0];
573         }
574         return copy_to_user(compat, &v, size) ? -EFAULT : 0;
575 #else
576         return copy_to_user(compat, set, size) ? -EFAULT : 0;
577 #endif
578 }
579 
580 asmlinkage long compat_sys_migrate_pages(compat_pid_t pid,
581                 compat_ulong_t maxnode, const compat_ulong_t __user *old_nodes,
582                 const compat_ulong_t __user *new_nodes);
583 
584 extern int compat_ptrace_request(struct task_struct *child,
585                                  compat_long_t request,
586                                  compat_ulong_t addr, compat_ulong_t data);
587 
588 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
589                                compat_ulong_t addr, compat_ulong_t data);
590 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
591                                   compat_long_t addr, compat_long_t data);
592 
593 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
594 /*
595  * epoll (fs/eventpoll.c) compat bits follow ...
596  */
597 struct epoll_event;     /* fortunately, this one is fixed-layout */
598 asmlinkage long compat_sys_epoll_pwait(int epfd,
599                         struct epoll_event __user *events,
600                         int maxevents, int timeout,
601                         const compat_sigset_t __user *sigmask,
602                         compat_size_t sigsetsize);
603 
604 asmlinkage long compat_sys_utime(const char __user *filename,
605                                  struct compat_utimbuf __user *t);
606 asmlinkage long compat_sys_utimensat(unsigned int dfd,
607                                      const char __user *filename,
608                                      struct compat_timespec __user *t,
609                                      int flags);
610 
611 asmlinkage long compat_sys_time(compat_time_t __user *tloc);
612 asmlinkage long compat_sys_stime(compat_time_t __user *tptr);
613 asmlinkage long compat_sys_signalfd(int ufd,
614                                     const compat_sigset_t __user *sigmask,
615                                     compat_size_t sigsetsize);
616 asmlinkage long compat_sys_timerfd_settime(int ufd, int flags,
617                                    const struct compat_itimerspec __user *utmr,
618                                    struct compat_itimerspec __user *otmr);
619 asmlinkage long compat_sys_timerfd_gettime(int ufd,
620                                    struct compat_itimerspec __user *otmr);
621 
622 asmlinkage long compat_sys_move_pages(pid_t pid, compat_ulong_t nr_pages,
623                                       __u32 __user *pages,
624                                       const int __user *nodes,
625                                       int __user *status,
626                                       int flags);
627 asmlinkage long compat_sys_futimesat(unsigned int dfd,
628                                      const char __user *filename,
629                                      struct compat_timeval __user *t);
630 asmlinkage long compat_sys_utimes(const char __user *filename,
631                                   struct compat_timeval __user *t);
632 asmlinkage long compat_sys_newstat(const char __user *filename,
633                                    struct compat_stat __user *statbuf);
634 asmlinkage long compat_sys_newlstat(const char __user *filename,
635                                     struct compat_stat __user *statbuf);
636 asmlinkage long compat_sys_newfstatat(unsigned int dfd,
637                                       const char __user *filename,
638                                       struct compat_stat __user *statbuf,
639                                       int flag);
640 asmlinkage long compat_sys_newfstat(unsigned int fd,
641                                     struct compat_stat __user *statbuf);
642 asmlinkage long compat_sys_statfs(const char __user *pathname,
643                                   struct compat_statfs __user *buf);
644 asmlinkage long compat_sys_fstatfs(unsigned int fd,
645                                    struct compat_statfs __user *buf);
646 asmlinkage long compat_sys_statfs64(const char __user *pathname,
647                                     compat_size_t sz,
648                                     struct compat_statfs64 __user *buf);
649 asmlinkage long compat_sys_fstatfs64(unsigned int fd, compat_size_t sz,
650                                      struct compat_statfs64 __user *buf);
651 asmlinkage long compat_sys_fcntl64(unsigned int fd, unsigned int cmd,
652                                    compat_ulong_t arg);
653 asmlinkage long compat_sys_fcntl(unsigned int fd, unsigned int cmd,
654                                  compat_ulong_t arg);
655 asmlinkage long compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p);
656 asmlinkage long compat_sys_io_getevents(compat_aio_context_t ctx_id,
657                                         compat_long_t min_nr,
658                                         compat_long_t nr,
659                                         struct io_event __user *events,
660                                         struct compat_timespec __user *timeout);
661 asmlinkage long compat_sys_io_submit(compat_aio_context_t ctx_id, int nr,
662                                      u32 __user *iocb);
663 asmlinkage long compat_sys_mount(const char __user *dev_name,
664                                  const char __user *dir_name,
665                                  const char __user *type, compat_ulong_t flags,
666                                  const void __user *data);
667 asmlinkage long compat_sys_old_readdir(unsigned int fd,
668                                        struct compat_old_linux_dirent __user *,
669                                        unsigned int count);
670 asmlinkage long compat_sys_getdents(unsigned int fd,
671                                     struct compat_linux_dirent __user *dirent,
672                                     unsigned int count);
673 asmlinkage long compat_sys_vmsplice(int fd, const struct compat_iovec __user *,
674                                     unsigned int nr_segs, unsigned int flags);
675 asmlinkage long compat_sys_open(const char __user *filename, int flags,
676                                 umode_t mode);
677 asmlinkage long compat_sys_openat(int dfd, const char __user *filename,
678                                   int flags, umode_t mode);
679 asmlinkage long compat_sys_open_by_handle_at(int mountdirfd,
680                                              struct file_handle __user *handle,
681                                              int flags);
682 asmlinkage long compat_sys_truncate(const char __user *, compat_off_t);
683 asmlinkage long compat_sys_ftruncate(unsigned int, compat_ulong_t);
684 asmlinkage long compat_sys_pselect6(int n, compat_ulong_t __user *inp,
685                                     compat_ulong_t __user *outp,
686                                     compat_ulong_t __user *exp,
687                                     struct compat_timespec __user *tsp,
688                                     void __user *sig);
689 asmlinkage long compat_sys_ppoll(struct pollfd __user *ufds,
690                                  unsigned int nfds,
691                                  struct compat_timespec __user *tsp,
692                                  const compat_sigset_t __user *sigmask,
693                                  compat_size_t sigsetsize);
694 asmlinkage long compat_sys_signalfd4(int ufd,
695                                      const compat_sigset_t __user *sigmask,
696                                      compat_size_t sigsetsize, int flags);
697 asmlinkage long compat_sys_get_mempolicy(int __user *policy,
698                                          compat_ulong_t __user *nmask,
699                                          compat_ulong_t maxnode,
700                                          compat_ulong_t addr,
701                                          compat_ulong_t flags);
702 asmlinkage long compat_sys_set_mempolicy(int mode, compat_ulong_t __user *nmask,
703                                          compat_ulong_t maxnode);
704 asmlinkage long compat_sys_mbind(compat_ulong_t start, compat_ulong_t len,
705                                  compat_ulong_t mode,
706                                  compat_ulong_t __user *nmask,
707                                  compat_ulong_t maxnode, compat_ulong_t flags);
708 
709 asmlinkage long compat_sys_setsockopt(int fd, int level, int optname,
710                                       char __user *optval, unsigned int optlen);
711 asmlinkage long compat_sys_sendmsg(int fd, struct compat_msghdr __user *msg,
712                                    unsigned flags);
713 asmlinkage long compat_sys_sendmmsg(int fd, struct compat_mmsghdr __user *mmsg,
714                                     unsigned vlen, unsigned int flags);
715 asmlinkage long compat_sys_recvmsg(int fd, struct compat_msghdr __user *msg,
716                                    unsigned int flags);
717 asmlinkage long compat_sys_recv(int fd, void __user *buf, compat_size_t len,
718                                 unsigned flags);
719 asmlinkage long compat_sys_recvfrom(int fd, void __user *buf, compat_size_t len,
720                             unsigned flags, struct sockaddr __user *addr,
721                             int __user *addrlen);
722 asmlinkage long compat_sys_recvmmsg(int fd, struct compat_mmsghdr __user *mmsg,
723                                     unsigned vlen, unsigned int flags,
724                                     struct compat_timespec __user *timeout);
725 asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
726                                      struct compat_timespec __user *rmtp);
727 asmlinkage long compat_sys_getitimer(int which,
728                                      struct compat_itimerval __user *it);
729 asmlinkage long compat_sys_setitimer(int which,
730                                      struct compat_itimerval __user *in,
731                                      struct compat_itimerval __user *out);
732 asmlinkage long compat_sys_times(struct compat_tms __user *tbuf);
733 asmlinkage long compat_sys_setrlimit(unsigned int resource,
734                                      struct compat_rlimit __user *rlim);
735 asmlinkage long compat_sys_getrlimit(unsigned int resource,
736                                      struct compat_rlimit __user *rlim);
737 asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru);
738 asmlinkage long compat_sys_sched_setaffinity(compat_pid_t pid,
739                                      unsigned int len,
740                                      compat_ulong_t __user *user_mask_ptr);
741 asmlinkage long compat_sys_sched_getaffinity(compat_pid_t pid,
742                                      unsigned int len,
743                                      compat_ulong_t __user *user_mask_ptr);
744 asmlinkage long compat_sys_timer_create(clockid_t which_clock,
745                         struct compat_sigevent __user *timer_event_spec,
746                         timer_t __user *created_timer_id);
747 asmlinkage long compat_sys_timer_settime(timer_t timer_id, int flags,
748                                          struct compat_itimerspec __user *new,
749                                          struct compat_itimerspec __user *old);
750 asmlinkage long compat_sys_timer_gettime(timer_t timer_id,
751                                  struct compat_itimerspec __user *setting);
752 asmlinkage long compat_sys_clock_settime(clockid_t which_clock,
753                                          struct compat_timespec __user *tp);
754 asmlinkage long compat_sys_clock_gettime(clockid_t which_clock,
755                                          struct compat_timespec __user *tp);
756 asmlinkage long compat_sys_clock_adjtime(clockid_t which_clock,
757                                          struct compat_timex __user *tp);
758 asmlinkage long compat_sys_clock_getres(clockid_t which_clock,
759                                         struct compat_timespec __user *tp);
760 asmlinkage long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
761                                            struct compat_timespec __user *rqtp,
762                                            struct compat_timespec __user *rmtp);
763 asmlinkage long compat_sys_rt_sigtimedwait(compat_sigset_t __user *uthese,
764                 struct compat_siginfo __user *uinfo,
765                 struct compat_timespec __user *uts, compat_size_t sigsetsize);
766 asmlinkage long compat_sys_rt_sigsuspend(compat_sigset_t __user *unewset,
767                                          compat_size_t sigsetsize);
768 asmlinkage long compat_sys_rt_sigprocmask(int how, compat_sigset_t __user *set,
769                                           compat_sigset_t __user *oset,
770                                           compat_size_t sigsetsize);
771 asmlinkage long compat_sys_rt_sigpending(compat_sigset_t __user *uset,
772                                          compat_size_t sigsetsize);
773 #ifndef CONFIG_ODD_RT_SIGACTION
774 asmlinkage long compat_sys_rt_sigaction(int,
775                                  const struct compat_sigaction __user *,
776                                  struct compat_sigaction __user *,
777                                  compat_size_t);
778 #endif
779 asmlinkage long compat_sys_rt_sigqueueinfo(compat_pid_t pid, int sig,
780                                 struct compat_siginfo __user *uinfo);
781 asmlinkage long compat_sys_sysinfo(struct compat_sysinfo __user *info);
782 asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
783                                  compat_ulong_t arg);
784 asmlinkage long compat_sys_futex(u32 __user *uaddr, int op, u32 val,
785                 struct compat_timespec __user *utime, u32 __user *uaddr2,
786                 u32 val3);
787 asmlinkage long compat_sys_getsockopt(int fd, int level, int optname,
788                                       char __user *optval, int __user *optlen);
789 asmlinkage long compat_sys_kexec_load(compat_ulong_t entry,
790                                       compat_ulong_t nr_segments,
791                                       struct compat_kexec_segment __user *,
792                                       compat_ulong_t flags);
793 asmlinkage long compat_sys_mq_getsetattr(mqd_t mqdes,
794                         const struct compat_mq_attr __user *u_mqstat,
795                         struct compat_mq_attr __user *u_omqstat);
796 asmlinkage long compat_sys_mq_notify(mqd_t mqdes,
797                         const struct compat_sigevent __user *u_notification);
798 asmlinkage long compat_sys_mq_open(const char __user *u_name,
799                         int oflag, compat_mode_t mode,
800                         struct compat_mq_attr __user *u_attr);
801 asmlinkage long compat_sys_mq_timedsend(mqd_t mqdes,
802                         const char __user *u_msg_ptr,
803                         compat_size_t msg_len, unsigned int msg_prio,
804                         const struct compat_timespec __user *u_abs_timeout);
805 asmlinkage ssize_t compat_sys_mq_timedreceive(mqd_t mqdes,
806                         char __user *u_msg_ptr,
807                         compat_size_t msg_len, unsigned int __user *u_msg_prio,
808                         const struct compat_timespec __user *u_abs_timeout);
809 asmlinkage long compat_sys_socketcall(int call, u32 __user *args);
810 asmlinkage long compat_sys_sysctl(struct compat_sysctl_args __user *args);
811 
812 extern ssize_t compat_rw_copy_check_uvector(int type,
813                 const struct compat_iovec __user *uvector,
814                 unsigned long nr_segs,
815                 unsigned long fast_segs, struct iovec *fast_pointer,
816                 struct iovec **ret_pointer);
817 
818 extern void __user *compat_alloc_user_space(unsigned long len);
819 
820 asmlinkage ssize_t compat_sys_process_vm_readv(compat_pid_t pid,
821                 const struct compat_iovec __user *lvec,
822                 compat_ulong_t liovcnt, const struct compat_iovec __user *rvec,
823                 compat_ulong_t riovcnt, compat_ulong_t flags);
824 asmlinkage ssize_t compat_sys_process_vm_writev(compat_pid_t pid,
825                 const struct compat_iovec __user *lvec,
826                 compat_ulong_t liovcnt, const struct compat_iovec __user *rvec,
827                 compat_ulong_t riovcnt, compat_ulong_t flags);
828 
829 asmlinkage long compat_sys_sendfile(int out_fd, int in_fd,
830                                     compat_off_t __user *offset, compat_size_t count);
831 asmlinkage long compat_sys_sendfile64(int out_fd, int in_fd,
832                                     compat_loff_t __user *offset, compat_size_t count);
833 asmlinkage long compat_sys_sigaltstack(const compat_stack_t __user *uss_ptr,
834                                        compat_stack_t __user *uoss_ptr);
835 
836 #ifdef __ARCH_WANT_SYS_SIGPENDING
837 asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set);
838 #endif
839 
840 #ifdef __ARCH_WANT_SYS_SIGPROCMASK
841 asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *nset,
842                                        compat_old_sigset_t __user *oset);
843 #endif
844 
845 int compat_restore_altstack(const compat_stack_t __user *uss);
846 int __compat_save_altstack(compat_stack_t __user *, unsigned long);
847 #define compat_save_altstack_ex(uss, sp) do { \
848         compat_stack_t __user *__uss = uss; \
849         struct task_struct *t = current; \
850         put_user_ex(ptr_to_compat((void __user *)t->sas_ss_sp), &__uss->ss_sp); \
851         put_user_ex(t->sas_ss_flags, &__uss->ss_flags); \
852         put_user_ex(t->sas_ss_size, &__uss->ss_size); \
853         if (t->sas_ss_flags & SS_AUTODISARM) \
854                 sas_ss_reset(t); \
855 } while (0);
856 
857 asmlinkage long compat_sys_sched_rr_get_interval(compat_pid_t pid,
858                                                  struct compat_timespec __user *interval);
859 
860 asmlinkage long compat_sys_fanotify_mark(int, unsigned int, __u32, __u32,
861                                             int, const char __user *);
862 
863 asmlinkage long compat_sys_arch_prctl(int option, unsigned long arg2);
864 
865 /*
866  * For most but not all architectures, "am I in a compat syscall?" and
867  * "am I a compat task?" are the same question.  For architectures on which
868  * they aren't the same question, arch code can override in_compat_syscall.
869  */
870 
871 #ifndef in_compat_syscall
872 static inline bool in_compat_syscall(void) { return is_compat_task(); }
873 #endif
874 
875 /**
876  * ns_to_compat_timeval - Compat version of ns_to_timeval
877  * @nsec:       the nanoseconds value to be converted
878  *
879  * Returns the compat_timeval representation of the nsec parameter.
880  */
881 static inline struct compat_timeval ns_to_compat_timeval(s64 nsec)
882 {
883         struct timeval tv;
884         struct compat_timeval ctv;
885 
886         tv = ns_to_timeval(nsec);
887         ctv.tv_sec = tv.tv_sec;
888         ctv.tv_usec = tv.tv_usec;
889 
890         return ctv;
891 }
892 
893 #else /* !CONFIG_COMPAT */
894 
895 #define is_compat_task() (0)
896 static inline bool in_compat_syscall(void) { return false; }
897 
898 #endif /* CONFIG_COMPAT */
899 
900 #endif /* _LINUX_COMPAT_H */
901 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp