xref: /netbsd-src/sys/compat/linux/common/linux_limit.h (revision ce099b40997c43048fb78bd578195f81d2456523)
1 /* 	$NetBSD: linux_limit.h,v 1.3 2008/04/28 20:23:43 martin 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  *
20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef _LINUX_LIMIT_H_
34 #define _LINUX_LIMIT_H_
35 
36 static int linux_to_bsd_limit(int);
37 
38 #ifdef LINUX_LARGEFILE64
39 #define bsd_to_linux_rlimit1(l, b, f) \
40     (l)->f = ((b)->f == RLIM_INFINITY || \
41 	     ((b)->f & 0x8000000000000000UL) != 0) ? \
42     LINUX_RLIM_INFINITY : (b)->f
43 #else
44 #define bsd_to_linux_rlimit1(l, b, f) \
45     (l)->f = ((b)->f == RLIM_INFINITY || \
46 	     ((b)->f & 0xffffffff00000000ULL) != 0) ? \
47     LINUX_RLIM_INFINITY : (int32_t)(b)->f
48 #endif
49 #define bsd_to_linux_rlimit(l, b) \
50     bsd_to_linux_rlimit1(l, b, rlim_cur); \
51     bsd_to_linux_rlimit1(l, b, rlim_max)
52 
53 #define linux_to_bsd_rlimit1(b, l, f) \
54     (b)->f = (l)->f == LINUX_RLIM_INFINITY ? RLIM_INFINITY : (l)->f
55 #define linux_to_bsd_rlimit(b, l) \
56     linux_to_bsd_rlimit1(b, l, rlim_cur); \
57     linux_to_bsd_rlimit1(b, l, rlim_max)
58 
59 static int
60 linux_to_bsd_limit(lim)
61 	int lim;
62 {
63 	switch (lim) {
64 	case LINUX_RLIMIT_CPU:
65 		return RLIMIT_CPU;
66 	case LINUX_RLIMIT_FSIZE:
67 		return RLIMIT_FSIZE;
68 	case LINUX_RLIMIT_DATA:
69 		return RLIMIT_DATA;
70 	case LINUX_RLIMIT_STACK:
71 		return RLIMIT_STACK;
72 	case LINUX_RLIMIT_CORE:
73 		return RLIMIT_CORE;
74 	case LINUX_RLIMIT_RSS:
75 		return RLIMIT_RSS;
76 	case LINUX_RLIMIT_NPROC:
77 		return RLIMIT_NPROC;
78 	case LINUX_RLIMIT_NOFILE:
79 		return RLIMIT_NOFILE;
80 	case LINUX_RLIMIT_MEMLOCK:
81 		return RLIMIT_MEMLOCK;
82 	case LINUX_RLIMIT_AS:
83 	case LINUX_RLIMIT_LOCKS:
84 		return -EOPNOTSUPP;
85 	default:
86 		return -EINVAL;
87 	}
88 }
89 
90 
91 #endif /* _LINUX_LIMIT_H_ */
92