sys_s390.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. SYSCALL_DEFINE1(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. SYSCALL_DEFINE1(s390_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. /*
  93. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  94. *
  95. * This is really horribly ugly.
  96. */
  97. SYSCALL_DEFINE5(ipc, uint, call, int, first, unsigned long, second,
  98. unsigned long, third, void __user *, ptr)
  99. {
  100. struct ipc_kludge tmp;
  101. int ret;
  102. switch (call) {
  103. case SEMOP:
  104. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  105. (unsigned)second, NULL);
  106. case SEMTIMEDOP:
  107. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  108. (unsigned)second,
  109. (const struct timespec __user *) third);
  110. case SEMGET:
  111. return sys_semget(first, (int)second, third);
  112. case SEMCTL: {
  113. union semun fourth;
  114. if (!ptr)
  115. return -EINVAL;
  116. if (get_user(fourth.__pad, (void __user * __user *) ptr))
  117. return -EFAULT;
  118. return sys_semctl(first, (int)second, third, fourth);
  119. }
  120. case MSGSND:
  121. return sys_msgsnd (first, (struct msgbuf __user *) ptr,
  122. (size_t)second, third);
  123. break;
  124. case MSGRCV:
  125. if (!ptr)
  126. return -EINVAL;
  127. if (copy_from_user (&tmp, (struct ipc_kludge __user *) ptr,
  128. sizeof (struct ipc_kludge)))
  129. return -EFAULT;
  130. return sys_msgrcv (first, tmp.msgp,
  131. (size_t)second, tmp.msgtyp, third);
  132. case MSGGET:
  133. return sys_msgget((key_t)first, (int)second);
  134. case MSGCTL:
  135. return sys_msgctl(first, (int)second,
  136. (struct msqid_ds __user *)ptr);
  137. case SHMAT: {
  138. ulong raddr;
  139. ret = do_shmat(first, (char __user *)ptr,
  140. (int)second, &raddr);
  141. if (ret)
  142. return ret;
  143. return put_user (raddr, (ulong __user *) third);
  144. break;
  145. }
  146. case SHMDT:
  147. return sys_shmdt ((char __user *)ptr);
  148. case SHMGET:
  149. return sys_shmget(first, (size_t)second, third);
  150. case SHMCTL:
  151. return sys_shmctl(first, (int)second,
  152. (struct shmid_ds __user *) ptr);
  153. default:
  154. return -ENOSYS;
  155. }
  156. return -EINVAL;
  157. }
  158. #ifdef CONFIG_64BIT
  159. SYSCALL_DEFINE1(s390_newuname, struct new_utsname __user *, name)
  160. {
  161. int ret = sys_newuname(name);
  162. if (personality(current->personality) == PER_LINUX32 && !ret) {
  163. ret = copy_to_user(name->machine, "s390\0\0\0\0", 8);
  164. if (ret) ret = -EFAULT;
  165. }
  166. return ret;
  167. }
  168. SYSCALL_DEFINE1(s390_personality, unsigned long, personality)
  169. {
  170. int ret;
  171. if (current->personality == PER_LINUX32 && personality == PER_LINUX)
  172. personality = PER_LINUX32;
  173. ret = sys_personality(personality);
  174. if (ret == PER_LINUX32)
  175. ret = PER_LINUX;
  176. return ret;
  177. }
  178. #endif /* CONFIG_64BIT */
  179. /*
  180. * Wrapper function for sys_fadvise64/fadvise64_64
  181. */
  182. #ifndef CONFIG_64BIT
  183. SYSCALL_DEFINE5(s390_fadvise64, int, fd, u32, offset_high, u32, offset_low,
  184. size_t, len, int, advice)
  185. {
  186. return sys_fadvise64(fd, (u64) offset_high << 32 | offset_low,
  187. len, advice);
  188. }
  189. struct fadvise64_64_args {
  190. int fd;
  191. long long offset;
  192. long long len;
  193. int advice;
  194. };
  195. SYSCALL_DEFINE1(s390_fadvise64_64, struct fadvise64_64_args __user *, args)
  196. {
  197. struct fadvise64_64_args a;
  198. if ( copy_from_user(&a, args, sizeof(a)) )
  199. return -EFAULT;
  200. return sys_fadvise64_64(a.fd, a.offset, a.len, a.advice);
  201. }
  202. /*
  203. * This is a wrapper to call sys_fallocate(). For 31 bit s390 the last
  204. * 64 bit argument "len" is split into the upper and lower 32 bits. The
  205. * system call wrapper in the user space loads the value to %r6/%r7.
  206. * The code in entry.S keeps the values in %r2 - %r6 where they are and
  207. * stores %r7 to 96(%r15). But the standard C linkage requires that
  208. * the whole 64 bit value for len is stored on the stack and doesn't
  209. * use %r6 at all. So s390_fallocate has to convert the arguments from
  210. * %r2: fd, %r3: mode, %r4/%r5: offset, %r6/96(%r15)-99(%r15): len
  211. * to
  212. * %r2: fd, %r3: mode, %r4/%r5: offset, 96(%r15)-103(%r15): len
  213. */
  214. SYSCALL_DEFINE(s390_fallocate)(int fd, int mode, loff_t offset,
  215. u32 len_high, u32 len_low)
  216. {
  217. return sys_fallocate(fd, mode, offset, ((u64)len_high << 32) | len_low);
  218. }
  219. #ifdef CONFIG_HAVE_SYSCALL_WRAPPERS
  220. asmlinkage long SyS_s390_fallocate(long fd, long mode, loff_t offset,
  221. long len_high, long len_low)
  222. {
  223. return SYSC_s390_fallocate((int) fd, (int) mode, offset,
  224. (u32) len_high, (u32) len_low);
  225. }
  226. SYSCALL_ALIAS(sys_s390_fallocate, SyS_s390_fallocate);
  227. #endif
  228. #endif