sys_s390.c 6.8 KB

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