1/* Copyright (C) 2018-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
17
18#define USE_VERSIONED_RLIMIT
19#include <sysdeps/unix/sysv/linux/getrlimit64.c>
20versioned_symbol (libc, __getrlimit, getrlimit, GLIBC_2_27);
21versioned_symbol (libc, __getrlimit64, getrlimit64, GLIBC_2_27);
22
23#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_27)
24/* RLIM64_INFINITY was supposed to be a glibc convention rather than
25 anything seen by the kernel, but it ended being passed to the kernel
26 through the prlimit64 syscall. Given that a lot of binaries with
27 the wrong constant value are in the wild, provide a wrapper function
28 fixing the value after the syscall. */
29# define OLD_RLIM64_INFINITY 0x7fffffffffffffffULL
30
31int
32attribute_compat_text_section
33__old_getrlimit64 (enum __rlimit_resource resource,
34 struct rlimit64 *rlimits)
35{
36 struct rlimit64 krlimits;
37
38 if (__getrlimit64 (resource, &krlimits) < 0)
39 return -1;
40
41 if (krlimits.rlim_cur == RLIM64_INFINITY)
42 rlimits->rlim_cur = OLD_RLIM64_INFINITY;
43 else
44 rlimits->rlim_cur = krlimits.rlim_cur;
45 if (krlimits.rlim_max == RLIM64_INFINITY)
46 rlimits->rlim_max = OLD_RLIM64_INFINITY;
47 else
48 rlimits->rlim_max = krlimits.rlim_max;
49
50 return 0;
51}
52
53strong_alias (__old_getrlimit64, __old_getrlimit)
54compat_symbol (libc, __old_getrlimit, getrlimit, GLIBC_2_0);
55compat_symbol (libc, __old_getrlimit64, getrlimit64, GLIBC_2_1);
56#endif
57

source code of glibc/sysdeps/unix/sysv/linux/alpha/getrlimit64.c