syscall.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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/fs.h"
  10. #include "linux/utsname.h"
  11. #include "linux/msg.h"
  12. #include "linux/shm.h"
  13. #include "linux/sys.h"
  14. #include "linux/syscalls.h"
  15. #include "linux/unistd.h"
  16. #include "linux/slab.h"
  17. #include "linux/utime.h"
  18. #include "asm/mman.h"
  19. #include "asm/uaccess.h"
  20. #include "kern_util.h"
  21. #include "sysdep/syscalls.h"
  22. /* Unlocked, I don't care if this is a bit off */
  23. int nsyscalls = 0;
  24. long sys_fork(void)
  25. {
  26. long ret;
  27. current->thread.forking = 1;
  28. ret = do_fork(SIGCHLD, UPT_SP(&current->thread.regs.regs),
  29. &current->thread.regs, 0, NULL, NULL);
  30. current->thread.forking = 0;
  31. return(ret);
  32. }
  33. long sys_vfork(void)
  34. {
  35. long ret;
  36. current->thread.forking = 1;
  37. ret = do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD,
  38. UPT_SP(&current->thread.regs.regs),
  39. &current->thread.regs, 0, NULL, 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 __user * name)
  91. {
  92. long err;
  93. if (!name)
  94. return -EFAULT;
  95. down_read(&uts_sem);
  96. err = copy_to_user(name, utsname(), sizeof (*name));
  97. up_read(&uts_sem);
  98. return err?-EFAULT:0;
  99. }
  100. long sys_olduname(struct oldold_utsname __user * 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, &utsname()->sysname,
  109. __OLD_UTS_LEN);
  110. error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
  111. error |= __copy_to_user(&name->nodename, &utsname()->nodename,
  112. __OLD_UTS_LEN);
  113. error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
  114. error |= __copy_to_user(&name->release, &utsname()->release,
  115. __OLD_UTS_LEN);
  116. error |= __put_user(0, name->release + __OLD_UTS_LEN);
  117. error |= __copy_to_user(&name->version, &utsname()->version,
  118. __OLD_UTS_LEN);
  119. error |= __put_user(0, name->version + __OLD_UTS_LEN);
  120. error |= __copy_to_user(&name->machine, &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. int kernel_execve(const char *filename, char *const argv[], char *const envp[])
  128. {
  129. mm_segment_t fs;
  130. int ret;
  131. fs = get_fs();
  132. set_fs(KERNEL_DS);
  133. ret = um_execve(filename, argv, envp);
  134. set_fs(fs);
  135. return ret;
  136. }