syscall.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Access to user system call parameters and results
  3. *
  4. * Copyright IBM Corp. 2008
  5. * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License (version 2 only)
  9. * as published by the Free Software Foundation.
  10. */
  11. #ifndef _ASM_SYSCALL_H
  12. #define _ASM_SYSCALL_H 1
  13. #include <linux/sched.h>
  14. #include <linux/err.h>
  15. #include <asm/ptrace.h>
  16. /*
  17. * The syscall table always contains 32 bit pointers since we know that the
  18. * address of the function to be called is (way) below 4GB. So the "int"
  19. * type here is what we want [need] for both 32 bit and 64 bit systems.
  20. */
  21. extern const unsigned int sys_call_table[];
  22. static inline long syscall_get_nr(struct task_struct *task,
  23. struct pt_regs *regs)
  24. {
  25. return regs->svc_code ? (regs->svc_code & 0xffff) : -1;
  26. }
  27. static inline void syscall_rollback(struct task_struct *task,
  28. struct pt_regs *regs)
  29. {
  30. regs->gprs[2] = regs->orig_gpr2;
  31. }
  32. static inline long syscall_get_error(struct task_struct *task,
  33. struct pt_regs *regs)
  34. {
  35. return IS_ERR_VALUE(regs->gprs[2]) ? regs->gprs[2] : 0;
  36. }
  37. static inline long syscall_get_return_value(struct task_struct *task,
  38. struct pt_regs *regs)
  39. {
  40. return regs->gprs[2];
  41. }
  42. static inline void syscall_set_return_value(struct task_struct *task,
  43. struct pt_regs *regs,
  44. int error, long val)
  45. {
  46. regs->gprs[2] = error ? -error : val;
  47. }
  48. static inline void syscall_get_arguments(struct task_struct *task,
  49. struct pt_regs *regs,
  50. unsigned int i, unsigned int n,
  51. unsigned long *args)
  52. {
  53. unsigned long mask = -1UL;
  54. BUG_ON(i + n > 6);
  55. #ifdef CONFIG_COMPAT
  56. if (test_tsk_thread_flag(task, TIF_31BIT))
  57. mask = 0xffffffff;
  58. #endif
  59. while (n-- > 0)
  60. if (i + n > 0)
  61. args[n] = regs->gprs[2 + i + n] & mask;
  62. if (i == 0)
  63. args[0] = regs->orig_gpr2 & mask;
  64. }
  65. static inline void syscall_set_arguments(struct task_struct *task,
  66. struct pt_regs *regs,
  67. unsigned int i, unsigned int n,
  68. const unsigned long *args)
  69. {
  70. BUG_ON(i + n > 6);
  71. while (n-- > 0)
  72. if (i + n > 0)
  73. regs->gprs[2 + i + n] = args[n];
  74. if (i == 0)
  75. regs->orig_gpr2 = args[0];
  76. }
  77. #endif /* _ASM_SYSCALL_H */