syscalls.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. void
  46. check_bugs(void)
  47. {
  48. }
  49. /*
  50. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  51. *
  52. * This is really horribly ugly.
  53. */
  54. asmlinkage int
  55. sys_ipc (uint call, int first, unsigned long second, long third,
  56. void __user *ptr, long fifth)
  57. {
  58. int version, ret;
  59. version = call >> 16; /* hack for backward compatibility */
  60. call &= 0xffff;
  61. ret = -ENOSYS;
  62. switch (call) {
  63. case SEMOP:
  64. ret = sys_semtimedop(first, (struct sembuf __user *)ptr,
  65. (unsigned)second, NULL);
  66. break;
  67. case SEMTIMEDOP:
  68. ret = sys_semtimedop(first, (struct sembuf __user *)ptr,
  69. (unsigned)second,
  70. (const struct timespec __user *) fifth);
  71. break;
  72. case SEMGET:
  73. ret = sys_semget (first, (int)second, third);
  74. break;
  75. case SEMCTL: {
  76. union semun fourth;
  77. ret = -EINVAL;
  78. if (!ptr)
  79. break;
  80. if ((ret = get_user(fourth.__pad, (void __user * __user *)ptr)))
  81. break;
  82. ret = sys_semctl(first, (int)second, third, fourth);
  83. break;
  84. }
  85. case MSGSND:
  86. ret = sys_msgsnd(first, (struct msgbuf __user *)ptr,
  87. (size_t)second, third);
  88. break;
  89. case MSGRCV:
  90. switch (version) {
  91. case 0: {
  92. struct ipc_kludge tmp;
  93. ret = -EINVAL;
  94. if (!ptr)
  95. break;
  96. if ((ret = copy_from_user(&tmp,
  97. (struct ipc_kludge __user *) ptr,
  98. sizeof (tmp)) ? -EFAULT : 0))
  99. break;
  100. ret = sys_msgrcv(first, tmp.msgp, (size_t) second,
  101. tmp.msgtyp, third);
  102. break;
  103. }
  104. default:
  105. ret = sys_msgrcv (first, (struct msgbuf __user *) ptr,
  106. (size_t)second, fifth, third);
  107. break;
  108. }
  109. break;
  110. case MSGGET:
  111. ret = sys_msgget ((key_t)first, (int)second);
  112. break;
  113. case MSGCTL:
  114. ret = sys_msgctl(first, (int)second,
  115. (struct msqid_ds __user *)ptr);
  116. break;
  117. case SHMAT:
  118. switch (version) {
  119. default: {
  120. ulong raddr;
  121. ret = do_shmat(first, (char __user *) ptr,
  122. (int)second, &raddr);
  123. if (ret)
  124. break;
  125. ret = put_user (raddr, (ulong __user *) third);
  126. break;
  127. }
  128. case 1: /* iBCS2 emulator entry point */
  129. ret = -EINVAL;
  130. if (!segment_eq(get_fs(), get_ds()))
  131. break;
  132. ret = do_shmat(first, (char __user *)ptr,
  133. (int)second, (ulong *)third);
  134. break;
  135. }
  136. break;
  137. case SHMDT:
  138. ret = sys_shmdt ((char __user *)ptr);
  139. break;
  140. case SHMGET:
  141. ret = sys_shmget (first, (size_t)second, third);
  142. break;
  143. case SHMCTL:
  144. ret = sys_shmctl(first, (int)second,
  145. (struct shmid_ds __user *)ptr);
  146. break;
  147. }
  148. return ret;
  149. }
  150. /*
  151. * sys_pipe() is the normal C calling standard for creating
  152. * a pipe. It's not the way unix traditionally does this, though.
  153. */
  154. asmlinkage int sys_pipe(int __user *fildes)
  155. {
  156. int fd[2];
  157. int error;
  158. error = do_pipe(fd);
  159. if (!error) {
  160. if (copy_to_user(fildes, fd, 2*sizeof(int)))
  161. error = -EFAULT;
  162. }
  163. return error;
  164. }
  165. unsigned long sys_mmap(unsigned long addr, size_t len,
  166. unsigned long prot, unsigned long flags,
  167. unsigned long fd, off_t offset)
  168. {
  169. struct file * file = NULL;
  170. unsigned long ret = -EBADF;
  171. if (!(flags & MAP_ANONYMOUS)) {
  172. if (!(file = fget(fd)))
  173. goto out;
  174. }
  175. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  176. down_write(&current->mm->mmap_sem);
  177. ret = do_mmap(file, addr, len, prot, flags, offset);
  178. up_write(&current->mm->mmap_sem);
  179. if (file)
  180. fput(file);
  181. out:
  182. return ret;
  183. }
  184. long ppc64_personality(unsigned long personality)
  185. {
  186. long ret;
  187. if (personality(current->personality) == PER_LINUX32
  188. && personality == PER_LINUX)
  189. personality = PER_LINUX32;
  190. ret = sys_personality(personality);
  191. if (ret == PER_LINUX32)
  192. ret = PER_LINUX;
  193. return ret;
  194. }
  195. long ppc64_newuname(struct new_utsname __user * name)
  196. {
  197. int err = 0;
  198. down_read(&uts_sem);
  199. if (copy_to_user(name, &system_utsname, sizeof(*name)))
  200. err = -EFAULT;
  201. up_read(&uts_sem);
  202. if (!err && personality(current->personality) == PER_LINUX32) {
  203. /* change ppc64 to ppc */
  204. if (__put_user(0, name->machine + 3)
  205. || __put_user(0, name->machine + 4))
  206. err = -EFAULT;
  207. }
  208. return err;
  209. }
  210. asmlinkage time_t sys64_time(time_t __user * tloc)
  211. {
  212. time_t secs;
  213. time_t usecs;
  214. long tb_delta = tb_ticks_since(tb_last_stamp);
  215. tb_delta += (jiffies - wall_jiffies) * tb_ticks_per_jiffy;
  216. secs = xtime.tv_sec;
  217. usecs = (xtime.tv_nsec/1000) + tb_delta / tb_ticks_per_usec;
  218. while (usecs >= USEC_PER_SEC) {
  219. ++secs;
  220. usecs -= USEC_PER_SEC;
  221. }
  222. if (tloc) {
  223. if (put_user(secs,tloc))
  224. secs = -EFAULT;
  225. }
  226. return secs;
  227. }
  228. void do_show_syscall(unsigned long r3, unsigned long r4, unsigned long r5,
  229. unsigned long r6, unsigned long r7, unsigned long r8,
  230. struct pt_regs *regs)
  231. {
  232. printk("syscall %ld(%lx, %lx, %lx, %lx, %lx, %lx) regs=%p current=%p"
  233. " cpu=%d\n", regs->gpr[0], r3, r4, r5, r6, r7, r8, regs,
  234. current, smp_processor_id());
  235. }
  236. void do_show_syscall_exit(unsigned long r3)
  237. {
  238. printk(" -> %lx, current=%p cpu=%d\n", r3, current, smp_processor_id());
  239. }