c463df5b8ff54e28c92fe390b4045fc516711a1c
[util-vserver.git] / lib / syscall_rlimit-v11.hc
1 // $Id: syscall_rlimit-v11.hc,v 1.5 2004/02/20 19:03:24 ensc Exp $    --*- 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
19 #ifdef HAVE_CONFIG_H
20 #  include <config.h>
21 #endif
22
23 #define KERN2USR(LIMIT) \
24   (((LIMIT)==CRLIM_INFINITY)  ? VC_LIM_INFINITY :               \
25    ((LIMIT)==CRLIM_KEEP)      ? VC_LIM_KEEP     : (LIMIT))
26
27 #define USR2KERN(LIMIT) \
28   (((LIMIT)==VC_LIM_INFINITY) ? CRLIM_INFINITY :                \
29    ((LIMIT)==VC_LIM_KEEP)     ? CRLIM_KEEP     : (LIMIT))
30
31 static inline ALWAYSINLINE int
32 vc_get_rlimit_v11(xid_t ctx, int resource, struct vc_rlimit *lim)
33 {
34   struct vcmd_ctx_rlimit_v0     vc_lim;
35   int                           rc;
36
37   vc_lim.id        = resource;
38   rc = vserver(VCMD_get_rlimit, CTX_USER2KERNEL(ctx), &vc_lim);
39   lim->min  = KERN2USR(vc_lim.minimum);
40   lim->soft = KERN2USR(vc_lim.softlimit);
41   lim->hard = KERN2USR(vc_lim.maximum);
42
43   return rc;
44 }
45
46 static inline ALWAYSINLINE int
47 vc_set_rlimit_v11(xid_t ctx, int resource, struct vc_rlimit const *lim)
48 {
49   struct vcmd_ctx_rlimit_v0     vc_lim;
50
51   vc_lim.id        = resource;
52   vc_lim.minimum   = USR2KERN(lim->min);
53   vc_lim.softlimit = USR2KERN(lim->soft);
54   vc_lim.maximum   = USR2KERN(lim->hard);
55
56   return vserver(VCMD_set_rlimit, CTX_USER2KERNEL(ctx), &vc_lim);
57 }
58
59 static inline ALWAYSINLINE int
60 vc_get_rlimit_mask_v11(xid_t ctx, int UNUSED tmp, struct vc_rlimit_mask *lim)
61 {
62   struct vcmd_ctx_rlimit_mask_v0        vc_lim;
63   int                                   rc;
64
65   rc = vserver(VCMD_get_rlimit_mask, CTX_USER2KERNEL(ctx), &vc_lim);
66
67   lim->min  = vc_lim.minimum;
68   lim->soft = vc_lim.softlimit;
69   lim->hard = vc_lim.maximum;
70
71   return rc;
72 }
73
74 #undef KERN2USR
75 #undef USR2KERN