use ENSC_SYSCALL_TRADITIONAL
[util-vserver.git] / util-vserver / lib / vserver-internal.h
1 // $Id$    --*- c++ -*--
2
3 // Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 //  
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.
8 //  
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.
13 //  
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.
17
18 #ifdef H_VSERVER_SYSCALL_INTERNAL_H
19 #  error vserver-internal.h must not be included more than once
20 #endif
21
22 #ifndef H_VSERVER_SYSCALL_INTERNAL_H
23 #define H_VSERVER_SYSCALL_INTERNAL_H
24
25 #include <asm/unistd.h>
26 #include <syscall.h>
27 #include <errno.h>
28 #include <stdint.h>
29 #include <sys/syscall.h>
30 #include <unistd.h>
31
32 #include "internal.h"
33
34 #ifndef __NR_vserver
35 #  define __NR_vserver  273
36 #endif
37
38 #define VC_PREFIX       0)
39 #define VC_SUFFIX       else (void)((void)0
40 #define CALL_VC_NOOP    (void)0
41 #define CALL_VC_GENERAL(ID, SUFFIX, FUNC, ...)                          \
42   VC_PREFIX; VC_SELECT(ID) return FUNC ## _ ## SUFFIX(__VA_ARGS__); VC_SUFFIX
43
44 #ifdef VC_MULTIVERSION_SYSCALL
45 #  define VC_SELECT(ID) if (ver>=(ID))
46 #  define CALL_VC(...)                                  \
47   do {                                                  \
48     int ver = utilvserver_checkCompatVersion();         \
49     if (ver==-1) return -1;                             \
50     VC_SUFFIX, __VA_ARGS__, VC_PREFIX;                  \
51     errno = ENOSYS;                                     \
52     return -1;                                          \
53   } while (0)
54 #else
55 #  define VC_SELECT(ID) if (1)
56 #  define CALL_VC(...)                                  \
57   do {                                                  \
58     if (1) {} VC_SUFFIX, __VA_ARGS__, VC_PREFIX;        \
59     errno = ENOSYS; return -1;                          \
60   } while (0)
61 #endif
62
63 #ifdef VC_ENABLE_API_COMPAT
64 #  define CALL_VC_COMPAT(F,...) CALL_VC_GENERAL(0x00010000, compat, F, __VA_ARGS__)
65 #else
66 #  define CALL_VC_COMPAT(F,...) CALL_VC_NOOP
67 #endif
68
69 #ifdef VC_ENABLE_API_LEGACY
70 #  define CALL_VC_LEGACY(F,...) CALL_VC_GENERAL(0x00000000, legacy, F, __VA_ARGS__)
71 #else
72 #  define CALL_VC_LEGACY(F,...) CALL_VC_NOOP
73 #endif
74
75 #ifdef VC_ENABLE_API_V11
76 #  define CALL_VC_V11(F,...)    CALL_VC_GENERAL(0x00010000, v11, F, __VA_ARGS__)
77 #else
78 #  define CALL_VC_V11(F,...)    CALL_VC_NOOP
79 #endif
80
81 #ifdef VC_ENABLE_API_V13
82 #  define CALL_VC_V13(F,...)    CALL_VC_GENERAL(0x00010010, v13, F, __VA_ARGS__)
83 #else
84 #  define CALL_VC_V13(F,...)    CALL_VC_NOOP
85 #endif
86
87 #ifdef VC_ENABLE_API_FSCOMPAT
88 #  define CALL_VC_FSCOMPAT(F,...)       CALL_VC_GENERAL(0x00010000, fscompat, F, __VA_ARGS__)
89 #else
90 #  define CALL_VC_FSCOMPAT(F,...)       CALL_VC_NOOP
91 #endif
92
93 #ifdef VC_ENABLE_API_OLDPROC
94 #  define CALL_VC_OLDPROC(F,...)        CALL_VC_GENERAL(0x00000000, oldproc, F, __VA_ARGS__)
95 #else
96 #  define CALL_VC_OLDPROC(F,...)        CALL_VC_NOOP
97 #endif
98
99 #ifdef VC_ENABLE_API_OLDUTS
100 #  define CALL_VC_OLDUTS(F,...)         CALL_VC_GENERAL(0x00000000, olduts, F, __VA_ARGS__)
101 #else
102 #  define CALL_VC_OLDUTS(F,...)         CALL_VC_NOOP
103 #endif
104
105
106   // Some  kernel <-> userspace wrappers; they should be noops in most cases
107
108 #if 1
109 #  define CTX_KERNEL2USER(X)    (((X)==(uint32_t)(-1)) ? VC_NOCTX   : \
110                                  ((X)==(uint32_t)(-2)) ? VC_SAMECTX : \
111                                  (xid_t)(X))
112
113 #  define CTX_USER2KERNEL(X)    (((X)==VC_RANDCTX) ? (uint32_t)(-1) : \
114                                  ((X)==VC_SAMECTX) ? (uint32_t)(-2) : \
115                                  (uint32_t)(X))
116 #else
117 #  define CTX_USER2KERNEL(X)    (X)
118 #  define CTX_KERNEL2USER(X)    (X)
119 #endif
120
121 #if 1
122 #  define EXT2FLAGS_USER2KERNEL(X)      (((X) & ~(VC_IMMUTABLE_FILE_FL|VC_IMMUTABLE_LINK_FL)) | \
123                                          ((X) & VC_IMMUTABLE_FILE_FL ? EXT2_IMMUTABLE_FILE_FL : 0) | \
124                                          ((X) & VC_IMMUTABLE_LINK_FL ? EXT2_IMMUTABLE_LINK_FL : 0))
125 #  define EXT2FLAGS_KERNEL2USER(X)      (((X) & ~(EXT2_IMMUTABLE_FILE_FL|EXT2_IMMUTABLE_LINK_FL)) | \
126                                          ((X) & EXT2_IMMUTABLE_FILE_FL ? VC_IMMUTABLE_FILE_FL : 0) | \
127                                          ((X) & EXT2_IMMUTABLE_LINK_FL ? VC_IMMUTABLE_LINK_FL : 0))
128 #else
129 #  define EXT2FLAGS_KERNEL2USER(X)      (X)
130 #  define EXT2FLAGS_USER2KERNEL(X)      (X)
131 #endif
132
133 #if 1
134 #  define VHI_USER2KERNEL(X)            ((((X)==vcVHI_CONTEXT)    ? VHIN_CONTEXT    : \
135                                           ((X)==vcVHI_SYSNAME)    ? VHIN_SYSNAME    : \
136                                           ((X)==vcVHI_NODENAME)   ? VHIN_NODENAME   : \
137                                           ((X)==vcVHI_RELEASE)    ? VHIN_RELEASE    : \
138                                           ((X)==vcVHI_VERSION)    ? VHIN_VERSION    : \
139                                           ((X)==vcVHI_MACHINE)    ? VHIN_MACHINE    : \
140                                           ((X)==vcVHI_DOMAINNAME) ? VHIN_DOMAINNAME : \
141                                           (X)))
142 #  define VHI_KERNEL2USER(X)            ((((X)==VHIN_CONTEXT)     ? vcVHI_CONTEXT    : \
143                                           ((X)==VHIN_SYSNAME)     ? vcVHI_SYSNAME    : \
144                                           ((X)==VHIN_NODENAME)    ? vcVHI_NODENAME   : \
145                                           ((X)==VHIN_RELEASE)     ? vcVHI_RELEASE    : \
146                                           ((X)==VHIN_VERSION)     ? vcVHI_VERSION    : \
147                                           ((X)==VHIN_MACHINE)     ? vcVHI_MACHINE    : \
148                                           ((X)==VHIN_DOMAINNAME)  ? vcVHI_DOMAINNAME : \
149                                           (X)))
150 #else
151 #  define VHI_USER2KERNEL(X)            (X)
152 #  define VHI_KERNEL2USER(X)            (X)
153 #endif
154
155
156 #define EXT2_IOC_GETCONTEXT             _IOR('x', 1, long)
157 #define EXT2_IOC_SETCONTEXT             _IOW('x', 2, long)
158
159 #ifndef HAVE_VSERVER
160 #ifdef ENSC_SYSCALL_TRADITIONAL
161 inline static UNUSED ALWAYSINLINE
162 int vserver(uint32_t cmd, uint32_t id, void *data)
163 {
164 #if defined __dietlibc__
165   extern long int syscall (long int __sysno, ...);
166 #endif
167  
168   return syscall(__NR_vserver, cmd, id, data);
169 }
170 #else
171 inline static UNUSED ALWAYSINLINE
172 _syscall3(int, vserver,
173           uint32_t, cmd, uint32_t, id, void *, data)
174 #endif
175 #endif
176
177 #endif  //  H_VSERVER_SYSCALL_INTERNAL_H