syscall.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Hexagon system calls
  3. *
  4. * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 and
  8. * only version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. * 02110-1301, USA.
  19. */
  20. #include <linux/file.h>
  21. #include <linux/fs.h>
  22. #include <linux/linkage.h>
  23. #include <linux/mm.h>
  24. #include <linux/module.h>
  25. #include <linux/sched.h>
  26. #include <linux/slab.h>
  27. #include <linux/syscalls.h>
  28. #include <linux/unistd.h>
  29. #include <asm/mman.h>
  30. #include <asm/registers.h>
  31. /*
  32. * System calls with architecture-specific wrappers.
  33. * See signal.c for signal-related system call wrappers.
  34. */
  35. asmlinkage int sys_execve(char __user *ufilename,
  36. const char __user *const __user *argv,
  37. const char __user *const __user *envp)
  38. {
  39. struct pt_regs *pregs = current_thread_info()->regs;
  40. char *filename;
  41. int retval;
  42. filename = getname(ufilename);
  43. retval = PTR_ERR(filename);
  44. if (IS_ERR(filename))
  45. return retval;
  46. retval = do_execve(filename, argv, envp, pregs);
  47. putname(filename);
  48. return retval;
  49. }
  50. asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
  51. unsigned long parent_tidp, unsigned long child_tidp)
  52. {
  53. struct pt_regs *pregs = current_thread_info()->regs;
  54. if (!newsp)
  55. newsp = pregs->SP;
  56. return do_fork(clone_flags, newsp, pregs, 0, (int __user *)parent_tidp,
  57. (int __user *)child_tidp);
  58. }
  59. /*
  60. * Do a system call from the kernel, so as to have a proper pt_regs
  61. * and recycle the sys_execvpe infrustructure.
  62. */
  63. int kernel_execve(const char *filename,
  64. const char *const argv[], const char *const envp[])
  65. {
  66. register unsigned long __a0 asm("r0") = (unsigned long) filename;
  67. register unsigned long __a1 asm("r1") = (unsigned long) argv;
  68. register unsigned long __a2 asm("r2") = (unsigned long) envp;
  69. int retval;
  70. __asm__ volatile(
  71. " R6 = #%4;\n"
  72. " trap0(#1);\n"
  73. " %0 = R0;\n"
  74. : "=r" (retval)
  75. : "r" (__a0), "r" (__a1), "r" (__a2), "i" (__NR_execve)
  76. );
  77. return retval;
  78. }
  79. EXPORT_SYMBOL(kernel_execve);