sys_arm.c 5.8 KB

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