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 uint_least32_t 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 #ifdef VC_ENABLE_API_V21
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 #ifdef VC_ENABLE_API_NET
124 # define CALL_VC_NET(F,...) CALL_VC_GENERAL(0x00010016, net, F, __VA_ARGS__)
126 # define CALL_VC_NET(F,...) CALL_VC_NOOP
129 #ifdef VC_ENABLE_API_FSCOMPAT
130 # define CALL_VC_FSCOMPAT(F,...) CALL_VC_GENERAL(0x00010000, fscompat, F, __VA_ARGS__)
132 # define CALL_VC_FSCOMPAT(F,...) CALL_VC_NOOP
135 #ifdef VC_ENABLE_API_OLDPROC
136 # define CALL_VC_OLDPROC(F,...) CALL_VC_GENERAL(0x00000000, oldproc, F, __VA_ARGS__)
138 # define CALL_VC_OLDPROC(F,...) CALL_VC_NOOP
141 #ifdef VC_ENABLE_API_OLDUTS
142 # define CALL_VC_OLDUTS(F,...) CALL_VC_GENERAL(0x00000000, olduts, F, __VA_ARGS__)
144 # define CALL_VC_OLDUTS(F,...) CALL_VC_NOOP
148 // Some kernel <-> userspace wrappers; they should be noops in most cases
151 # define CTX_KERNEL2USER(X) (((X)==(uint32_t)(-1)) ? VC_NOCTX : \
152 ((X)==(uint32_t)(-2)) ? VC_SAMECTX : \
155 # define CTX_USER2KERNEL(X) (((X)==VC_DYNAMIC_XID) ? (uint32_t)(-1) : \
156 ((X)==VC_SAMECTX) ? (uint32_t)(-2) : \
159 # define CTX_USER2KERNEL(X) (X)
160 # define CTX_KERNEL2USER(X) (X)
164 # define EXT2FLAGS_USER2KERNEL(X) (((X) & ~(VC_IMMUTABLE_FILE_FL|VC_IMMUTABLE_LINK_FL)) | \
165 ((X) & VC_IMMUTABLE_FILE_FL ? EXT2_IMMUTABLE_FILE_FL : 0) | \
166 ((X) & VC_IMMUTABLE_LINK_FL ? EXT2_IMMUTABLE_LINK_FL : 0))
167 # define EXT2FLAGS_KERNEL2USER(X) (((X) & ~(EXT2_IMMUTABLE_FILE_FL|EXT2_IMMUTABLE_LINK_FL)) | \
168 ((X) & EXT2_IMMUTABLE_FILE_FL ? VC_IMMUTABLE_FILE_FL : 0) | \
169 ((X) & EXT2_IMMUTABLE_LINK_FL ? VC_IMMUTABLE_LINK_FL : 0))
171 # define EXT2FLAGS_KERNEL2USER(X) (X)
172 # define EXT2FLAGS_USER2KERNEL(X) (X)
176 # define VHI_USER2KERNEL(X) ((((X)==vcVHI_CONTEXT) ? VHIN_CONTEXT : \
177 ((X)==vcVHI_SYSNAME) ? VHIN_SYSNAME : \
178 ((X)==vcVHI_NODENAME) ? VHIN_NODENAME : \
179 ((X)==vcVHI_RELEASE) ? VHIN_RELEASE : \
180 ((X)==vcVHI_VERSION) ? VHIN_VERSION : \
181 ((X)==vcVHI_MACHINE) ? VHIN_MACHINE : \
182 ((X)==vcVHI_DOMAINNAME) ? VHIN_DOMAINNAME : \
184 # define VHI_KERNEL2USER(X) ((((X)==VHIN_CONTEXT) ? vcVHI_CONTEXT : \
185 ((X)==VHIN_SYSNAME) ? vcVHI_SYSNAME : \
186 ((X)==VHIN_NODENAME) ? vcVHI_NODENAME : \
187 ((X)==VHIN_RELEASE) ? vcVHI_RELEASE : \
188 ((X)==VHIN_VERSION) ? vcVHI_VERSION : \
189 ((X)==VHIN_MACHINE) ? vcVHI_MACHINE : \
190 ((X)==VHIN_DOMAINNAME) ? vcVHI_DOMAINNAME : \
193 # define VHI_USER2KERNEL(X) (X)
194 # define VHI_KERNEL2USER(X) (X)
198 # define NID_KERNEL2USER(X) (((X)==(uint32_t)(-1)) ? VC_NONID : \
201 # define NID_USER2KERNEL(X) (((X)==VC_DYNAMIC_NID) ? (uint32_t)(-1) : \
204 # define NID_USER2KERNEL(X) (X)
205 # define NID_KERNEL2USER(X) (X)
209 # define NETTYPE_USER2KERNEL(X) ((X)==vcNET_IPV4 ? NXA_TYPE_IPV4 : \
210 (X)==vcNET_IPV6 ? NXA_TYPE_IPV6 : \
211 (X)==vcNET_IPV4B ? (NXA_TYPE_IPV4 | NXA_MOD_BCAST) : \
212 (X)==vcNET_IPV6B ? (NXA_TYPE_IPV6 | NXA_MOD_BCAST) : \
213 (X)==vcNET_ANY ? NXA_TYPE_ANY : \
215 # define NETTYPE_KERNEL2USER(X) ((X)==NXA_TYPE_IPV4 ? vcNET_IPV4 : \
216 (X)==NXA_TYPE_IPV6 ? vcNET_IPV6 : \
217 (X)==(NXA_TYPE_IPV4|NXA_MOD_BCAST) ? vcNET_IPV4B : \
218 (X)==(NXA_TYPE_IPV6|NXA_MOD_BCAST) ? vcNET_IPV6B : \
219 (X)==NXA_TYPE_ANY ? vcNET_ANY : \
222 # define NETTYPE_USER2KERNEL(X) (X)
223 # define NETTYPE_KERNEL2USER(X) (X)
226 #define CDLIM_USER2KERNEL(X) ((X)==VC_CDLIM_UNSET ? CDLIM_UNSET : \
227 (X)==VC_CDLIM_INFINITY ? CDLIM_INFINITY : \
228 (X)==VC_CDLIM_KEEP ? CDLIM_KEEP : \
231 /// the __typeof__ thing is a hack to deal with the kernel interface
232 /// using an unsigned long long value for a uint32_t type
233 #define CDLIM_KERNEL2USER(X) ((X)==(__typeof__(X))CDLIM_UNSET ? VC_CDLIM_UNSET : \
234 (X)==(__typeof__(X))CDLIM_INFINITY ? VC_CDLIM_INFINITY : \
235 (X)==(__typeof__(X))CDLIM_KEEP ? VC_CDLIM_KEEP : \
239 #define ENSC_STRUCT_IDX(STRUCT,ATTR) \
240 ((char*)(&(STRUCT).ATTR) - (char*)(&(STRUCT)))
241 #define ENSC_SAME_STRUCT_IDX(LHS,RHS,ATTR) \
242 (ENSC_STRUCT_IDX(LHS,ATTR) == ENSC_STRUCT_IDX(RHS,ATTR))
243 #define ENSC_SAME_STRUCT_ITEM(LHS,RHS,ATTR) \
244 (ENSC_SAME_STRUCT_IDX(LHS,RHS,ATTR) && \
245 sizeof((LHS).ATTR)==sizeof((RHS).ATTR) && \
246 sizeof(LHS)==sizeof(RHS))
248 #define EXT2_IOC_GETCONTEXT _IOR('x', 1, long)
249 #define EXT2_IOC_SETCONTEXT _IOW('x', 2, long)
252 #ifdef ENSC_SYSCALL_TRADITIONAL
253 inline static UNUSED ALWAYSINLINE
254 int vserver(uint32_t cmd, uint32_t id, void *data)
256 return syscall(__NR_vserver, cmd, id, data);
259 inline static UNUSED ALWAYSINLINE
260 _syscall3(int, vserver,
261 uint32_t, cmd, uint32_t, id, void *, data)
265 #endif // H_VSERVER_SYSCALL_INTERNAL_H