1 /* $NetBSD: linux_limit.h,v 1.7 2015/02/28 13:08:00 njoly 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 #define linux32_to_bsd_rlimit1(b, l, f) \ 60 (b)->f = (l)->f == LINUX32_RLIM_INFINITY ? RLIM_INFINITY : (uint32_t)(l)->f 61 #define linux32_to_bsd_rlimit(b, l) \ 62 linux32_to_bsd_rlimit1(b, l, rlim_cur); \ 63 linux32_to_bsd_rlimit1(b, l, rlim_max) 64 65 static int 66 linux_to_bsd_limit(int lim) 67 { 68 switch (lim) { 69 case LINUX_RLIMIT_CPU: 70 return RLIMIT_CPU; 71 case LINUX_RLIMIT_FSIZE: 72 return RLIMIT_FSIZE; 73 case LINUX_RLIMIT_DATA: 74 return RLIMIT_DATA; 75 case LINUX_RLIMIT_STACK: 76 return RLIMIT_STACK; 77 case LINUX_RLIMIT_CORE: 78 return RLIMIT_CORE; 79 case LINUX_RLIMIT_RSS: 80 return RLIMIT_RSS; 81 case LINUX_RLIMIT_NPROC: 82 return RLIMIT_NPROC; 83 case LINUX_RLIMIT_NOFILE: 84 return RLIMIT_NOFILE; 85 case LINUX_RLIMIT_MEMLOCK: 86 return RLIMIT_MEMLOCK; 87 case LINUX_RLIMIT_AS: 88 return RLIMIT_AS; 89 case LINUX_RLIMIT_LOCKS: 90 return -EOPNOTSUPP; 91 default: 92 return -EINVAL; 93 } 94 } 95 96 97 #endif /* _LINUX_LIMIT_H_ */ 98