syscall.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Access to user system call parameters and results
  3. *
  4. * Copyright (C) 2008 Red Hat, Inc. All rights reserved.
  5. *
  6. * This copyrighted material is made available to anyone wishing to use,
  7. * modify, copy, or redistribute it subject to the terms and conditions
  8. * of the GNU General Public License v.2.
  9. *
  10. * See asm-generic/syscall.h for descriptions of what we must do here.
  11. */
  12. #ifndef _ASM_SYSCALL_H
  13. #define _ASM_SYSCALL_H 1
  14. #include <linux/sched.h>
  15. static inline long syscall_get_nr(struct task_struct *task,
  16. struct pt_regs *regs)
  17. {
  18. return TRAP(regs) == 0xc00 ? regs->gpr[0] : -1L;
  19. }
  20. static inline void syscall_rollback(struct task_struct *task,
  21. struct pt_regs *regs)
  22. {
  23. regs->gpr[3] = regs->orig_gpr3;
  24. }
  25. static inline long syscall_get_error(struct task_struct *task,
  26. struct pt_regs *regs)
  27. {
  28. return (regs->ccr & 0x1000) ? -regs->gpr[3] : 0;
  29. }
  30. static inline long syscall_get_return_value(struct task_struct *task,
  31. struct pt_regs *regs)
  32. {
  33. return regs->gpr[3];
  34. }
  35. static inline void syscall_set_return_value(struct task_struct *task,
  36. struct pt_regs *regs,
  37. int error, long val)
  38. {
  39. if (error) {
  40. regs->ccr |= 0x1000L;
  41. regs->gpr[3] = -error;
  42. } else {
  43. regs->ccr &= ~0x1000L;
  44. regs->gpr[3] = val;
  45. }
  46. }
  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. BUG_ON(i + n > 6);
  53. #ifdef CONFIG_PPC64
  54. if (test_tsk_thread_flag(task, TIF_32BIT)) {
  55. /*
  56. * Zero-extend 32-bit argument values. The high bits are
  57. * garbage ignored by the actual syscall dispatch.
  58. */
  59. while (n-- > 0)
  60. args[n] = (u32) regs->gpr[3 + i + n];
  61. return;
  62. }
  63. #endif
  64. memcpy(args, &regs->gpr[3 + i], n * sizeof(args[0]));
  65. }
  66. static inline void syscall_set_arguments(struct task_struct *task,
  67. struct pt_regs *regs,
  68. unsigned int i, unsigned int n,
  69. const unsigned long *args)
  70. {
  71. BUG_ON(i + n > 6);
  72. memcpy(&regs->gpr[3 + i], args, n * sizeof(args[0]));
  73. }
  74. #endif /* _ASM_SYSCALL_H */