syscalls.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*
  2. * linux/arch/ppc64/kernel/sys_ppc.c
  3. *
  4. * PowerPC version
  5. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  6. *
  7. * Derived from "arch/i386/kernel/sys_i386.c"
  8. * Adapted from the i386 version by Gary Thomas
  9. * Modified by Cort Dougan (cort@cs.nmt.edu)
  10. * and Paul Mackerras (paulus@cs.anu.edu.au).
  11. *
  12. * This file contains various random system calls that
  13. * have a non-standard calling sequence on the Linux/PPC
  14. * platform.
  15. *
  16. * This program is free software; you can redistribute it and/or
  17. * modify it under the terms of the GNU General Public License
  18. * as published by the Free Software Foundation; either version
  19. * 2 of the License, or (at your option) any later version.
  20. *
  21. */
  22. #include <linux/errno.h>
  23. #include <linux/sched.h>
  24. #include <linux/syscalls.h>
  25. #include <linux/mm.h>
  26. #include <linux/smp.h>
  27. #include <linux/smp_lock.h>
  28. #include <linux/sem.h>
  29. #include <linux/msg.h>
  30. #include <linux/shm.h>
  31. #include <linux/stat.h>
  32. #include <linux/mman.h>
  33. #include <linux/sys.h>
  34. #include <linux/ipc.h>
  35. #include <linux/utsname.h>
  36. #include <linux/file.h>
  37. #include <linux/init.h>
  38. #include <linux/personality.h>
  39. #include <asm/uaccess.h>
  40. #include <asm/ipc.h>
  41. #include <asm/semaphore.h>
  42. #include <asm/time.h>
  43. #include <asm/unistd.h>
  44. extern unsigned long wall_jiffies;
  45. /*
  46. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  47. *
  48. * This is really horribly ugly.
  49. */
  50. asmlinkage int
  51. sys_ipc (uint call, int first, unsigned long second, long third,
  52. void __user *ptr, long fifth)
  53. {
  54. int version, ret;
  55. version = call >> 16; /* hack for backward compatibility */
  56. call &= 0xffff;
  57. ret = -ENOSYS;
  58. switch (call) {
  59. case SEMOP:
  60. ret = sys_semtimedop(first, (struct sembuf __user *)ptr,
  61. (unsigned)second, NULL);
  62. break;
  63. case SEMTIMEDOP:
  64. ret = sys_semtimedop(first, (struct sembuf __user *)ptr,
  65. (unsigned)second,
  66. (const struct timespec __user *) fifth);
  67. break;
  68. case SEMGET:
  69. ret = sys_semget (first, (int)second, third);
  70. break;
  71. case SEMCTL: {
  72. union semun fourth;
  73. ret = -EINVAL;
  74. if (!ptr)
  75. break;
  76. if ((ret = get_user(fourth.__pad, (void __user * __user *)ptr)))
  77. break;
  78. ret = sys_semctl(first, (int)second, third, fourth);
  79. break;
  80. }
  81. case MSGSND:
  82. ret = sys_msgsnd(first, (struct msgbuf __user *)ptr,
  83. (size_t)second, third);
  84. break;
  85. case MSGRCV:
  86. switch (version) {
  87. case 0: {
  88. struct ipc_kludge tmp;
  89. ret = -EINVAL;
  90. if (!ptr)
  91. break;
  92. if ((ret = copy_from_user(&tmp,
  93. (struct ipc_kludge __user *) ptr,
  94. sizeof (tmp)) ? -EFAULT : 0))
  95. break;
  96. ret = sys_msgrcv(first, tmp.msgp, (size_t) second,
  97. tmp.msgtyp, third);
  98. break;
  99. }
  100. default:
  101. ret = sys_msgrcv (first, (struct msgbuf __user *) ptr,
  102. (size_t)second, fifth, third);
  103. break;
  104. }
  105. break;
  106. case MSGGET:
  107. ret = sys_msgget ((key_t)first, (int)second);
  108. break;
  109. case MSGCTL:
  110. ret = sys_msgctl(first, (int)second,
  111. (struct msqid_ds __user *)ptr);
  112. break;
  113. case SHMAT:
  114. switch (version) {
  115. default: {
  116. ulong raddr;
  117. ret = do_shmat(first, (char __user *) ptr,
  118. (int)second, &raddr);
  119. if (ret)
  120. break;
  121. ret = put_user (raddr, (ulong __user *) third);
  122. break;
  123. }
  124. case 1: /* iBCS2 emulator entry point */
  125. ret = -EINVAL;
  126. if (!segment_eq(get_fs(), get_ds()))
  127. break;
  128. ret = do_shmat(first, (char __user *)ptr,
  129. (int)second, (ulong *)third);
  130. break;
  131. }
  132. break;
  133. case SHMDT:
  134. ret = sys_shmdt ((char __user *)ptr);
  135. break;
  136. case SHMGET:
  137. ret = sys_shmget (first, (size_t)second, third);
  138. break;
  139. case SHMCTL:
  140. ret = sys_shmctl(first, (int)second,
  141. (struct shmid_ds __user *)ptr);
  142. break;
  143. }
  144. return ret;
  145. }
  146. /*
  147. * sys_pipe() is the normal C calling standard for creating
  148. * a pipe. It's not the way unix traditionally does this, though.
  149. */
  150. asmlinkage int sys_pipe(int __user *fildes)
  151. {
  152. int fd[2];
  153. int error;
  154. error = do_pipe(fd);
  155. if (!error) {
  156. if (copy_to_user(fildes, fd, 2*sizeof(int)))
  157. error = -EFAULT;
  158. }
  159. return error;
  160. }
  161. unsigned long sys_mmap(unsigned long addr, size_t len,
  162. unsigned long prot, unsigned long flags,
  163. unsigned long fd, off_t offset)
  164. {
  165. struct file * file = NULL;
  166. unsigned long ret = -EBADF;
  167. if (!(flags & MAP_ANONYMOUS)) {
  168. if (!(file = fget(fd)))
  169. goto out;
  170. }
  171. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  172. down_write(&current->mm->mmap_sem);
  173. ret = do_mmap(file, addr, len, prot, flags, offset);
  174. up_write(&current->mm->mmap_sem);
  175. if (file)
  176. fput(file);
  177. out:
  178. return ret;
  179. }
  180. long ppc64_personality(unsigned long personality)
  181. {
  182. long ret;
  183. if (personality(current->personality) == PER_LINUX32
  184. && personality == PER_LINUX)
  185. personality = PER_LINUX32;
  186. ret = sys_personality(personality);
  187. if (ret == PER_LINUX32)
  188. ret = PER_LINUX;
  189. return ret;
  190. }
  191. long ppc64_newuname(struct new_utsname __user * name)
  192. {
  193. int err = 0;
  194. down_read(&uts_sem);
  195. if (copy_to_user(name, &system_utsname, sizeof(*name)))
  196. err = -EFAULT;
  197. up_read(&uts_sem);
  198. if (!err && personality(current->personality) == PER_LINUX32) {
  199. /* change ppc64 to ppc */
  200. if (__put_user(0, name->machine + 3)
  201. || __put_user(0, name->machine + 4))
  202. err = -EFAULT;
  203. }
  204. return err;
  205. }
  206. asmlinkage time_t sys64_time(time_t __user * tloc)
  207. {
  208. time_t secs;
  209. time_t usecs;
  210. long tb_delta = tb_ticks_since(tb_last_stamp);
  211. tb_delta += (jiffies - wall_jiffies) * tb_ticks_per_jiffy;
  212. secs = xtime.tv_sec;
  213. usecs = (xtime.tv_nsec/1000) + tb_delta / tb_ticks_per_usec;
  214. while (usecs >= USEC_PER_SEC) {
  215. ++secs;
  216. usecs -= USEC_PER_SEC;
  217. }
  218. if (tloc) {
  219. if (put_user(secs,tloc))
  220. secs = -EFAULT;
  221. }
  222. return secs;
  223. }
  224. void do_show_syscall(unsigned long r3, unsigned long r4, unsigned long r5,
  225. unsigned long r6, unsigned long r7, unsigned long r8,
  226. struct pt_regs *regs)
  227. {
  228. printk("syscall %ld(%lx, %lx, %lx, %lx, %lx, %lx) regs=%p current=%p"
  229. " cpu=%d\n", regs->gpr[0], r3, r4, r5, r6, r7, r8, regs,
  230. current, smp_processor_id());
  231. }
  232. void do_show_syscall_exit(unsigned long r3)
  233. {
  234. printk(" -> %lx, current=%p cpu=%d\n", r3, current, smp_processor_id());
  235. }