shim_getrlimit.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 OSCAR lab, 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 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 General Public License for more details.
  13. You should have received a copy of the GNU 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. default:
  46. return -ENOSYS;
  47. }
  48. }
  49. int shim_do_setrlimit (int resource, struct __kernel_rlimit * rlim)
  50. {
  51. switch (resource) {
  52. case RLIMIT_NOFILE:
  53. if (rlim->rlim_cur > MAX_MAX_FDS)
  54. return -EINVAL;
  55. max_fds = rlim->rlim_cur;
  56. return 0;
  57. case RLIMIT_STACK:
  58. sys_stack_size = rlim->rlim_cur;
  59. return 0;
  60. default:
  61. return -ENOSYS;
  62. }
  63. }