sys_arm.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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/slab.h>
  19. #include <linux/mm.h>
  20. #include <linux/sem.h>
  21. #include <linux/msg.h>
  22. #include <linux/shm.h>
  23. #include <linux/stat.h>
  24. #include <linux/syscalls.h>
  25. #include <linux/mman.h>
  26. #include <linux/fs.h>
  27. #include <linux/file.h>
  28. #include <linux/ipc.h>
  29. #include <linux/uaccess.h>
  30. #if !defined(CONFIG_AEABI) || defined(CONFIG_OABI_COMPAT)
  31. /*
  32. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  33. *
  34. * This is really horribly ugly.
  35. */
  36. asmlinkage int sys_ipc(uint call, int first, int second, int third,
  37. void __user *ptr, long fifth)
  38. {
  39. int version, ret;
  40. version = call >> 16; /* hack for backward compatibility */
  41. call &= 0xffff;
  42. switch (call) {
  43. case SEMOP:
  44. return sys_semtimedop (first, (struct sembuf __user *)ptr, second, NULL);
  45. case SEMTIMEDOP:
  46. return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
  47. (const struct timespec __user *)fifth);
  48. case SEMGET:
  49. return sys_semget (first, second, third);
  50. case SEMCTL: {
  51. union semun fourth;
  52. if (!ptr)
  53. return -EINVAL;
  54. if (get_user(fourth.__pad, (void __user * __user *) ptr))
  55. return -EFAULT;
  56. return sys_semctl (first, second, third, fourth);
  57. }
  58. case MSGSND:
  59. return sys_msgsnd(first, (struct msgbuf __user *) ptr,
  60. second, third);
  61. case MSGRCV:
  62. switch (version) {
  63. case 0: {
  64. struct ipc_kludge tmp;
  65. if (!ptr)
  66. return -EINVAL;
  67. if (copy_from_user(&tmp,(struct ipc_kludge __user *)ptr,
  68. sizeof (tmp)))
  69. return -EFAULT;
  70. return sys_msgrcv (first, tmp.msgp, second,
  71. tmp.msgtyp, third);
  72. }
  73. default:
  74. return sys_msgrcv (first,
  75. (struct msgbuf __user *) ptr,
  76. second, fifth, third);
  77. }
  78. case MSGGET:
  79. return sys_msgget ((key_t) first, second);
  80. case MSGCTL:
  81. return sys_msgctl(first, second, (struct msqid_ds __user *)ptr);
  82. case SHMAT:
  83. switch (version) {
  84. default: {
  85. ulong raddr;
  86. ret = do_shmat(first, (char __user *)ptr, second, &raddr);
  87. if (ret)
  88. return ret;
  89. return put_user(raddr, (ulong __user *)third);
  90. }
  91. case 1: /* Of course, we don't support iBCS2! */
  92. return -EINVAL;
  93. }
  94. case SHMDT:
  95. return sys_shmdt ((char __user *)ptr);
  96. case SHMGET:
  97. return sys_shmget (first, second, third);
  98. case SHMCTL:
  99. return sys_shmctl (first, second,
  100. (struct shmid_ds __user *) ptr);
  101. default:
  102. return -ENOSYS;
  103. }
  104. }
  105. #endif
  106. /* Fork a new task - this creates a new program thread.
  107. * This is called indirectly via a small wrapper
  108. */
  109. asmlinkage int sys_fork(struct pt_regs *regs)
  110. {
  111. #ifdef CONFIG_MMU
  112. return do_fork(SIGCHLD, regs->ARM_sp, regs, 0, NULL, NULL);
  113. #else
  114. /* can not support in nommu mode */
  115. return(-EINVAL);
  116. #endif
  117. }
  118. /* Clone a task - this clones the calling program thread.
  119. * This is called indirectly via a small wrapper
  120. */
  121. asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
  122. int __user *parent_tidptr, int tls_val,
  123. int __user *child_tidptr, struct pt_regs *regs)
  124. {
  125. if (!newsp)
  126. newsp = regs->ARM_sp;
  127. return do_fork(clone_flags, newsp, regs, 0, parent_tidptr, child_tidptr);
  128. }
  129. asmlinkage int sys_vfork(struct pt_regs *regs)
  130. {
  131. return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->ARM_sp, regs, 0, NULL, NULL);
  132. }
  133. /* sys_execve() executes a new program.
  134. * This is called indirectly via a small wrapper
  135. */
  136. asmlinkage int sys_execve(char __user *filenamei, char __user * __user *argv,
  137. char __user * __user *envp, struct pt_regs *regs)
  138. {
  139. int error;
  140. char * filename;
  141. filename = getname(filenamei);
  142. error = PTR_ERR(filename);
  143. if (IS_ERR(filename))
  144. goto out;
  145. error = do_execve(filename, argv, envp, regs);
  146. putname(filename);
  147. out:
  148. return error;
  149. }
  150. int kernel_execve(const char *filename, char *const argv[], char *const envp[])
  151. {
  152. struct pt_regs regs;
  153. int ret;
  154. memset(&regs, 0, sizeof(struct pt_regs));
  155. ret = do_execve((char *)filename, (char __user * __user *)argv,
  156. (char __user * __user *)envp, &regs);
  157. if (ret < 0)
  158. goto out;
  159. /*
  160. * Save argc to the register structure for userspace.
  161. */
  162. regs.ARM_r0 = ret;
  163. /*
  164. * We were successful. We won't be returning to our caller, but
  165. * instead to user space by manipulating the kernel stack.
  166. */
  167. asm( "add r0, %0, %1\n\t"
  168. "mov r1, %2\n\t"
  169. "mov r2, %3\n\t"
  170. "bl memmove\n\t" /* copy regs to top of stack */
  171. "mov r8, #0\n\t" /* not a syscall */
  172. "mov r9, %0\n\t" /* thread structure */
  173. "mov sp, r0\n\t" /* reposition stack pointer */
  174. "b ret_to_user"
  175. :
  176. : "r" (current_thread_info()),
  177. "Ir" (THREAD_START_SP - sizeof(regs)),
  178. "r" (&regs),
  179. "Ir" (sizeof(regs))
  180. : "r0", "r1", "r2", "r3", "ip", "lr", "memory");
  181. out:
  182. return ret;
  183. }
  184. EXPORT_SYMBOL(kernel_execve);
  185. /*
  186. * Since loff_t is a 64 bit type we avoid a lot of ABI hassle
  187. * with a different argument ordering.
  188. */
  189. asmlinkage long sys_arm_fadvise64_64(int fd, int advice,
  190. loff_t offset, loff_t len)
  191. {
  192. return sys_fadvise64_64(fd, offset, len, advice);
  193. }