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