sys_arm.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. /*
  127. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  128. *
  129. * This is really horribly ugly.
  130. */
  131. asmlinkage int sys_ipc(uint call, int first, int second, int third,
  132. void __user *ptr, long fifth)
  133. {
  134. int version, ret;
  135. version = call >> 16; /* hack for backward compatibility */
  136. call &= 0xffff;
  137. switch (call) {
  138. case SEMOP:
  139. return sys_semtimedop (first, (struct sembuf __user *)ptr, second, NULL);
  140. case SEMTIMEDOP:
  141. return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
  142. (const struct timespec __user *)fifth);
  143. case SEMGET:
  144. return sys_semget (first, second, third);
  145. case SEMCTL: {
  146. union semun fourth;
  147. if (!ptr)
  148. return -EINVAL;
  149. if (get_user(fourth.__pad, (void __user * __user *) ptr))
  150. return -EFAULT;
  151. return sys_semctl (first, second, third, fourth);
  152. }
  153. case MSGSND:
  154. return sys_msgsnd(first, (struct msgbuf __user *) ptr,
  155. second, third);
  156. case MSGRCV:
  157. switch (version) {
  158. case 0: {
  159. struct ipc_kludge tmp;
  160. if (!ptr)
  161. return -EINVAL;
  162. if (copy_from_user(&tmp,(struct ipc_kludge __user *)ptr,
  163. sizeof (tmp)))
  164. return -EFAULT;
  165. return sys_msgrcv (first, tmp.msgp, second,
  166. tmp.msgtyp, third);
  167. }
  168. default:
  169. return sys_msgrcv (first,
  170. (struct msgbuf __user *) ptr,
  171. second, fifth, third);
  172. }
  173. case MSGGET:
  174. return sys_msgget ((key_t) first, second);
  175. case MSGCTL:
  176. return sys_msgctl(first, second, (struct msqid_ds __user *)ptr);
  177. case SHMAT:
  178. switch (version) {
  179. default: {
  180. ulong raddr;
  181. ret = do_shmat(first, (char __user *)ptr, second, &raddr);
  182. if (ret)
  183. return ret;
  184. return put_user(raddr, (ulong __user *)third);
  185. }
  186. case 1: /* Of course, we don't support iBCS2! */
  187. return -EINVAL;
  188. }
  189. case SHMDT:
  190. return sys_shmdt ((char __user *)ptr);
  191. case SHMGET:
  192. return sys_shmget (first, second, third);
  193. case SHMCTL:
  194. return sys_shmctl (first, second,
  195. (struct shmid_ds __user *) ptr);
  196. default:
  197. return -ENOSYS;
  198. }
  199. }
  200. /* Fork a new task - this creates a new program thread.
  201. * This is called indirectly via a small wrapper
  202. */
  203. asmlinkage int sys_fork(struct pt_regs *regs)
  204. {
  205. return do_fork(SIGCHLD, regs->ARM_sp, regs, 0, NULL, NULL);
  206. }
  207. /* Clone a task - this clones the calling program thread.
  208. * This is called indirectly via a small wrapper
  209. */
  210. asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
  211. int __user *parent_tidptr, int tls_val,
  212. int __user *child_tidptr, struct pt_regs *regs)
  213. {
  214. if (!newsp)
  215. newsp = regs->ARM_sp;
  216. return do_fork(clone_flags, newsp, regs, 0, parent_tidptr, child_tidptr);
  217. }
  218. asmlinkage int sys_vfork(struct pt_regs *regs)
  219. {
  220. return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->ARM_sp, regs, 0, NULL, NULL);
  221. }
  222. /* sys_execve() executes a new program.
  223. * This is called indirectly via a small wrapper
  224. */
  225. asmlinkage int sys_execve(char __user *filenamei, char __user * __user *argv,
  226. char __user * __user *envp, struct pt_regs *regs)
  227. {
  228. int error;
  229. char * filename;
  230. filename = getname(filenamei);
  231. error = PTR_ERR(filename);
  232. if (IS_ERR(filename))
  233. goto out;
  234. error = do_execve(filename, argv, envp, regs);
  235. putname(filename);
  236. out:
  237. return error;
  238. }
  239. long execve(const char *filename, char **argv, char **envp)
  240. {
  241. struct pt_regs regs;
  242. int ret;
  243. memset(&regs, 0, sizeof(struct pt_regs));
  244. ret = do_execve((char *)filename, (char __user * __user *)argv,
  245. (char __user * __user *)envp, &regs);
  246. if (ret < 0)
  247. goto out;
  248. /*
  249. * Save argc to the register structure for userspace.
  250. */
  251. regs.ARM_r0 = ret;
  252. /*
  253. * We were successful. We won't be returning to our caller, but
  254. * instead to user space by manipulating the kernel stack.
  255. */
  256. asm( "add r0, %0, %1\n\t"
  257. "mov r1, %2\n\t"
  258. "mov r2, %3\n\t"
  259. "bl memmove\n\t" /* copy regs to top of stack */
  260. "mov r8, #0\n\t" /* not a syscall */
  261. "mov r9, %0\n\t" /* thread structure */
  262. "mov sp, r0\n\t" /* reposition stack pointer */
  263. "b ret_to_user"
  264. :
  265. : "r" (current_thread_info()),
  266. "Ir" (THREAD_START_SP - sizeof(regs)),
  267. "r" (&regs),
  268. "Ir" (sizeof(regs))
  269. : "r0", "r1", "r2", "r3", "ip", "memory");
  270. out:
  271. return ret;
  272. }
  273. EXPORT_SYMBOL(execve);
  274. /*
  275. * Since loff_t is a 64 bit type we avoid a lot of ABI hastle
  276. * with a different argument ordering.
  277. */
  278. asmlinkage long sys_arm_fadvise64_64(int fd, int advice,
  279. loff_t offset, loff_t len)
  280. {
  281. return sys_fadvise64_64(fd, offset, len, advice);
  282. }