syscall.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* Access to user system call parameters and results
  2. *
  3. * See asm-generic/syscall.h for function descriptions.
  4. *
  5. * Copyright (C) 2010 Red Hat, Inc. All Rights Reserved.
  6. * Written by David Howells (dhowells@redhat.com)
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public Licence
  10. * as published by the Free Software Foundation; either version
  11. * 2 of the Licence, or (at your option) any later version.
  12. */
  13. #ifndef _ASM_SYSCALL_H
  14. #define _ASM_SYSCALL_H
  15. #include <linux/sched.h>
  16. #include <linux/err.h>
  17. extern const unsigned long sys_call_table[];
  18. static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
  19. {
  20. return regs->orig_d0;
  21. }
  22. static inline void syscall_rollback(struct task_struct *task,
  23. struct pt_regs *regs)
  24. {
  25. regs->d0 = regs->orig_d0;
  26. }
  27. static inline long syscall_get_error(struct task_struct *task,
  28. struct pt_regs *regs)
  29. {
  30. unsigned long error = regs->d0;
  31. return IS_ERR_VALUE(error) ? error : 0;
  32. }
  33. static inline long syscall_get_return_value(struct task_struct *task,
  34. struct pt_regs *regs)
  35. {
  36. return regs->d0;
  37. }
  38. static inline void syscall_set_return_value(struct task_struct *task,
  39. struct pt_regs *regs,
  40. int error, long val)
  41. {
  42. regs->d0 = (long) error ?: val;
  43. }
  44. static inline void syscall_get_arguments(struct task_struct *task,
  45. struct pt_regs *regs,
  46. unsigned int i, unsigned int n,
  47. unsigned long *args)
  48. {
  49. switch (i) {
  50. case 0:
  51. if (!n--) break;
  52. *args++ = regs->a0;
  53. case 1:
  54. if (!n--) break;
  55. *args++ = regs->d1;
  56. case 2:
  57. if (!n--) break;
  58. *args++ = regs->a3;
  59. case 3:
  60. if (!n--) break;
  61. *args++ = regs->a2;
  62. case 4:
  63. if (!n--) break;
  64. *args++ = regs->d3;
  65. case 5:
  66. if (!n--) break;
  67. *args++ = regs->d2;
  68. case 6:
  69. if (!n--) break;
  70. default:
  71. BUG();
  72. break;
  73. }
  74. }
  75. static inline void syscall_set_arguments(struct task_struct *task,
  76. struct pt_regs *regs,
  77. unsigned int i, unsigned int n,
  78. const unsigned long *args)
  79. {
  80. switch (i) {
  81. case 0:
  82. if (!n--) break;
  83. regs->a0 = *args++;
  84. case 1:
  85. if (!n--) break;
  86. regs->d1 = *args++;
  87. case 2:
  88. if (!n--) break;
  89. regs->a3 = *args++;
  90. case 3:
  91. if (!n--) break;
  92. regs->a2 = *args++;
  93. case 4:
  94. if (!n--) break;
  95. regs->d3 = *args++;
  96. case 5:
  97. if (!n--) break;
  98. regs->d2 = *args++;
  99. case 6:
  100. if (!n--) break;
  101. default:
  102. BUG();
  103. break;
  104. }
  105. }
  106. #endif /* _ASM_SYSCALL_H */