linux_limit.h revision 1.1.10.2 1 1.1.10.2 simonb /* $NetBSD: linux_limit.h,v 1.1.10.2 2006/04/22 11:38:13 simonb Exp $ */
2 1.1.10.2 simonb
3 1.1.10.2 simonb /*-
4 1.1.10.2 simonb * Copyright (c) 1995, 1998, 1999 The NetBSD Foundation, Inc.
5 1.1.10.2 simonb * All rights reserved.
6 1.1.10.2 simonb *
7 1.1.10.2 simonb * This code is derived from software contributed to The NetBSD Foundation
8 1.1.10.2 simonb * by Frank van der Linden and Eric Haszlakiewicz; by Jason R. Thorpe
9 1.1.10.2 simonb * of the Numerical Aerospace Simulation Facility, NASA Ames Research Center.
10 1.1.10.2 simonb *
11 1.1.10.2 simonb * Redistribution and use in source and binary forms, with or without
12 1.1.10.2 simonb * modification, are permitted provided that the following conditions
13 1.1.10.2 simonb * are met:
14 1.1.10.2 simonb * 1. Redistributions of source code must retain the above copyright
15 1.1.10.2 simonb * notice, this list of conditions and the following disclaimer.
16 1.1.10.2 simonb * 2. Redistributions in binary form must reproduce the above copyright
17 1.1.10.2 simonb * notice, this list of conditions and the following disclaimer in the
18 1.1.10.2 simonb * documentation and/or other materials provided with the distribution.
19 1.1.10.2 simonb * 3. All advertising materials mentioning features or use of this software
20 1.1.10.2 simonb * must display the following acknowledgement:
21 1.1.10.2 simonb * This product includes software developed by the NetBSD
22 1.1.10.2 simonb * Foundation, Inc. and its contributors.
23 1.1.10.2 simonb * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.1.10.2 simonb * contributors may be used to endorse or promote products derived
25 1.1.10.2 simonb * from this software without specific prior written permission.
26 1.1.10.2 simonb *
27 1.1.10.2 simonb * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.1.10.2 simonb * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.1.10.2 simonb * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.1.10.2 simonb * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.1.10.2 simonb * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.1.10.2 simonb * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.1.10.2 simonb * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.1.10.2 simonb * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.1.10.2 simonb * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.1.10.2 simonb * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.1.10.2 simonb * POSSIBILITY OF SUCH DAMAGE.
38 1.1.10.2 simonb */
39 1.1.10.2 simonb
40 1.1.10.2 simonb #ifndef _LINUX_LIMIT_H_
41 1.1.10.2 simonb #define _LINUX_LIMIT_H_
42 1.1.10.2 simonb
43 1.1.10.2 simonb static int linux_to_bsd_limit __P((int));
44 1.1.10.2 simonb
45 1.1.10.2 simonb #ifdef LINUX_LARGEFILE64
46 1.1.10.2 simonb #define bsd_to_linux_rlimit1(l, b, f) \
47 1.1.10.2 simonb (l)->f = ((b)->f == RLIM_INFINITY || \
48 1.1.10.2 simonb ((b)->f & 0x8000000000000000UL) != 0) ? \
49 1.1.10.2 simonb LINUX_RLIM_INFINITY : (b)->f
50 1.1.10.2 simonb #else
51 1.1.10.2 simonb #define bsd_to_linux_rlimit1(l, b, f) \
52 1.1.10.2 simonb (l)->f = ((b)->f == RLIM_INFINITY || \
53 1.1.10.2 simonb ((b)->f & 0xffffffff00000000ULL) != 0) ? \
54 1.1.10.2 simonb LINUX_RLIM_INFINITY : (int32_t)(b)->f
55 1.1.10.2 simonb #endif
56 1.1.10.2 simonb #define bsd_to_linux_rlimit(l, b) \
57 1.1.10.2 simonb bsd_to_linux_rlimit1(l, b, rlim_cur); \
58 1.1.10.2 simonb bsd_to_linux_rlimit1(l, b, rlim_max)
59 1.1.10.2 simonb
60 1.1.10.2 simonb #define linux_to_bsd_rlimit1(b, l, f) \
61 1.1.10.2 simonb (b)->f = (l)->f == LINUX_RLIM_INFINITY ? RLIM_INFINITY : (l)->f
62 1.1.10.2 simonb #define linux_to_bsd_rlimit(b, l) \
63 1.1.10.2 simonb linux_to_bsd_rlimit1(b, l, rlim_cur); \
64 1.1.10.2 simonb linux_to_bsd_rlimit1(b, l, rlim_max)
65 1.1.10.2 simonb
66 1.1.10.2 simonb static int
67 1.1.10.2 simonb linux_to_bsd_limit(lim)
68 1.1.10.2 simonb int lim;
69 1.1.10.2 simonb {
70 1.1.10.2 simonb switch (lim) {
71 1.1.10.2 simonb case LINUX_RLIMIT_CPU:
72 1.1.10.2 simonb return RLIMIT_CPU;
73 1.1.10.2 simonb case LINUX_RLIMIT_FSIZE:
74 1.1.10.2 simonb return RLIMIT_FSIZE;
75 1.1.10.2 simonb case LINUX_RLIMIT_DATA:
76 1.1.10.2 simonb return RLIMIT_DATA;
77 1.1.10.2 simonb case LINUX_RLIMIT_STACK:
78 1.1.10.2 simonb return RLIMIT_STACK;
79 1.1.10.2 simonb case LINUX_RLIMIT_CORE:
80 1.1.10.2 simonb return RLIMIT_CORE;
81 1.1.10.2 simonb case LINUX_RLIMIT_RSS:
82 1.1.10.2 simonb return RLIMIT_RSS;
83 1.1.10.2 simonb case LINUX_RLIMIT_NPROC:
84 1.1.10.2 simonb return RLIMIT_NPROC;
85 1.1.10.2 simonb case LINUX_RLIMIT_NOFILE:
86 1.1.10.2 simonb return RLIMIT_NOFILE;
87 1.1.10.2 simonb case LINUX_RLIMIT_MEMLOCK:
88 1.1.10.2 simonb return RLIMIT_MEMLOCK;
89 1.1.10.2 simonb case LINUX_RLIMIT_AS:
90 1.1.10.2 simonb case LINUX_RLIMIT_LOCKS:
91 1.1.10.2 simonb return -EOPNOTSUPP;
92 1.1.10.2 simonb default:
93 1.1.10.2 simonb return -EINVAL;
94 1.1.10.2 simonb }
95 1.1.10.2 simonb }
96 1.1.10.2 simonb
97 1.1.10.2 simonb
98 1.1.10.2 simonb #endif /* _LINUX_LIMIT_H_ */
99