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