sys_s390.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. * arch/s390/kernel/sys_s390.c
  3. *
  4. * S390 version
  5. * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
  6. * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
  7. * Thomas Spatzier (tspat@de.ibm.com)
  8. *
  9. * Derived from "arch/i386/kernel/sys_i386.c"
  10. *
  11. * This file contains various random system calls that
  12. * have a non-standard calling sequence on the Linux/s390
  13. * platform.
  14. */
  15. #include <linux/errno.h>
  16. #include <linux/sched.h>
  17. #include <linux/mm.h>
  18. #include <linux/fs.h>
  19. #include <linux/smp.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/file.h>
  27. #include <linux/utsname.h>
  28. #include <linux/personality.h>
  29. #include <linux/unistd.h>
  30. #include <linux/ipc.h>
  31. #include <asm/uaccess.h>
  32. #include "entry.h"
  33. /* common code for old and new mmaps */
  34. static inline long do_mmap2(
  35. unsigned long addr, unsigned long len,
  36. unsigned long prot, unsigned long flags,
  37. unsigned long fd, unsigned long pgoff)
  38. {
  39. long error = -EBADF;
  40. struct file * file = NULL;
  41. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  42. if (!(flags & MAP_ANONYMOUS)) {
  43. file = fget(fd);
  44. if (!file)
  45. goto out;
  46. }
  47. down_write(&current->mm->mmap_sem);
  48. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  49. up_write(&current->mm->mmap_sem);
  50. if (file)
  51. fput(file);
  52. out:
  53. return error;
  54. }
  55. /*
  56. * Perform the select(nd, in, out, ex, tv) and mmap() system
  57. * calls. Linux for S/390 isn't able to handle more than 5
  58. * system call parameters, so these system calls used a memory
  59. * block for parameter passing..
  60. */
  61. struct mmap_arg_struct {
  62. unsigned long addr;
  63. unsigned long len;
  64. unsigned long prot;
  65. unsigned long flags;
  66. unsigned long fd;
  67. unsigned long offset;
  68. };
  69. asmlinkage long sys_mmap2(struct mmap_arg_struct __user *arg)
  70. {
  71. struct mmap_arg_struct a;
  72. int error = -EFAULT;
  73. if (copy_from_user(&a, arg, sizeof(a)))
  74. goto out;
  75. error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
  76. out:
  77. return error;
  78. }
  79. asmlinkage long old_mmap(struct mmap_arg_struct __user *arg)
  80. {
  81. struct mmap_arg_struct a;
  82. long error = -EFAULT;
  83. if (copy_from_user(&a, arg, sizeof(a)))
  84. goto out;
  85. error = -EINVAL;
  86. if (a.offset & ~PAGE_MASK)
  87. goto out;
  88. error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
  89. out:
  90. return error;
  91. }
  92. #ifndef CONFIG_64BIT
  93. struct sel_arg_struct {
  94. unsigned long n;
  95. fd_set __user *inp, *outp, *exp;
  96. struct timeval __user *tvp;
  97. };
  98. asmlinkage long old_select(struct sel_arg_struct __user *arg)
  99. {
  100. struct sel_arg_struct a;
  101. if (copy_from_user(&a, arg, sizeof(a)))
  102. return -EFAULT;
  103. /* sys_select() does the appropriate kernel locking */
  104. return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
  105. }
  106. #endif /* CONFIG_64BIT */
  107. /*
  108. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  109. *
  110. * This is really horribly ugly.
  111. */
  112. asmlinkage long sys_ipc(uint call, int first, unsigned long second,
  113. unsigned long third, void __user *ptr)
  114. {
  115. struct ipc_kludge tmp;
  116. int ret;
  117. switch (call) {
  118. case SEMOP:
  119. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  120. (unsigned)second, NULL);
  121. case SEMTIMEDOP:
  122. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  123. (unsigned)second,
  124. (const struct timespec __user *) third);
  125. case SEMGET:
  126. return sys_semget(first, (int)second, third);
  127. case SEMCTL: {
  128. union semun fourth;
  129. if (!ptr)
  130. return -EINVAL;
  131. if (get_user(fourth.__pad, (void __user * __user *) ptr))
  132. return -EFAULT;
  133. return sys_semctl(first, (int)second, third, fourth);
  134. }
  135. case MSGSND:
  136. return sys_msgsnd (first, (struct msgbuf __user *) ptr,
  137. (size_t)second, third);
  138. break;
  139. case MSGRCV:
  140. if (!ptr)
  141. return -EINVAL;
  142. if (copy_from_user (&tmp, (struct ipc_kludge __user *) ptr,
  143. sizeof (struct ipc_kludge)))
  144. return -EFAULT;
  145. return sys_msgrcv (first, tmp.msgp,
  146. (size_t)second, tmp.msgtyp, third);
  147. case MSGGET:
  148. return sys_msgget((key_t)first, (int)second);
  149. case MSGCTL:
  150. return sys_msgctl(first, (int)second,
  151. (struct msqid_ds __user *)ptr);
  152. case SHMAT: {
  153. ulong raddr;
  154. ret = do_shmat(first, (char __user *)ptr,
  155. (int)second, &raddr);
  156. if (ret)
  157. return ret;
  158. return put_user (raddr, (ulong __user *) third);
  159. break;
  160. }
  161. case SHMDT:
  162. return sys_shmdt ((char __user *)ptr);
  163. case SHMGET:
  164. return sys_shmget(first, (size_t)second, third);
  165. case SHMCTL:
  166. return sys_shmctl(first, (int)second,
  167. (struct shmid_ds __user *) ptr);
  168. default:
  169. return -ENOSYS;
  170. }
  171. return -EINVAL;
  172. }
  173. #ifdef CONFIG_64BIT
  174. asmlinkage long s390x_newuname(struct new_utsname __user *name)
  175. {
  176. int ret = sys_newuname(name);
  177. if (current->personality == PER_LINUX32 && !ret) {
  178. ret = copy_to_user(name->machine, "s390\0\0\0\0", 8);
  179. if (ret) ret = -EFAULT;
  180. }
  181. return ret;
  182. }
  183. asmlinkage long s390x_personality(unsigned long personality)
  184. {
  185. int ret;
  186. if (current->personality == PER_LINUX32 && personality == PER_LINUX)
  187. personality = PER_LINUX32;
  188. ret = sys_personality(personality);
  189. if (ret == PER_LINUX32)
  190. ret = PER_LINUX;
  191. return ret;
  192. }
  193. #endif /* CONFIG_64BIT */
  194. /*
  195. * Wrapper function for sys_fadvise64/fadvise64_64
  196. */
  197. #ifndef CONFIG_64BIT
  198. asmlinkage long
  199. s390_fadvise64(int fd, u32 offset_high, u32 offset_low, size_t len, int advice)
  200. {
  201. return sys_fadvise64(fd, (u64) offset_high << 32 | offset_low,
  202. len, advice);
  203. }
  204. #endif
  205. struct fadvise64_64_args {
  206. int fd;
  207. long long offset;
  208. long long len;
  209. int advice;
  210. };
  211. asmlinkage long
  212. s390_fadvise64_64(struct fadvise64_64_args __user *args)
  213. {
  214. struct fadvise64_64_args a;
  215. if ( copy_from_user(&a, args, sizeof(a)) )
  216. return -EFAULT;
  217. return sys_fadvise64_64(a.fd, a.offset, a.len, a.advice);
  218. }
  219. #ifndef CONFIG_64BIT
  220. /*
  221. * This is a wrapper to call sys_fallocate(). For 31 bit s390 the last
  222. * 64 bit argument "len" is split into the upper and lower 32 bits. The
  223. * system call wrapper in the user space loads the value to %r6/%r7.
  224. * The code in entry.S keeps the values in %r2 - %r6 where they are and
  225. * stores %r7 to 96(%r15). But the standard C linkage requires that
  226. * the whole 64 bit value for len is stored on the stack and doesn't
  227. * use %r6 at all. So s390_fallocate has to convert the arguments from
  228. * %r2: fd, %r3: mode, %r4/%r5: offset, %r6/96(%r15)-99(%r15): len
  229. * to
  230. * %r2: fd, %r3: mode, %r4/%r5: offset, 96(%r15)-103(%r15): len
  231. */
  232. asmlinkage long s390_fallocate(int fd, int mode, loff_t offset,
  233. u32 len_high, u32 len_low)
  234. {
  235. return sys_fallocate(fd, mode, offset, ((u64)len_high << 32) | len_low);
  236. }
  237. #endif