sys_arm.c 6.2 KB

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