3 // Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; version 2 of the License.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 #ifdef H_VSERVER_SYSCALL_INTERNAL_H
19 # error vserver-internal.h must not be included more than once
22 #ifndef H_VSERVER_SYSCALL_INTERNAL_H
23 #define H_VSERVER_SYSCALL_INTERNAL_H
25 #include <asm/unistd.h>
31 #include "syscall-wrap.h"
33 #if !defined(__NR_vserver) && defined(ENSC_SYSCALL__NR_vserver)
34 # define __NR_vserver ENSC_SYSCALL__NR_vserver
37 inline static ALWAYSINLINE void vc_noop0() {}
40 #define VC_SUFFIX else (void)(vc_noop0()
41 #define CALL_VC_NOOP vc_noop0()
42 #define CALL_VC_GENERAL(ID, SUFFIX, FUNC, ...) \
43 VC_PREFIX; VC_SELECT(ID) return FUNC ## _ ## SUFFIX(__VA_ARGS__); VC_SUFFIX
44 #define CALL_VC_GENERAL_CONFIG(BIT, SUFFIX, FUNC, ...) \
45 VC_PREFIX; VC_CBIT(BIT) return FUNC ## _ ## SUFFIX(__VA_ARGS__); VC_SUFFIX
47 #ifdef VC_MULTIVERSION_SYSCALL
48 # define VC_SELECT(ID) if (ver>=(ID))
49 # define VC_CBIT(BIT) if ((conf&BIT) == BIT)
50 # define CALL_VC(...) \
52 int ver = utilvserver_checkCompatVersion(); \
53 vc_vci_t UNUSED conf = utilvserver_checkCompatConfig(); \
54 if (ver==-1) return -1; \
55 VC_SUFFIX, __VA_ARGS__, VC_PREFIX; \
60 # define VC_SELECT(ID) if (1)
61 # define VC_CBIT(BIT) if (1)
62 # define CALL_VC(...) \
64 if (1) {} VC_SUFFIX, __VA_ARGS__, VC_PREFIX; \
65 errno = ENOSYS; return -1; \
69 #ifdef VC_ENABLE_API_COMPAT
70 # define CALL_VC_COMPAT(F,...) CALL_VC_GENERAL(0x00010000, compat, F, __VA_ARGS__)
72 # define CALL_VC_COMPAT(F,...) CALL_VC_NOOP
75 #ifdef VC_ENABLE_API_LEGACY
76 # define CALL_VC_LEGACY(F,...) CALL_VC_GENERAL(0x00000000, legacy, F, __VA_ARGS__)
78 # define CALL_VC_LEGACY(F,...) CALL_VC_NOOP
81 #ifdef VC_ENABLE_API_V11
82 # define CALL_VC_V11(F,...) CALL_VC_GENERAL(0x00010000, v11, F, __VA_ARGS__)
84 # define CALL_VC_V11(F,...) CALL_VC_NOOP
87 #ifdef VC_ENABLE_API_V13
88 # define CALL_VC_V13(F,...) CALL_VC_GENERAL(0x00010011, v13, F, __VA_ARGS__)
90 # define CALL_VC_V13(F,...) CALL_VC_NOOP
93 #ifdef VC_ENABLE_API_V13
94 # define CALL_VC_V13A(F,...) CALL_VC_GENERAL(0x00010012, v13, F, __VA_ARGS__)
96 # define CALL_VC_V13A(F,...) CALL_VC_NOOP
99 #ifdef VC_ENABLE_API_V13
100 # define CALL_VC_V13B(F,...) CALL_VC_GENERAL(0x00010021, v13b, F, __VA_ARGS__)
102 # define CALL_VC_V13B(F,...) CALL_VC_NOOP
105 #ifdef VC_ENABLE_API_V13OBS
106 # define CALL_VC_V13OBS(F,...) CALL_VC_GENERAL(0x00010011, v13obs, F, __VA_ARGS__)
108 # define CALL_VC_V13OBS(F,...) CALL_VC_NOOP
111 #ifdef VC_ENABLE_API_V21
112 # define CALL_VC_V21(F,...) CALL_VC_GENERAL(0x00020100, v21, F, __VA_ARGS__)
114 # define CALL_VC_V21(F,...) CALL_VC_NOOP
117 #if defined(VC_ENABLE_API_V21) || defined(VC_ENABLE_API_V22) || defined(VC_ENABLE_API_V23)
118 # define CALL_VC_SPACES(F,...) CALL_VC_GENERAL_CONFIG(VC_VCI_SPACES, spaces, F, __VA_ARGS__)
120 # define CALL_VC_SPACES(F,...) CALL_VC_NOOP
123 #if defined(VC_ENABLE_API_V23)
124 # define CALL_VC_TAG(F,...) CALL_VC_GENERAL_CONFIG(VC_VCI_PPTAG, tag, F, __VA_ARGS__)
126 # define CALL_VC_TAG(F,...) CALL_VC_NOOP
129 #ifdef VC_ENABLE_API_V22
130 # define CALL_VC_V22(F,...) CALL_VC_GENERAL(0x00020200, v22, F, __VA_ARGS__)
132 # define CALL_VC_V22(F,...) CALL_VC_NOOP
135 #ifdef VC_ENABLE_API_V23
136 # define CALL_VC_V23(F,...) CALL_VC_GENERAL(0x00020300, v23, F, __VA_ARGS__)
138 # define CALL_VC_V23(F,...) CALL_VC_NOOP
141 #ifdef VC_ENABLE_API_V23
142 # define CALL_VC_V23P(F,...) CALL_VC_GENERAL(0x00020304, v23, F, __VA_ARGS__)
144 # define CALL_VC_V23P(F,...) CALL_VC_NOOP
147 #ifdef VC_ENABLE_API_NET
148 # define CALL_VC_NET(F,...) CALL_VC_GENERAL(0x00010016, net, F, __VA_ARGS__)
150 # define CALL_VC_NET(F,...) CALL_VC_NOOP
153 #if defined(VC_ENABLE_API_NETV2)
154 # define CALL_VC_NETV2(F,...) CALL_VC_GENERAL_CONFIG(VC_VCI_NETV2, netv2, F, __VA_ARGS__)
156 # define CALL_VC_NETV2(F,...) CALL_VC_NOOP
159 #ifdef VC_ENABLE_API_FSCOMPAT
160 # define CALL_VC_FSCOMPAT(F,...) CALL_VC_GENERAL(0x00010000, fscompat, F, __VA_ARGS__)
162 # define CALL_VC_FSCOMPAT(F,...) CALL_VC_NOOP
165 #ifdef VC_ENABLE_API_OLDPROC
166 # define CALL_VC_OLDPROC(F,...) CALL_VC_GENERAL(0x00000000, oldproc, F, __VA_ARGS__)
168 # define CALL_VC_OLDPROC(F,...) CALL_VC_NOOP
171 #ifdef VC_ENABLE_API_OLDUTS
172 # define CALL_VC_OLDUTS(F,...) CALL_VC_GENERAL(0x00000000, olduts, F, __VA_ARGS__)
174 # define CALL_VC_OLDUTS(F,...) CALL_VC_NOOP
178 // Some kernel <-> userspace wrappers; they should be noops in most cases
181 # define CTX_KERNEL2USER(X) (((X)==(uint32_t)(-1)) ? VC_NOCTX : \
182 ((X)==(uint32_t)(-2)) ? VC_SAMECTX : \
185 # define CTX_USER2KERNEL(X) (((X)==VC_DYNAMIC_XID) ? (uint32_t)(-1) : \
186 ((X)==VC_SAMECTX) ? (uint32_t)(-2) : \
189 # define CTX_USER2KERNEL(X) (X)
190 # define CTX_KERNEL2USER(X) (X)
194 # define TAG_KERNEL2USER(X) (((X)==(uint32_t)(-1)) ? VC_NOCTX : \
195 ((X)==(uint32_t)(-2)) ? VC_SAMECTX : \
198 # define TAG_USER2KERNEL(X) (((X)==VC_DYNAMIC_XID) ? (uint32_t)(-1) : \
199 ((X)==VC_SAMECTX) ? (uint32_t)(-2) : \
202 # define TAG_USER2KERNEL(X) (X)
203 # define TAG_KERNEL2USER(X) (X)
207 # define EXT2FLAGS_USER2KERNEL(X) (((X) & ~(VC_IMMUTABLE_FILE_FL|VC_IMMUTABLE_LINK_FL)) | \
208 ((X) & VC_IMMUTABLE_FILE_FL ? EXT2_IMMUTABLE_FILE_FL : 0) | \
209 ((X) & VC_IMMUTABLE_LINK_FL ? EXT2_IMMUTABLE_LINK_FL : 0))
210 # define EXT2FLAGS_KERNEL2USER(X) (((X) & ~(EXT2_IMMUTABLE_FILE_FL|EXT2_IMMUTABLE_LINK_FL)) | \
211 ((X) & EXT2_IMMUTABLE_FILE_FL ? VC_IMMUTABLE_FILE_FL : 0) | \
212 ((X) & EXT2_IMMUTABLE_LINK_FL ? VC_IMMUTABLE_LINK_FL : 0))
214 # define EXT2FLAGS_KERNEL2USER(X) (X)
215 # define EXT2FLAGS_USER2KERNEL(X) (X)
219 # define VHI_USER2KERNEL(X) ((((X)==vcVHI_CONTEXT) ? VHIN_CONTEXT : \
220 ((X)==vcVHI_SYSNAME) ? VHIN_SYSNAME : \
221 ((X)==vcVHI_NODENAME) ? VHIN_NODENAME : \
222 ((X)==vcVHI_RELEASE) ? VHIN_RELEASE : \
223 ((X)==vcVHI_VERSION) ? VHIN_VERSION : \
224 ((X)==vcVHI_MACHINE) ? VHIN_MACHINE : \
225 ((X)==vcVHI_DOMAINNAME) ? VHIN_DOMAINNAME : \
227 # define VHI_KERNEL2USER(X) ((((X)==VHIN_CONTEXT) ? vcVHI_CONTEXT : \
228 ((X)==VHIN_SYSNAME) ? vcVHI_SYSNAME : \
229 ((X)==VHIN_NODENAME) ? vcVHI_NODENAME : \
230 ((X)==VHIN_RELEASE) ? vcVHI_RELEASE : \
231 ((X)==VHIN_VERSION) ? vcVHI_VERSION : \
232 ((X)==VHIN_MACHINE) ? vcVHI_MACHINE : \
233 ((X)==VHIN_DOMAINNAME) ? vcVHI_DOMAINNAME : \
236 # define VHI_USER2KERNEL(X) (X)
237 # define VHI_KERNEL2USER(X) (X)
241 # define NID_KERNEL2USER(X) (((X)==(uint32_t)(-1)) ? VC_NONID : \
244 # define NID_USER2KERNEL(X) (((X)==VC_DYNAMIC_NID) ? (uint32_t)(-1) : \
247 # define NID_USER2KERNEL(X) (X)
248 # define NID_KERNEL2USER(X) (X)
251 #define CDLIM_USER2KERNEL(X) ((X)==VC_CDLIM_UNSET ? CDLIM_UNSET : \
252 (X)==VC_CDLIM_INFINITY ? CDLIM_INFINITY : \
253 (X)==VC_CDLIM_KEEP ? CDLIM_KEEP : \
256 /// the __typeof__ thing is a hack to deal with the kernel interface
257 /// using an unsigned long long value for a uint32_t type
258 #define CDLIM_KERNEL2USER(X) ((X)==(__typeof__(X))CDLIM_UNSET ? VC_CDLIM_UNSET : \
259 (X)==(__typeof__(X))CDLIM_INFINITY ? VC_CDLIM_INFINITY : \
260 (X)==(__typeof__(X))CDLIM_KEEP ? VC_CDLIM_KEEP : \
264 #define ENSC_STRUCT_IDX(STRUCT,ATTR) \
265 ((char*)(&(STRUCT).ATTR) - (char*)(&(STRUCT)))
266 #define ENSC_SAME_STRUCT_IDX(LHS,RHS,ATTR) \
267 (ENSC_STRUCT_IDX(LHS,ATTR) == ENSC_STRUCT_IDX(RHS,ATTR))
268 #define ENSC_SAME_STRUCT_ITEM(LHS,RHS,ATTR) \
269 (ENSC_SAME_STRUCT_IDX(LHS,RHS,ATTR) && \
270 sizeof((LHS).ATTR)==sizeof((RHS).ATTR) && \
271 sizeof(LHS)==sizeof(RHS))
273 #define EXT2_IOC_GETCONTEXT _IOR('x', 1, long)
274 #define EXT2_IOC_SETCONTEXT _IOW('x', 2, long)
277 #ifdef ENSC_SYSCALL_TRADITIONAL
278 inline static UNUSED ALWAYSINLINE
279 int vserver(uint32_t cmd, uint32_t id, void *data)
281 return syscall(__NR_vserver, cmd, id, data);
284 inline static UNUSED ALWAYSINLINE
285 _syscall3(int, vserver,
286 uint32_t, cmd, uint32_t, id, void *, data)
290 #endif // H_VSERVER_SYSCALL_INTERNAL_H