syscall.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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->r8;
  19. else
  20. return -1;
  21. }
  22. static inline void
  23. syscall_rollback(struct task_struct *task, struct pt_regs *regs)
  24. {
  25. regs->r0 = regs->orig_r0;
  26. }
  27. static inline long
  28. syscall_get_error(struct task_struct *task, struct pt_regs *regs)
  29. {
  30. /* 0 if syscall succeeded, otherwise -Errorcode */
  31. return IS_ERR_VALUE(regs->r0) ? regs->r0 : 0;
  32. }
  33. static inline long
  34. syscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
  35. {
  36. return regs->r0;
  37. }
  38. static inline void
  39. syscall_set_return_value(struct task_struct *task, struct pt_regs *regs,
  40. int error, long val)
  41. {
  42. regs->r0 = (long) error ?: val;
  43. }
  44. /*
  45. * @i: argument index [0,5]
  46. * @n: number of arguments; n+i must be [1,6].
  47. */
  48. static inline void
  49. syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
  50. unsigned int i, unsigned int n, unsigned long *args)
  51. {
  52. unsigned long *inside_ptregs = &(regs->r0);
  53. inside_ptregs -= i;
  54. BUG_ON((i + n) > 6);
  55. while (n--) {
  56. args[i++] = (*inside_ptregs);
  57. inside_ptregs--;
  58. }
  59. }
  60. #endif