syscall.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (C) 2008-2009 Red Hat, Inc. All rights reserved.
  3. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation, version 2.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  12. * NON INFRINGEMENT. See the GNU General Public License for
  13. * more details.
  14. *
  15. * See asm-generic/syscall.h for descriptions of what we must do here.
  16. */
  17. #ifndef _ASM_TILE_SYSCALL_H
  18. #define _ASM_TILE_SYSCALL_H
  19. #include <linux/sched.h>
  20. #include <linux/err.h>
  21. #include <linux/audit.h>
  22. #include <linux/compat.h>
  23. #include <arch/abi.h>
  24. /* The array of function pointers for syscalls. */
  25. extern void *sys_call_table[];
  26. #ifdef CONFIG_COMPAT
  27. extern void *compat_sys_call_table[];
  28. #endif
  29. /*
  30. * Only the low 32 bits of orig_r0 are meaningful, so we return int.
  31. * This importantly ignores the high bits on 64-bit, so comparisons
  32. * sign-extend the low 32 bits.
  33. */
  34. static inline int syscall_get_nr(struct task_struct *t, struct pt_regs *regs)
  35. {
  36. return regs->regs[TREG_SYSCALL_NR];
  37. }
  38. static inline void syscall_rollback(struct task_struct *task,
  39. struct pt_regs *regs)
  40. {
  41. regs->regs[0] = regs->orig_r0;
  42. }
  43. static inline long syscall_get_error(struct task_struct *task,
  44. struct pt_regs *regs)
  45. {
  46. unsigned long error = regs->regs[0];
  47. return IS_ERR_VALUE(error) ? error : 0;
  48. }
  49. static inline long syscall_get_return_value(struct task_struct *task,
  50. struct pt_regs *regs)
  51. {
  52. return regs->regs[0];
  53. }
  54. static inline void syscall_set_return_value(struct task_struct *task,
  55. struct pt_regs *regs,
  56. int error, long val)
  57. {
  58. if (error) {
  59. /* R0 is the passed-in negative error, R1 is positive. */
  60. regs->regs[0] = error;
  61. regs->regs[1] = -error;
  62. } else {
  63. /* R1 set to zero to indicate no error. */
  64. regs->regs[0] = val;
  65. regs->regs[1] = 0;
  66. }
  67. }
  68. static inline void syscall_get_arguments(struct task_struct *task,
  69. struct pt_regs *regs,
  70. unsigned int i, unsigned int n,
  71. unsigned long *args)
  72. {
  73. BUG_ON(i + n > 6);
  74. memcpy(args, &regs[i], n * sizeof(args[0]));
  75. }
  76. static inline void syscall_set_arguments(struct task_struct *task,
  77. struct pt_regs *regs,
  78. unsigned int i, unsigned int n,
  79. const unsigned long *args)
  80. {
  81. BUG_ON(i + n > 6);
  82. memcpy(&regs[i], args, n * sizeof(args[0]));
  83. }
  84. /*
  85. * We don't care about endianness (__AUDIT_ARCH_LE bit) here because
  86. * tile has the same system calls both on little- and big- endian.
  87. */
  88. static inline int syscall_get_arch(void)
  89. {
  90. if (is_compat_task())
  91. return AUDIT_ARCH_TILEGX32;
  92. #ifdef CONFIG_TILEGX
  93. return AUDIT_ARCH_TILEGX;
  94. #else
  95. return AUDIT_ARCH_TILEPRO;
  96. #endif
  97. }
  98. #endif /* _ASM_TILE_SYSCALL_H */