sys_arm.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * linux/arch/arm/kernel/sys_arm.c
  3. *
  4. * Copyright (C) People who wrote linux/arch/i386/kernel/sys_i386.c
  5. * Copyright (C) 1995, 1996 Russell King.
  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 file contains various random system calls that
  12. * have a non-standard calling sequence on the Linux/arm
  13. * platform.
  14. */
  15. #include <linux/module.h>
  16. #include <linux/errno.h>
  17. #include <linux/sched.h>
  18. #include <linux/mm.h>
  19. #include <linux/sem.h>
  20. #include <linux/msg.h>
  21. #include <linux/shm.h>
  22. #include <linux/stat.h>
  23. #include <linux/syscalls.h>
  24. #include <linux/mman.h>
  25. #include <linux/fs.h>
  26. #include <linux/file.h>
  27. #include <linux/ipc.h>
  28. #include <linux/uaccess.h>
  29. #include <linux/slab.h>
  30. /* Fork a new task - this creates a new program thread.
  31. * This is called indirectly via a small wrapper
  32. */
  33. asmlinkage int sys_fork(struct pt_regs *regs)
  34. {
  35. #ifdef CONFIG_MMU
  36. return do_fork(SIGCHLD, regs->ARM_sp, regs, 0, NULL, NULL);
  37. #else
  38. /* can not support in nommu mode */
  39. return(-EINVAL);
  40. #endif
  41. }
  42. /* Clone a task - this clones the calling program thread.
  43. * This is called indirectly via a small wrapper
  44. */
  45. asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
  46. int __user *parent_tidptr, int tls_val,
  47. int __user *child_tidptr, struct pt_regs *regs)
  48. {
  49. if (!newsp)
  50. newsp = regs->ARM_sp;
  51. return do_fork(clone_flags, newsp, regs, 0, parent_tidptr, child_tidptr);
  52. }
  53. asmlinkage int sys_vfork(struct pt_regs *regs)
  54. {
  55. return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->ARM_sp, regs, 0, NULL, NULL);
  56. }
  57. /* sys_execve() executes a new program.
  58. * This is called indirectly via a small wrapper
  59. */
  60. asmlinkage int sys_execve(char __user *filenamei, char __user * __user *argv,
  61. char __user * __user *envp, struct pt_regs *regs)
  62. {
  63. int error;
  64. char * filename;
  65. filename = getname(filenamei);
  66. error = PTR_ERR(filename);
  67. if (IS_ERR(filename))
  68. goto out;
  69. error = do_execve(filename, argv, envp, regs);
  70. putname(filename);
  71. out:
  72. return error;
  73. }
  74. int kernel_execve(const char *filename, char *const argv[], char *const envp[])
  75. {
  76. struct pt_regs regs;
  77. int ret;
  78. memset(&regs, 0, sizeof(struct pt_regs));
  79. ret = do_execve((char *)filename, (char __user * __user *)argv,
  80. (char __user * __user *)envp, &regs);
  81. if (ret < 0)
  82. goto out;
  83. /*
  84. * Save argc to the register structure for userspace.
  85. */
  86. regs.ARM_r0 = ret;
  87. /*
  88. * We were successful. We won't be returning to our caller, but
  89. * instead to user space by manipulating the kernel stack.
  90. */
  91. asm( "add r0, %0, %1\n\t"
  92. "mov r1, %2\n\t"
  93. "mov r2, %3\n\t"
  94. "bl memmove\n\t" /* copy regs to top of stack */
  95. "mov r8, #0\n\t" /* not a syscall */
  96. "mov r9, %0\n\t" /* thread structure */
  97. "mov sp, r0\n\t" /* reposition stack pointer */
  98. "b ret_to_user"
  99. :
  100. : "r" (current_thread_info()),
  101. "Ir" (THREAD_START_SP - sizeof(regs)),
  102. "r" (&regs),
  103. "Ir" (sizeof(regs))
  104. : "r0", "r1", "r2", "r3", "ip", "lr", "memory");
  105. out:
  106. return ret;
  107. }
  108. EXPORT_SYMBOL(kernel_execve);
  109. /*
  110. * Since loff_t is a 64 bit type we avoid a lot of ABI hassle
  111. * with a different argument ordering.
  112. */
  113. asmlinkage long sys_arm_fadvise64_64(int fd, int advice,
  114. loff_t offset, loff_t len)
  115. {
  116. return sys_fadvise64_64(fd, offset, len, advice);
  117. }