sys.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * AArch64-specific system calls implementation
  3. *
  4. * Copyright (C) 2012 ARM Ltd.
  5. * Author: Catalin Marinas <catalin.marinas@arm.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 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/compiler.h>
  20. #include <linux/errno.h>
  21. #include <linux/fs.h>
  22. #include <linux/mm.h>
  23. #include <linux/export.h>
  24. #include <linux/sched.h>
  25. #include <linux/slab.h>
  26. #include <linux/syscalls.h>
  27. /*
  28. * Clone a task - this clones the calling program thread.
  29. */
  30. asmlinkage long sys_clone(unsigned long clone_flags, unsigned long newsp,
  31. int __user *parent_tidptr, unsigned long tls_val,
  32. int __user *child_tidptr, struct pt_regs *regs)
  33. {
  34. if (!newsp)
  35. newsp = regs->sp;
  36. /* 16-byte aligned stack mandatory on AArch64 */
  37. if (newsp & 15)
  38. return -EINVAL;
  39. return do_fork(clone_flags, newsp, regs, 0, parent_tidptr, child_tidptr);
  40. }
  41. /*
  42. * sys_execve() executes a new program.
  43. */
  44. asmlinkage long sys_execve(const char __user *filenamei,
  45. const char __user *const __user *argv,
  46. const char __user *const __user *envp,
  47. struct pt_regs *regs)
  48. {
  49. long error;
  50. struct filename *filename;
  51. filename = getname(filenamei);
  52. error = PTR_ERR(filename);
  53. if (IS_ERR(filename))
  54. goto out;
  55. error = do_execve(filename->name, argv, envp, regs);
  56. putname(filename);
  57. out:
  58. return error;
  59. }
  60. int kernel_execve(const char *filename,
  61. const char *const argv[],
  62. const char *const envp[])
  63. {
  64. struct pt_regs regs;
  65. int ret;
  66. memset(&regs, 0, sizeof(struct pt_regs));
  67. ret = do_execve(filename,
  68. (const char __user *const __user *)argv,
  69. (const char __user *const __user *)envp, &regs);
  70. if (ret < 0)
  71. goto out;
  72. /*
  73. * Save argc to the register structure for userspace.
  74. */
  75. regs.regs[0] = ret;
  76. /*
  77. * We were successful. We won't be returning to our caller, but
  78. * instead to user space by manipulating the kernel stack.
  79. */
  80. asm( "add x0, %0, %1\n\t"
  81. "mov x1, %2\n\t"
  82. "mov x2, %3\n\t"
  83. "bl memmove\n\t" /* copy regs to top of stack */
  84. "mov x27, #0\n\t" /* not a syscall */
  85. "mov x28, %0\n\t" /* thread structure */
  86. "mov sp, x0\n\t" /* reposition stack pointer */
  87. "b ret_to_user"
  88. :
  89. : "r" (current_thread_info()),
  90. "Ir" (THREAD_START_SP - sizeof(regs)),
  91. "r" (&regs),
  92. "Ir" (sizeof(regs))
  93. : "x0", "x1", "x2", "x27", "x28", "x30", "memory");
  94. out:
  95. return ret;
  96. }
  97. EXPORT_SYMBOL(kernel_execve);
  98. asmlinkage long sys_mmap(unsigned long addr, unsigned long len,
  99. unsigned long prot, unsigned long flags,
  100. unsigned long fd, off_t off)
  101. {
  102. if (offset_in_page(off) != 0)
  103. return -EINVAL;
  104. return sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
  105. }
  106. /*
  107. * Wrappers to pass the pt_regs argument.
  108. */
  109. #define sys_execve sys_execve_wrapper
  110. #define sys_clone sys_clone_wrapper
  111. #define sys_rt_sigreturn sys_rt_sigreturn_wrapper
  112. #define sys_sigaltstack sys_sigaltstack_wrapper
  113. #include <asm/syscalls.h>
  114. #undef __SYSCALL
  115. #define __SYSCALL(nr, sym) [nr] = sym,
  116. /*
  117. * The sys_call_table array must be 4K aligned to be accessible from
  118. * kernel/entry.S.
  119. */
  120. void *sys_call_table[__NR_syscalls] __aligned(4096) = {
  121. [0 ... __NR_syscalls - 1] = sys_ni_syscall,
  122. #include <asm/unistd.h>
  123. };