sys_arm.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. /*
  2. * linux/arch/arm26/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. * Copyright (C) 2003 Ian Molton.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * This file contains various random system calls that
  13. * have a non-standard calling sequence on the Linux/arm
  14. * platform.
  15. */
  16. #include <linux/module.h>
  17. #include <linux/errno.h>
  18. #include <linux/sched.h>
  19. #include <linux/slab.h>
  20. #include <linux/mm.h>
  21. #include <linux/sem.h>
  22. #include <linux/msg.h>
  23. #include <linux/shm.h>
  24. #include <linux/stat.h>
  25. #include <linux/syscalls.h>
  26. #include <linux/mman.h>
  27. #include <linux/fs.h>
  28. #include <linux/file.h>
  29. #include <linux/utsname.h>
  30. #include <asm/uaccess.h>
  31. #include <asm/ipc.h>
  32. extern unsigned long do_mremap(unsigned long addr, unsigned long old_len,
  33. unsigned long new_len, unsigned long flags,
  34. unsigned long new_addr);
  35. /*
  36. * sys_pipe() is the normal C calling standard for creating
  37. * a pipe. It's not the way unix traditionally does this, though.
  38. */
  39. asmlinkage int sys_pipe(unsigned long * fildes)
  40. {
  41. int fd[2];
  42. int error;
  43. error = do_pipe(fd);
  44. if (!error) {
  45. if (copy_to_user(fildes, fd, 2*sizeof(int)))
  46. error = -EFAULT;
  47. }
  48. return error;
  49. }
  50. /* common code for old and new mmaps */
  51. inline long do_mmap2(
  52. unsigned long addr, unsigned long len,
  53. unsigned long prot, unsigned long flags,
  54. unsigned long fd, unsigned long pgoff)
  55. {
  56. int error = -EINVAL;
  57. struct file * file = NULL;
  58. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  59. /*
  60. * If we are doing a fixed mapping, and address < FIRST_USER_ADDRESS,
  61. * then deny it.
  62. */
  63. if (flags & MAP_FIXED && addr < FIRST_USER_ADDRESS)
  64. goto out;
  65. error = -EBADF;
  66. if (!(flags & MAP_ANONYMOUS)) {
  67. file = fget(fd);
  68. if (!file)
  69. goto out;
  70. }
  71. down_write(&current->mm->mmap_sem);
  72. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  73. up_write(&current->mm->mmap_sem);
  74. if (file)
  75. fput(file);
  76. out:
  77. return error;
  78. }
  79. struct mmap_arg_struct {
  80. unsigned long addr;
  81. unsigned long len;
  82. unsigned long prot;
  83. unsigned long flags;
  84. unsigned long fd;
  85. unsigned long offset;
  86. };
  87. asmlinkage int old_mmap(struct mmap_arg_struct *arg)
  88. {
  89. int error = -EFAULT;
  90. struct mmap_arg_struct a;
  91. if (copy_from_user(&a, arg, sizeof(a)))
  92. goto out;
  93. error = -EINVAL;
  94. if (a.offset & ~PAGE_MASK)
  95. goto out;
  96. error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
  97. out:
  98. return error;
  99. }
  100. asmlinkage unsigned long
  101. sys_arm_mremap(unsigned long addr, unsigned long old_len,
  102. unsigned long new_len, unsigned long flags,
  103. unsigned long new_addr)
  104. {
  105. unsigned long ret = -EINVAL;
  106. /*
  107. * If we are doing a fixed mapping, and address < FIRST_USER_ADDRESS,
  108. * then deny it.
  109. */
  110. if (flags & MREMAP_FIXED && new_addr < FIRST_USER_ADDRESS)
  111. goto out;
  112. down_write(&current->mm->mmap_sem);
  113. ret = do_mremap(addr, old_len, new_len, flags, new_addr);
  114. up_write(&current->mm->mmap_sem);
  115. out:
  116. return ret;
  117. }
  118. /*
  119. * Perform the select(nd, in, out, ex, tv) and mmap() system
  120. * calls.
  121. */
  122. struct sel_arg_struct {
  123. unsigned long n;
  124. fd_set *inp, *outp, *exp;
  125. struct timeval *tvp;
  126. };
  127. asmlinkage int old_select(struct sel_arg_struct *arg)
  128. {
  129. struct sel_arg_struct a;
  130. if (copy_from_user(&a, arg, sizeof(a)))
  131. return -EFAULT;
  132. /* sys_select() does the appropriate kernel locking */
  133. return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
  134. }
  135. /*
  136. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  137. *
  138. * This is really horribly ugly.
  139. */
  140. asmlinkage int sys_ipc (uint call, int first, int second, int third, void *ptr, long fifth)
  141. {
  142. int version, ret;
  143. version = call >> 16; /* hack for backward compatibility */
  144. call &= 0xffff;
  145. switch (call) {
  146. case SEMOP:
  147. return sys_semop (first, (struct sembuf *)ptr, second);
  148. case SEMGET:
  149. return sys_semget (first, second, third);
  150. case SEMCTL: {
  151. union semun fourth;
  152. if (!ptr)
  153. return -EINVAL;
  154. if (get_user(fourth.__pad, (void **) ptr))
  155. return -EFAULT;
  156. return sys_semctl (first, second, third, fourth);
  157. }
  158. case MSGSND:
  159. return sys_msgsnd (first, (struct msgbuf *) ptr,
  160. second, third);
  161. case MSGRCV:
  162. switch (version) {
  163. case 0: {
  164. struct ipc_kludge tmp;
  165. if (!ptr)
  166. return -EINVAL;
  167. if (copy_from_user(&tmp,(struct ipc_kludge *) ptr,
  168. sizeof (tmp)))
  169. return -EFAULT;
  170. return sys_msgrcv (first, tmp.msgp, second,
  171. tmp.msgtyp, third);
  172. }
  173. default:
  174. return sys_msgrcv (first,
  175. (struct msgbuf *) ptr,
  176. second, fifth, third);
  177. }
  178. case MSGGET:
  179. return sys_msgget ((key_t) first, second);
  180. case MSGCTL:
  181. return sys_msgctl (first, second, (struct msqid_ds *) ptr);
  182. case SHMAT:
  183. switch (version) {
  184. default: {
  185. ulong raddr;
  186. ret = do_shmat (first, (char *) ptr, second, &raddr);
  187. if (ret)
  188. return ret;
  189. return put_user (raddr, (ulong *) third);
  190. }
  191. case 1: /* iBCS2 emulator entry point */
  192. if (!segment_eq(get_fs(), get_ds()))
  193. return -EINVAL;
  194. return do_shmat (first, (char *) ptr,
  195. second, (ulong *) third);
  196. }
  197. case SHMDT:
  198. return sys_shmdt ((char *)ptr);
  199. case SHMGET:
  200. return sys_shmget (first, second, third);
  201. case SHMCTL:
  202. return sys_shmctl (first, second,
  203. (struct shmid_ds *) ptr);
  204. default:
  205. return -EINVAL;
  206. }
  207. }
  208. /* Fork a new task - this creates a new program thread.
  209. * This is called indirectly via a small wrapper
  210. */
  211. asmlinkage int sys_fork(struct pt_regs *regs)
  212. {
  213. return do_fork(SIGCHLD, regs->ARM_sp, regs, 0, NULL, NULL);
  214. }
  215. /* Clone a task - this clones the calling program thread.
  216. * This is called indirectly via a small wrapper
  217. */
  218. asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp, struct pt_regs *regs)
  219. {
  220. /*
  221. * We don't support SETTID / CLEARTID (FIXME!!! (nicked from arm32))
  222. */
  223. if (clone_flags & (CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID))
  224. return -EINVAL;
  225. if (!newsp)
  226. newsp = regs->ARM_sp;
  227. return do_fork(clone_flags, newsp, regs, 0, NULL, NULL);
  228. }
  229. asmlinkage int sys_vfork(struct pt_regs *regs)
  230. {
  231. return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->ARM_sp, regs, 0, NULL, NULL);
  232. }
  233. /* sys_execve() executes a new program.
  234. * This is called indirectly via a small wrapper
  235. */
  236. asmlinkage int sys_execve(char *filenamei, char **argv, char **envp, struct pt_regs *regs)
  237. {
  238. int error;
  239. char * filename;
  240. filename = getname(filenamei);
  241. error = PTR_ERR(filename);
  242. if (IS_ERR(filename))
  243. goto out;
  244. error = do_execve(filename, argv, envp, regs);
  245. putname(filename);
  246. out:
  247. return error;
  248. }
  249. /* FIXME - see if this is correct for arm26 */
  250. long execve(const char *filename, char **argv, char **envp)
  251. {
  252. struct pt_regs regs;
  253. int ret;
  254. memset(&regs, 0, sizeof(struct pt_regs));
  255. ret = do_execve((char *)filename, (char __user * __user *)argv, (char __user * __user *)envp, &regs);
  256. if (ret < 0)
  257. goto out;
  258. /*
  259. * Save argc to the register structure for userspace.
  260. */
  261. regs.ARM_r0 = ret;
  262. /*
  263. * We were successful. We won't be returning to our caller, but
  264. * instead to user space by manipulating the kernel stack.
  265. */
  266. asm( "add r0, %0, %1\n\t"
  267. "mov r1, %2\n\t"
  268. "mov r2, %3\n\t"
  269. "bl memmove\n\t" /* copy regs to top of stack */
  270. "mov r8, #0\n\t" /* not a syscall */
  271. "mov r9, %0\n\t" /* thread structure */
  272. "mov sp, r0\n\t" /* reposition stack pointer */
  273. "b ret_to_user"
  274. :
  275. : "r" (current_thread_info()),
  276. "Ir" (THREAD_SIZE - 8 - sizeof(regs)),
  277. "r" (&regs),
  278. "Ir" (sizeof(regs))
  279. : "r0", "r1", "r2", "r3", "ip", "memory");
  280. out:
  281. return ret;
  282. }
  283. EXPORT_SYMBOL(execve);