sys_arm.c 7.4 KB

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