Xenomai 3.3.2
Loading...
Searching...
No Matches
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#include <cobalt/uapi/kernel/types.h>
30
31#define __xn_copy_from_user(dstP, srcP, n) raw_copy_from_user(dstP, srcP, n)
32#define __xn_copy_to_user(dstP, srcP, n) raw_copy_to_user(dstP, srcP, n)
33#define __xn_put_user(src, dstP) __put_user(src, dstP)
34#define __xn_get_user(dst, srcP) __get_user(dst, srcP)
35#define __xn_strncpy_from_user(dstP, srcP, n) strncpy_from_user(dstP, srcP, n)
36
37static inline int cobalt_copy_from_user(void *dst, const void __user *src,
38 size_t size)
39{
40 size_t remaining = size;
41
42 if (likely(access_ok(src, size)))
43 remaining = __xn_copy_from_user(dst, src, size);
44
45 if (unlikely(remaining > 0)) {
46 memset(dst + (size - remaining), 0, remaining);
47 return -EFAULT;
48 }
49 return 0;
50}
51
52static inline int cobalt_copy_to_user(void __user *dst, const void *src,
53 size_t size)
54{
55 if (unlikely(!access_ok(dst, size) ||
56 __xn_copy_to_user(dst, src, size)))
57 return -EFAULT;
58 return 0;
59}
60
61static inline int cobalt_strncpy_from_user(char *dst, const char __user *src,
62 size_t count)
63{
64 if (unlikely(!access_ok(src, 1)))
65 return -EFAULT;
66
67 return __xn_strncpy_from_user(dst, src, count);
68}
69
70
71/*
72 * NOTE: those copy helpers won't work in compat mode: use
73 * sys32_get_*(), sys32_put_*() instead.
74 */
75
76static inline int
77cobalt_get_old_timespec(struct timespec64 *dst,
78 const struct __kernel_old_timespec __user *src)
79{
80 struct __kernel_old_timespec u_ts;
81 int ret;
82
83 ret = cobalt_copy_from_user(&u_ts, src, sizeof(u_ts));
84 if (ret)
85 return ret;
86
87 dst->tv_sec = u_ts.tv_sec;
88 dst->tv_nsec = u_ts.tv_nsec;
89
90 return 0;
91}
92
93static inline int
94cobalt_put_old_timespec(struct __kernel_old_timespec __user *dst,
95 const struct timespec64 *src)
96{
97 struct __kernel_old_timespec u_ts;
98 int ret;
99
100 u_ts.tv_sec = src->tv_sec;
101 u_ts.tv_nsec = src->tv_nsec;
102
103 ret = cobalt_copy_to_user(dst, &u_ts, sizeof(*dst));
104 if (ret)
105 return ret;
106
107 return 0;
108}
109
110static inline int
111cobalt_get_itimerspec32(struct itimerspec64 *dst,
112 const struct old_itimerspec32 __user *src)
113{
114 struct old_itimerspec32 u_its;
115 int ret;
116
117 ret = cobalt_copy_from_user(&u_its, src, sizeof(u_its));
118 if (ret)
119 return ret;
120
121 dst->it_interval.tv_sec = u_its.it_interval.tv_sec;
122 dst->it_interval.tv_nsec = u_its.it_interval.tv_nsec;
123 dst->it_value.tv_sec = u_its.it_value.tv_sec;
124 dst->it_value.tv_nsec = u_its.it_value.tv_nsec;
125
126 return 0;
127}
128
129static inline int cobalt_put_itimerspec32(struct old_itimerspec32 __user *dst,
130 const struct itimerspec64 *src)
131{
132 struct old_itimerspec32 u_its;
133
134 u_its.it_interval.tv_sec = src->it_interval.tv_sec;
135 u_its.it_interval.tv_nsec = src->it_interval.tv_nsec;
136 u_its.it_value.tv_sec = src->it_value.tv_sec;
137 u_its.it_value.tv_nsec = src->it_value.tv_nsec;
138
139 return cobalt_copy_to_user(dst, &u_its, sizeof(*dst));
140}
141
142static inline struct timespec64
143cobalt_timeval_to_timespec64(const struct __kernel_old_timeval *src)
144{
145 struct timespec64 ts;
146
147 ts.tv_sec = src->tv_sec + (src->tv_usec / USEC_PER_SEC);
148 ts.tv_nsec = (src->tv_usec % USEC_PER_SEC) * NSEC_PER_USEC;
149
150 return ts;
151}
152
153static inline struct __kernel_old_timeval
154cobalt_timespec64_to_timeval(const struct timespec64 *src)
155{
156 struct __kernel_old_timeval tv;
157
158 tv.tv_sec = src->tv_sec + (src->tv_nsec / NSEC_PER_SEC);
159 tv.tv_usec = (src->tv_nsec % NSEC_PER_SEC) / NSEC_PER_USEC;
160
161 return tv;
162}
163
164/* 32bit syscall emulation */
165#define __COBALT_COMPAT_BIT 0x1
166/* 32bit syscall emulation - extended form */
167#define __COBALT_COMPATX_BIT 0x2
168
169#endif /* !_COBALT_ASM_GENERIC_SYSCALL_H */