Xenomai  3.1
syscall.h
1 /*
2  * Copyright (C) 2001,2002,2003,2004,2005 Philippe Gerum <rpm@xenomai.org>.
3  *
4  * Xenomai is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published
6  * by the Free Software Foundation; either version 2 of the License,
7  * or (at your option) any later version.
8  *
9  * Xenomai is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Xenomai; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17  * 02111-1307, USA.
18  */
19 #ifndef _COBALT_ASM_GENERIC_SYSCALL_H
20 #define _COBALT_ASM_GENERIC_SYSCALL_H
21 
22 #include <linux/types.h>
23 #include <linux/version.h>
24 #include <linux/uaccess.h>
25 #include <asm/xenomai/features.h>
26 #include <asm/xenomai/wrappers.h>
27 #include <asm/xenomai/machine.h>
28 #include <cobalt/uapi/asm-generic/syscall.h>
29 
30 #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0)
31 #define access_rok(addr, size) access_ok((addr), (size))
32 #define access_wok(addr, size) access_ok((addr), (size))
33 #else
34 #define access_rok(addr, size) access_ok(VERIFY_READ, (addr), (size))
35 #define access_wok(addr, size) access_ok(VERIFY_WRITE, (addr), (size))
36 #endif
37 
38 #define __xn_reg_arglist(regs) \
39  __xn_reg_arg1(regs), \
40  __xn_reg_arg2(regs), \
41  __xn_reg_arg3(regs), \
42  __xn_reg_arg4(regs), \
43  __xn_reg_arg5(regs)
44 
45 #define __xn_copy_from_user(dstP, srcP, n) raw_copy_from_user(dstP, srcP, n)
46 #define __xn_copy_to_user(dstP, srcP, n) raw_copy_to_user(dstP, srcP, n)
47 #define __xn_put_user(src, dstP) __put_user(src, dstP)
48 #define __xn_get_user(dst, srcP) __get_user(dst, srcP)
49 #define __xn_strncpy_from_user(dstP, srcP, n) strncpy_from_user(dstP, srcP, n)
50 
51 static inline int cobalt_copy_from_user(void *dst, const void __user *src,
52  size_t size)
53 {
54  size_t remaining = size;
55 
56  if (likely(access_rok(src, size)))
57  remaining = __xn_copy_from_user(dst, src, size);
58 
59  if (unlikely(remaining > 0)) {
60  memset(dst + (size - remaining), 0, remaining);
61  return -EFAULT;
62  }
63  return 0;
64 }
65 
66 static inline int cobalt_copy_to_user(void __user *dst, const void *src,
67  size_t size)
68 {
69  if (unlikely(!access_wok(dst, size) ||
70  __xn_copy_to_user(dst, src, size)))
71  return -EFAULT;
72  return 0;
73 }
74 
75 static inline int cobalt_strncpy_from_user(char *dst, const char __user *src,
76  size_t count)
77 {
78  if (unlikely(!access_rok(src, 1)))
79  return -EFAULT;
80 
81  return __xn_strncpy_from_user(dst, src, count);
82 }
83 
84 /* 32bit syscall emulation */
85 #define __COBALT_COMPAT_BIT 0x1
86 /* 32bit syscall emulation - extended form */
87 #define __COBALT_COMPATX_BIT 0x2
88 
89 #endif /* !_COBALT_ASM_GENERIC_SYSCALL_H */