syscall.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (C) 2012 ARM Ltd.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program 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
  11. * GNU General Public License for more details.
  12. *
  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. #ifndef __ASM_SYSCALL_H
  17. #define __ASM_SYSCALL_H
  18. #include <linux/err.h>
  19. static inline int syscall_get_nr(struct task_struct *task,
  20. struct pt_regs *regs)
  21. {
  22. return regs->syscallno;
  23. }
  24. static inline void syscall_rollback(struct task_struct *task,
  25. struct pt_regs *regs)
  26. {
  27. regs->regs[0] = regs->orig_x0;
  28. }
  29. static inline long syscall_get_error(struct task_struct *task,
  30. struct pt_regs *regs)
  31. {
  32. unsigned long error = regs->regs[0];
  33. return IS_ERR_VALUE(error) ? error : 0;
  34. }
  35. static inline long syscall_get_return_value(struct task_struct *task,
  36. struct pt_regs *regs)
  37. {
  38. return regs->regs[0];
  39. }
  40. static inline void syscall_set_return_value(struct task_struct *task,
  41. struct pt_regs *regs,
  42. int error, long val)
  43. {
  44. regs->regs[0] = (long) error ? error : val;
  45. }
  46. #define SYSCALL_MAX_ARGS 6
  47. static inline void syscall_get_arguments(struct task_struct *task,
  48. struct pt_regs *regs,
  49. unsigned int i, unsigned int n,
  50. unsigned long *args)
  51. {
  52. if (i + n > SYSCALL_MAX_ARGS) {
  53. unsigned long *args_bad = args + SYSCALL_MAX_ARGS - i;
  54. unsigned int n_bad = n + i - SYSCALL_MAX_ARGS;
  55. pr_warning("%s called with max args %d, handling only %d\n",
  56. __func__, i + n, SYSCALL_MAX_ARGS);
  57. memset(args_bad, 0, n_bad * sizeof(args[0]));
  58. }
  59. if (i == 0) {
  60. args[0] = regs->orig_x0;
  61. args++;
  62. i++;
  63. n--;
  64. }
  65. memcpy(args, &regs->regs[i], n * sizeof(args[0]));
  66. }
  67. static inline void syscall_set_arguments(struct task_struct *task,
  68. struct pt_regs *regs,
  69. unsigned int i, unsigned int n,
  70. const unsigned long *args)
  71. {
  72. if (i + n > SYSCALL_MAX_ARGS) {
  73. pr_warning("%s called with max args %d, handling only %d\n",
  74. __func__, i + n, SYSCALL_MAX_ARGS);
  75. n = SYSCALL_MAX_ARGS - i;
  76. }
  77. if (i == 0) {
  78. regs->orig_x0 = args[0];
  79. args++;
  80. i++;
  81. n--;
  82. }
  83. memcpy(&regs->regs[i], args, n * sizeof(args[0]));
  84. }
  85. #endif /* __ASM_SYSCALL_H */