sys_s390.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. /*
  34. * Perform the mmap() system call. Linux for S/390 isn't able to handle more
  35. * than 5 system call parameters, so this system call uses a memory block
  36. * for parameter passing.
  37. */
  38. struct s390_mmap_arg_struct {
  39. unsigned long addr;
  40. unsigned long len;
  41. unsigned long prot;
  42. unsigned long flags;
  43. unsigned long fd;
  44. unsigned long offset;
  45. };
  46. SYSCALL_DEFINE1(mmap2, struct s390_mmap_arg_struct __user *, arg)
  47. {
  48. struct s390_mmap_arg_struct a;
  49. int error = -EFAULT;
  50. if (copy_from_user(&a, arg, sizeof(a)))
  51. goto out;
  52. error = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
  53. out:
  54. return error;
  55. }
  56. /*
  57. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  58. *
  59. * This is really horribly ugly.
  60. */
  61. SYSCALL_DEFINE5(s390_ipc, uint, call, int, first, unsigned long, second,
  62. unsigned long, third, void __user *, ptr)
  63. {
  64. struct ipc_kludge tmp;
  65. int ret;
  66. switch (call) {
  67. case SEMOP:
  68. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  69. (unsigned)second, NULL);
  70. case SEMTIMEDOP:
  71. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  72. (unsigned)second,
  73. (const struct timespec __user *) third);
  74. case SEMGET:
  75. return sys_semget(first, (int)second, third);
  76. case SEMCTL: {
  77. union semun fourth;
  78. if (!ptr)
  79. return -EINVAL;
  80. if (get_user(fourth.__pad, (void __user * __user *) ptr))
  81. return -EFAULT;
  82. return sys_semctl(first, (int)second, third, fourth);
  83. }
  84. case MSGSND:
  85. return sys_msgsnd (first, (struct msgbuf __user *) ptr,
  86. (size_t)second, third);
  87. break;
  88. case MSGRCV:
  89. if (!ptr)
  90. return -EINVAL;
  91. if (copy_from_user (&tmp, (struct ipc_kludge __user *) ptr,
  92. sizeof (struct ipc_kludge)))
  93. return -EFAULT;
  94. return sys_msgrcv (first, tmp.msgp,
  95. (size_t)second, tmp.msgtyp, third);
  96. case MSGGET:
  97. return sys_msgget((key_t)first, (int)second);
  98. case MSGCTL:
  99. return sys_msgctl(first, (int)second,
  100. (struct msqid_ds __user *)ptr);
  101. case SHMAT: {
  102. ulong raddr;
  103. ret = do_shmat(first, (char __user *)ptr,
  104. (int)second, &raddr);
  105. if (ret)
  106. return ret;
  107. return put_user (raddr, (ulong __user *) third);
  108. break;
  109. }
  110. case SHMDT:
  111. return sys_shmdt ((char __user *)ptr);
  112. case SHMGET:
  113. return sys_shmget(first, (size_t)second, third);
  114. case SHMCTL:
  115. return sys_shmctl(first, (int)second,
  116. (struct shmid_ds __user *) ptr);
  117. default:
  118. return -ENOSYS;
  119. }
  120. return -EINVAL;
  121. }
  122. #ifdef CONFIG_64BIT
  123. SYSCALL_DEFINE1(s390_personality, unsigned int, personality)
  124. {
  125. unsigned int ret;
  126. if (current->personality == PER_LINUX32 && personality == PER_LINUX)
  127. personality = PER_LINUX32;
  128. ret = sys_personality(personality);
  129. if (ret == PER_LINUX32)
  130. ret = PER_LINUX;
  131. return ret;
  132. }
  133. #endif /* CONFIG_64BIT */
  134. /*
  135. * Wrapper function for sys_fadvise64/fadvise64_64
  136. */
  137. #ifndef CONFIG_64BIT
  138. SYSCALL_DEFINE5(s390_fadvise64, int, fd, u32, offset_high, u32, offset_low,
  139. size_t, len, int, advice)
  140. {
  141. return sys_fadvise64(fd, (u64) offset_high << 32 | offset_low,
  142. len, advice);
  143. }
  144. struct fadvise64_64_args {
  145. int fd;
  146. long long offset;
  147. long long len;
  148. int advice;
  149. };
  150. SYSCALL_DEFINE1(s390_fadvise64_64, struct fadvise64_64_args __user *, args)
  151. {
  152. struct fadvise64_64_args a;
  153. if ( copy_from_user(&a, args, sizeof(a)) )
  154. return -EFAULT;
  155. return sys_fadvise64_64(a.fd, a.offset, a.len, a.advice);
  156. }
  157. /*
  158. * This is a wrapper to call sys_fallocate(). For 31 bit s390 the last
  159. * 64 bit argument "len" is split into the upper and lower 32 bits. The
  160. * system call wrapper in the user space loads the value to %r6/%r7.
  161. * The code in entry.S keeps the values in %r2 - %r6 where they are and
  162. * stores %r7 to 96(%r15). But the standard C linkage requires that
  163. * the whole 64 bit value for len is stored on the stack and doesn't
  164. * use %r6 at all. So s390_fallocate has to convert the arguments from
  165. * %r2: fd, %r3: mode, %r4/%r5: offset, %r6/96(%r15)-99(%r15): len
  166. * to
  167. * %r2: fd, %r3: mode, %r4/%r5: offset, 96(%r15)-103(%r15): len
  168. */
  169. SYSCALL_DEFINE(s390_fallocate)(int fd, int mode, loff_t offset,
  170. u32 len_high, u32 len_low)
  171. {
  172. return sys_fallocate(fd, mode, offset, ((u64)len_high << 32) | len_low);
  173. }
  174. #ifdef CONFIG_HAVE_SYSCALL_WRAPPERS
  175. asmlinkage long SyS_s390_fallocate(long fd, long mode, loff_t offset,
  176. long len_high, long len_low)
  177. {
  178. return SYSC_s390_fallocate((int) fd, (int) mode, offset,
  179. (u32) len_high, (u32) len_low);
  180. }
  181. SYSCALL_ALIAS(sys_s390_fallocate, SyS_s390_fallocate);
  182. #endif
  183. #endif