sys_s390.c 6.2 KB

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