sys_arm.c 6.8 KB

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