(root)/
glibc-2.38/
sysdeps/
unix/
sysv/
linux/
getrlimit64.c
       1  /* Linux getrlimit64 implementation (64 bits rlim_t).
       2     Copyright (C) 2010-2023 Free Software Foundation, Inc.
       3     This file is part of the GNU C Library.
       4  
       5     The GNU C Library is free software; you can redistribute it and/or
       6     modify it under the terms of the GNU Lesser General Public
       7     License as published by the Free Software Foundation; either
       8     version 2.1 of the License, or (at your option) any later version.
       9  
      10     The GNU C Library is distributed in the hope that it will be useful,
      11     but WITHOUT ANY WARRANTY; without even the implied warranty of
      12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13     Lesser General Public License for more details.
      14  
      15     You should have received a copy of the GNU Lesser General Public
      16     License along with the GNU C Library; if not, see
      17     <https://www.gnu.org/licenses/>.  */
      18  
      19  #include <errno.h>
      20  #include <sys/types.h>
      21  #include <sysdep.h>
      22  #include <shlib-compat.h>
      23  
      24  /* Add this redirection so the strong_alias for __RLIM_T_MATCHES_RLIM64_T
      25     linking getrlimit64 to {__}getrlimit does not throw a type error.  */
      26  #undef getrlimit
      27  #undef __getrlimit
      28  #define getrlimit getrlimit_redirect
      29  #define __getrlimit __getrlimit_redirect
      30  #include <sys/resource.h>
      31  #undef getrlimit
      32  #undef __getrlimit
      33  
      34  /* Put the soft and hard limits for RESOURCE in *RLIMITS.
      35     Returns 0 if successful, -1 if not (and sets errno).  */
      36  int
      37  __getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits)
      38  {
      39    return INLINE_SYSCALL_CALL (prlimit64, 0, resource, NULL, rlimits);
      40  }
      41  libc_hidden_def (__getrlimit64)
      42  
      43  #if __RLIM_T_MATCHES_RLIM64_T
      44  /* If both rlim_t and rlimt64_t are essentially the same type we can use
      45     alias both interfaces.  */
      46  strong_alias (__getrlimit64, __GI_getrlimit)
      47  strong_alias (__getrlimit64, __GI___getrlimit)
      48  strong_alias (__getrlimit64, __getrlimit)
      49  /* Alpha defines a versioned getrlimit{64}.  */
      50  # ifndef USE_VERSIONED_RLIMIT
      51  weak_alias (__getrlimit64, getrlimit)
      52  weak_alias (__getrlimit64, getrlimit64)
      53  libc_hidden_weak (getrlimit64)
      54  # else
      55  weak_alias (__getrlimit64, __GI_getrlimit64)
      56  # endif
      57  
      58  #elif SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_2)
      59  /* Back compatible 2GiB limited rlimit.  */
      60  extern int __new_getrlimit (enum __rlimit_resource, struct rlimit *)
      61    attribute_hidden;
      62  
      63  int
      64  attribute_compat_text_section
      65  __old_getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits)
      66  {
      67    struct rlimit rlimits32;
      68  
      69    if (__new_getrlimit (resource, &rlimits32) < 0)
      70      return -1;
      71  
      72    if (rlimits32.rlim_cur == RLIM_INFINITY)
      73      rlimits->rlim_cur = RLIM64_INFINITY >> 1;
      74    else
      75      rlimits->rlim_cur = rlimits32.rlim_cur;
      76    if (rlimits32.rlim_max == RLIM_INFINITY)
      77      rlimits->rlim_max = RLIM64_INFINITY >> 1;
      78    else
      79      rlimits->rlim_max = rlimits32.rlim_max;
      80  
      81    return 0;
      82  }
      83  versioned_symbol (libc, __getrlimit64, getrlimit64, GLIBC_2_2);
      84  compat_symbol (libc, __old_getrlimit64, getrlimit64, GLIBC_2_1);
      85  #else
      86  weak_alias (__getrlimit64, getrlimit64)
      87  libc_hidden_weak (getrlimit64)
      88  #endif /* __RLIM_T_MATCHES_RLIM64_T  */