shim_getrlimit.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. /* Copyright (C) 2014 Stony Brook University
  4. This file is part of Graphene Library OS.
  5. Graphene Library OS is free software: you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public License
  7. as published by the Free Software Foundation, either version 3 of the
  8. License, or (at your option) any later version.
  9. Graphene Library OS 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
  12. GNU Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. /*
  16. * shim_getrlimit.c
  17. *
  18. * Implementation of system call "getrlimit" and "setrlimit".
  19. */
  20. #include <shim_internal.h>
  21. #include <shim_table.h>
  22. #include <shim_utils.h>
  23. #include <shim_vma.h>
  24. #include <asm/resource.h>
  25. unsigned int max_fds = DEFAULT_MAX_FDS;
  26. int shim_do_getrlimit (int resource, struct __kernel_rlimit * rlim)
  27. {
  28. switch (resource) {
  29. case RLIMIT_NOFILE:
  30. rlim->rlim_cur = max_fds;
  31. rlim->rlim_max = MAX_MAX_FDS;
  32. return 0;
  33. case RLIMIT_RSS:
  34. rlim->rlim_cur = RLIM_INFINITY;
  35. rlim->rlim_max = RLIM_INFINITY;
  36. return 0;
  37. case RLIMIT_AS:
  38. rlim->rlim_cur = RLIM_INFINITY;
  39. rlim->rlim_max = RLIM_INFINITY;
  40. return 0;
  41. case RLIMIT_STACK:
  42. rlim->rlim_cur = sys_stack_size;
  43. rlim->rlim_max = sys_stack_size;
  44. return 0;
  45. case RLIMIT_DATA:
  46. rlim->rlim_cur = brk_max_size;
  47. rlim->rlim_max = brk_max_size;
  48. return 0;
  49. default:
  50. return -ENOSYS;
  51. }
  52. }
  53. int shim_do_setrlimit (int resource, struct __kernel_rlimit * rlim)
  54. {
  55. switch (resource) {
  56. case RLIMIT_NOFILE:
  57. if (rlim->rlim_cur > MAX_MAX_FDS)
  58. return -EINVAL;
  59. max_fds = rlim->rlim_cur;
  60. return 0;
  61. case RLIMIT_STACK:
  62. sys_stack_size = rlim->rlim_cur;
  63. return 0;
  64. default:
  65. return -ENOSYS;
  66. }
  67. }