/arch/ppc64/kernel/syscalls.c

https://bitbucket.org/evzijst/gittest · C · 258 lines · 200 code · 28 blank · 30 comment · 20 complexity · d1106bde546956557c37df3d626fa603 MD5 · raw file

  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. static int __init set_fakeppc(char *str)
  185. {
  186. if (*str)
  187. return 0;
  188. init_task.personality = PER_LINUX32;
  189. return 1;
  190. }
  191. __setup("fakeppc", set_fakeppc);
  192. asmlinkage int sys_uname(struct old_utsname __user * name)
  193. {
  194. int err = -EFAULT;
  195. down_read(&uts_sem);
  196. if (name && !copy_to_user(name, &system_utsname, sizeof (*name)))
  197. err = 0;
  198. up_read(&uts_sem);
  199. return err;
  200. }
  201. asmlinkage time_t sys64_time(time_t __user * tloc)
  202. {
  203. time_t secs;
  204. time_t usecs;
  205. long tb_delta = tb_ticks_since(tb_last_stamp);
  206. tb_delta += (jiffies - wall_jiffies) * tb_ticks_per_jiffy;
  207. secs = xtime.tv_sec;
  208. usecs = (xtime.tv_nsec/1000) + tb_delta / tb_ticks_per_usec;
  209. while (usecs >= USEC_PER_SEC) {
  210. ++secs;
  211. usecs -= USEC_PER_SEC;
  212. }
  213. if (tloc) {
  214. if (put_user(secs,tloc))
  215. secs = -EFAULT;
  216. }
  217. return secs;
  218. }
  219. void do_show_syscall(unsigned long r3, unsigned long r4, unsigned long r5,
  220. unsigned long r6, unsigned long r7, unsigned long r8,
  221. struct pt_regs *regs)
  222. {
  223. printk("syscall %ld(%lx, %lx, %lx, %lx, %lx, %lx) regs=%p current=%p"
  224. " cpu=%d\n", regs->gpr[0], r3, r4, r5, r6, r7, r8, regs,
  225. current, smp_processor_id());
  226. }
  227. void do_show_syscall_exit(unsigned long r3)
  228. {
  229. printk(" -> %lx, current=%p cpu=%d\n", r3, current, smp_processor_id());
  230. }