sys_arm.c 8.2 KB

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