syscall.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* syscall parameter access functions
  2. *
  3. * Copyright (C) 2009 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. */
  11. #ifndef _ASM_SYSCALL_H
  12. #define _ASM_SYSCALL_H
  13. #include <linux/err.h>
  14. #include <asm/ptrace.h>
  15. /*
  16. * Get the system call number or -1
  17. */
  18. static inline long syscall_get_nr(struct task_struct *task,
  19. struct pt_regs *regs)
  20. {
  21. return regs->syscallno;
  22. }
  23. /*
  24. * Restore the clobbered GR8 register
  25. * (1st syscall arg was overwritten with syscall return or error)
  26. */
  27. static inline void syscall_rollback(struct task_struct *task,
  28. struct pt_regs *regs)
  29. {
  30. regs->gr8 = regs->orig_gr8;
  31. }
  32. /*
  33. * See if the syscall return value is an error, returning it if it is and 0 if
  34. * not
  35. */
  36. static inline long syscall_get_error(struct task_struct *task,
  37. struct pt_regs *regs)
  38. {
  39. return IS_ERR_VALUE(regs->gr8) ? regs->gr8 : 0;
  40. }
  41. /*
  42. * Get the syscall return value
  43. */
  44. static inline long syscall_get_return_value(struct task_struct *task,
  45. struct pt_regs *regs)
  46. {
  47. return regs->gr8;
  48. }
  49. /*
  50. * Set the syscall return value
  51. */
  52. static inline void syscall_set_return_value(struct task_struct *task,
  53. struct pt_regs *regs,
  54. int error, long val)
  55. {
  56. if (error)
  57. regs->gr8 = -error;
  58. else
  59. regs->gr8 = val;
  60. }
  61. /*
  62. * Retrieve the system call arguments
  63. */
  64. static inline void syscall_get_arguments(struct task_struct *task,
  65. struct pt_regs *regs,
  66. unsigned int i, unsigned int n,
  67. unsigned long *args)
  68. {
  69. /*
  70. * Do this simply for now. If we need to start supporting
  71. * fetching arguments from arbitrary indices, this will need some
  72. * extra logic. Presently there are no in-tree users that depend
  73. * on this behaviour.
  74. */
  75. BUG_ON(i);
  76. /* Argument pattern is: GR8, GR9, GR10, GR11, GR12, GR13 */
  77. switch (n) {
  78. case 6: args[5] = regs->gr13;
  79. case 5: args[4] = regs->gr12;
  80. case 4: args[3] = regs->gr11;
  81. case 3: args[2] = regs->gr10;
  82. case 2: args[1] = regs->gr9;
  83. case 1: args[0] = regs->gr8;
  84. break;
  85. default:
  86. BUG();
  87. }
  88. }
  89. /*
  90. * Alter the system call arguments
  91. */
  92. static inline void syscall_set_arguments(struct task_struct *task,
  93. struct pt_regs *regs,
  94. unsigned int i, unsigned int n,
  95. const unsigned long *args)
  96. {
  97. /* Same note as above applies */
  98. BUG_ON(i);
  99. switch (n) {
  100. case 6: regs->gr13 = args[5];
  101. case 5: regs->gr12 = args[4];
  102. case 4: regs->gr11 = args[3];
  103. case 3: regs->gr10 = args[2];
  104. case 2: regs->gr9 = args[1];
  105. case 1: regs->gr8 = args[0];
  106. break;
  107. default:
  108. BUG();
  109. }
  110. }
  111. #endif /* _ASM_SYSCALL_H */