syscall.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  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. #ifndef _ASM_ARC_SYSCALL_H
  9. #define _ASM_ARC_SYSCALL_H 1
  10. #include <linux/err.h>
  11. #include <linux/sched.h>
  12. #include <asm/unistd.h>
  13. #include <asm/ptrace.h> /* in_syscall() */
  14. static inline long
  15. syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
  16. {
  17. if (user_mode(regs) && in_syscall(regs))
  18. return regs->orig_r8;
  19. else
  20. return -1;
  21. }
  22. static inline void
  23. syscall_rollback(struct task_struct *task, struct pt_regs *regs)
  24. {
  25. /* XXX: I can't fathom how pt_regs->r8 will be clobbered ? */
  26. regs->r8 = regs->orig_r8;
  27. }
  28. static inline long
  29. syscall_get_error(struct task_struct *task, struct pt_regs *regs)
  30. {
  31. /* 0 if syscall succeeded, otherwise -Errorcode */
  32. return IS_ERR_VALUE(regs->r0) ? regs->r0 : 0;
  33. }
  34. static inline long
  35. syscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
  36. {
  37. return regs->r0;
  38. }
  39. static inline void
  40. syscall_set_return_value(struct task_struct *task, struct pt_regs *regs,
  41. int error, long val)
  42. {
  43. regs->r0 = (long) error ?: val;
  44. }
  45. /*
  46. * @i: argument index [0,5]
  47. * @n: number of arguments; n+i must be [1,6].
  48. */
  49. static inline void
  50. syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
  51. unsigned int i, unsigned int n, unsigned long *args)
  52. {
  53. unsigned long *inside_ptregs = &(regs->r0);
  54. inside_ptregs -= i;
  55. BUG_ON((i + n) > 6);
  56. while (n--) {
  57. args[i++] = (*inside_ptregs);
  58. inside_ptregs--;
  59. }
  60. }
  61. #endif