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>
29 #include <sys/syscall.h>
35 # define __NR_vserver 273
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
44 #ifdef VC_MULTIVERSION_SYSCALL
45 # define VC_SELECT(ID) if (ver>=(ID))
46 # define CALL_VC(...) \
48 int ver = utilvserver_checkCompatVersion(); \
49 if (ver==-1) return -1; \
50 VC_SUFFIX, __VA_ARGS__, VC_PREFIX; \
55 # define VC_SELECT(ID) if (1)
56 # define CALL_VC(...) \
58 if (1) {} VC_SUFFIX, __VA_ARGS__, VC_PREFIX; \
59 errno = ENOSYS; return -1; \
63 #ifdef VC_ENABLE_API_COMPAT
64 # define CALL_VC_COMPAT(F,...) CALL_VC_GENERAL(0x00010000, compat, F, __VA_ARGS__)
66 # define CALL_VC_COMPAT(F,...) CALL_VC_NOOP
69 #ifdef VC_ENABLE_API_LEGACY
70 # define CALL_VC_LEGACY(F,...) CALL_VC_GENERAL(0x00000000, legacy, F, __VA_ARGS__)
72 # define CALL_VC_LEGACY(F,...) CALL_VC_NOOP
75 #ifdef VC_ENABLE_API_V11
76 # define CALL_VC_V11(F,...) CALL_VC_GENERAL(0x00010000, v11, F, __VA_ARGS__)
78 # define CALL_VC_V11(F,...) CALL_VC_NOOP
81 #ifdef VC_ENABLE_API_V13
82 # define CALL_VC_V13(F,...) CALL_VC_GENERAL(0x00010010, v13, F, __VA_ARGS__)
84 # define CALL_VC_V13(F,...) CALL_VC_NOOP
87 #ifdef VC_ENABLE_API_FSCOMPAT
88 # define CALL_VC_FSCOMPAT(F,...) CALL_VC_GENERAL(0x00010000, fscompat, F, __VA_ARGS__)
90 # define CALL_VC_FSCOMPAT(F,...) CALL_VC_NOOP
93 #ifdef VC_ENABLE_API_OLDPROC
94 # define CALL_VC_OLDPROC(F,...) CALL_VC_GENERAL(0x00000000, X, F, __VA_ARGS__)
96 # define CALL_VC_OLDPROC(F,...) CALL_VC_NOOP
100 # define CTX_KERNEL2USER(X) (((X)==(uint32_t)(-1)) ? VC_NOCTX : \
101 ((X)==(uint32_t)(-2)) ? VC_SAMECTX : \
104 # define CTX_USER2KERNEL(X) (((X)==VC_RANDCTX) ? (uint32_t)(-1) : \
105 ((X)==VC_SAMECTX) ? (uint32_t)(-2) : \
108 # define CTX_USER2KERNEL(X) (X)
109 # define CTX_KERNEL2USER(X) (X)
113 # define EXT2FLAGS_USER2KERNEL(X) (((X) & ~(VC_IMMUTABLE_FILE_FL|VC_IMMUTABLE_LINK_FL)) | \
114 ((X) & VC_IMMUTABLE_FILE_FL ? EXT2_IMMUTABLE_FILE_FL : 0) | \
115 ((X) & VC_IMMUTABLE_LINK_FL ? EXT2_IMMUTABLE_LINK_FL : 0))
116 # define EXT2FLAGS_KERNEL2USER(X) (((X) & ~(EXT2_IMMUTABLE_FILE_FL|EXT2_IMMUTABLE_LINK_FL)) | \
117 ((X) & EXT2_IMMUTABLE_FILE_FL ? VC_IMMUTABLE_FILE_FL : 0) | \
118 ((X) & EXT2_IMMUTABLE_LINK_FL ? VC_IMMUTABLE_LINK_FL : 0))
120 # define EXT2FLAGS_KERNEL2USER(X) (X)
121 # define EXT2FLAGS_USER2KERNEL(X) (X)
125 #define EXT2_IOC_GETCONTEXT _IOR('x', 1, long)
126 #define EXT2_IOC_SETCONTEXT _IOW('x', 2, long)
129 #if defined(__pic__) && defined(__i386)
130 inline static UNUSED ALWAYSINLINE
131 int vserver(uint32_t cmd, uint32_t id, void *data)
133 #if defined __dietlibc__
134 extern long int syscall (long int __sysno, ...);
137 return syscall(__NR_vserver, cmd, id, data);
140 inline static UNUSED ALWAYSINLINE
141 _syscall3(int, vserver,
142 uint32_t, cmd, uint32_t, id, void *, data)
146 #endif // H_VSERVER_SYSCALL_INTERNAL_H