hurdrlimit.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* Resource limits.
  2. Copyright (C) 1994-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  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. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #include <hurd.h>
  16. #include <lock-intern.h>
  17. #include <hurd/resource.h>
  18. #include "set-hooks.h"
  19. /* This must be given an initializer, or the a.out linking rules will
  20. not include the entire file when this symbol is referenced. */
  21. struct rlimit _hurd_rlimits[RLIM_NLIMITS] = { { 0, }, };
  22. /* This must be initialized data for the same reason as above, but this is
  23. intentionally initialized to a bogus value to emphasize the point that
  24. mutex_init is still required below just in case of unexec. */
  25. struct mutex _hurd_rlimit_lock = { SPIN_LOCK_INITIALIZER, };
  26. static void attribute_used_retain
  27. init_rlimit (void)
  28. {
  29. int i;
  30. __mutex_init (&_hurd_rlimit_lock);
  31. #ifdef HAVE_MACH_VM_GET_SIZE_LIMIT
  32. vm_size_t current, max;
  33. if (__vm_get_size_limit (__mach_task_self (), &current, &max) == KERN_SUCCESS)
  34. {
  35. _hurd_rlimits[RLIMIT_AS].rlim_cur = current;
  36. _hurd_rlimits[RLIMIT_AS].rlim_max = max;
  37. }
  38. #endif
  39. for (i = 0; i < RLIM_NLIMITS; ++i)
  40. {
  41. if (_hurd_rlimits[i].rlim_max == 0)
  42. _hurd_rlimits[i].rlim_max = RLIM_INFINITY;
  43. if (_hurd_rlimits[i].rlim_cur == 0)
  44. #define I(lim, val) case RLIMIT_##lim: _hurd_rlimits[i].rlim_cur = (val); break
  45. switch (i)
  46. {
  47. I (NOFILE, 1024); /* Linux 2.2.12 uses this initial value. */
  48. default:
  49. _hurd_rlimits[i].rlim_cur = _hurd_rlimits[i].rlim_max;
  50. break;
  51. }
  52. #undef I
  53. }
  54. }
  55. SET_RELHOOK (_hurd_preinit_hook, init_rlimit);