syscall_kern.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * Copyright (C) 2000 - 2003 Jeff Dike (jdike@addtoit.com)
  3. * Licensed under the GPL
  4. */
  5. #include "linux/sched.h"
  6. #include "linux/file.h"
  7. #include "linux/smp_lock.h"
  8. #include "linux/mm.h"
  9. #include "linux/utsname.h"
  10. #include "linux/msg.h"
  11. #include "linux/shm.h"
  12. #include "linux/sys.h"
  13. #include "linux/syscalls.h"
  14. #include "linux/unistd.h"
  15. #include "linux/slab.h"
  16. #include "linux/utime.h"
  17. #include "asm/mman.h"
  18. #include "asm/uaccess.h"
  19. #include "kern_util.h"
  20. #include "user_util.h"
  21. #include "sysdep/syscalls.h"
  22. #include "mode_kern.h"
  23. #include "choose-mode.h"
  24. /* Unlocked, I don't care if this is a bit off */
  25. int nsyscalls = 0;
  26. long sys_fork(void)
  27. {
  28. long ret;
  29. current->thread.forking = 1;
  30. ret = do_fork(SIGCHLD, 0, NULL, 0, NULL, NULL);
  31. current->thread.forking = 0;
  32. return(ret);
  33. }
  34. long sys_vfork(void)
  35. {
  36. long ret;
  37. current->thread.forking = 1;
  38. ret = do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, 0, NULL, 0, NULL,
  39. NULL);
  40. current->thread.forking = 0;
  41. return(ret);
  42. }
  43. /* common code for old and new mmaps */
  44. long sys_mmap2(unsigned long addr, unsigned long len,
  45. unsigned long prot, unsigned long flags,
  46. unsigned long fd, unsigned long pgoff)
  47. {
  48. long error = -EBADF;
  49. struct file * file = NULL;
  50. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  51. if (!(flags & MAP_ANONYMOUS)) {
  52. file = fget(fd);
  53. if (!file)
  54. goto out;
  55. }
  56. down_write(&current->mm->mmap_sem);
  57. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  58. up_write(&current->mm->mmap_sem);
  59. if (file)
  60. fput(file);
  61. out:
  62. return error;
  63. }
  64. long old_mmap(unsigned long addr, unsigned long len,
  65. unsigned long prot, unsigned long flags,
  66. unsigned long fd, unsigned long offset)
  67. {
  68. long err = -EINVAL;
  69. if (offset & ~PAGE_MASK)
  70. goto out;
  71. err = sys_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
  72. out:
  73. return err;
  74. }
  75. /*
  76. * sys_pipe() is the normal C calling standard for creating
  77. * a pipe. It's not the way unix traditionally does this, though.
  78. */
  79. long sys_pipe(unsigned long __user * fildes)
  80. {
  81. int fd[2];
  82. long error;
  83. error = do_pipe(fd);
  84. if (!error) {
  85. if (copy_to_user(fildes, fd, sizeof(fd)))
  86. error = -EFAULT;
  87. }
  88. return error;
  89. }
  90. long sys_uname(struct old_utsname * name)
  91. {
  92. long err;
  93. if (!name)
  94. return -EFAULT;
  95. down_read(&uts_sem);
  96. err=copy_to_user(name, &system_utsname, sizeof (*name));
  97. up_read(&uts_sem);
  98. return err?-EFAULT:0;
  99. }
  100. long sys_olduname(struct oldold_utsname * name)
  101. {
  102. long error;
  103. if (!name)
  104. return -EFAULT;
  105. if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
  106. return -EFAULT;
  107. down_read(&uts_sem);
  108. error = __copy_to_user(&name->sysname,&system_utsname.sysname,
  109. __OLD_UTS_LEN);
  110. error |= __put_user(0,name->sysname+__OLD_UTS_LEN);
  111. error |= __copy_to_user(&name->nodename,&system_utsname.nodename,
  112. __OLD_UTS_LEN);
  113. error |= __put_user(0,name->nodename+__OLD_UTS_LEN);
  114. error |= __copy_to_user(&name->release,&system_utsname.release,
  115. __OLD_UTS_LEN);
  116. error |= __put_user(0,name->release+__OLD_UTS_LEN);
  117. error |= __copy_to_user(&name->version,&system_utsname.version,
  118. __OLD_UTS_LEN);
  119. error |= __put_user(0,name->version+__OLD_UTS_LEN);
  120. error |= __copy_to_user(&name->machine,&system_utsname.machine,
  121. __OLD_UTS_LEN);
  122. error |= __put_user(0,name->machine+__OLD_UTS_LEN);
  123. up_read(&uts_sem);
  124. error = error ? -EFAULT : 0;
  125. return error;
  126. }
  127. DEFINE_SPINLOCK(syscall_lock);
  128. static int syscall_index = 0;
  129. int next_syscall_index(int limit)
  130. {
  131. int ret;
  132. spin_lock(&syscall_lock);
  133. ret = syscall_index;
  134. if(++syscall_index == limit)
  135. syscall_index = 0;
  136. spin_unlock(&syscall_lock);
  137. return(ret);
  138. }
  139. /*
  140. * Overrides for Emacs so that we follow Linus's tabbing style.
  141. * Emacs will notice this stuff at the end of the file and automatically
  142. * adjust the settings for this buffer only. This must remain at the end
  143. * of the file.
  144. * ---------------------------------------------------------------------------
  145. * Local variables:
  146. * c-file-style: "linux"
  147. * End:
  148. */