sys_arm.c 7.4 KB

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