syscall.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  3. * Licensed under the GPL
  4. */
  5. #include "linux/file.h"
  6. #include "linux/fs.h"
  7. #include "linux/mm.h"
  8. #include "linux/sched.h"
  9. #include "linux/utsname.h"
  10. #include "asm/current.h"
  11. #include "asm/mman.h"
  12. #include "asm/uaccess.h"
  13. #include "asm/unistd.h"
  14. /* Unlocked, I don't care if this is a bit off */
  15. int nsyscalls = 0;
  16. long sys_fork(void)
  17. {
  18. long ret;
  19. current->thread.forking = 1;
  20. ret = do_fork(SIGCHLD, UPT_SP(&current->thread.regs.regs),
  21. &current->thread.regs, 0, NULL, NULL);
  22. current->thread.forking = 0;
  23. return ret;
  24. }
  25. long sys_vfork(void)
  26. {
  27. long ret;
  28. current->thread.forking = 1;
  29. ret = do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD,
  30. UPT_SP(&current->thread.regs.regs),
  31. &current->thread.regs, 0, NULL, NULL);
  32. current->thread.forking = 0;
  33. return ret;
  34. }
  35. /* common code for old and new mmaps */
  36. long sys_mmap2(unsigned long addr, unsigned long len,
  37. unsigned long prot, unsigned long flags,
  38. unsigned long fd, unsigned long pgoff)
  39. {
  40. long error = -EBADF;
  41. struct file * file = NULL;
  42. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  43. if (!(flags & MAP_ANONYMOUS)) {
  44. file = fget(fd);
  45. if (!file)
  46. goto out;
  47. }
  48. down_write(&current->mm->mmap_sem);
  49. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  50. up_write(&current->mm->mmap_sem);
  51. if (file)
  52. fput(file);
  53. out:
  54. return error;
  55. }
  56. long old_mmap(unsigned long addr, unsigned long len,
  57. unsigned long prot, unsigned long flags,
  58. unsigned long fd, unsigned long offset)
  59. {
  60. long err = -EINVAL;
  61. if (offset & ~PAGE_MASK)
  62. goto out;
  63. err = sys_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
  64. out:
  65. return err;
  66. }
  67. /*
  68. * sys_pipe() is the normal C calling standard for creating
  69. * a pipe. It's not the way unix traditionally does this, though.
  70. */
  71. long sys_pipe(unsigned long __user * fildes)
  72. {
  73. int fd[2];
  74. long error;
  75. error = do_pipe(fd);
  76. if (!error) {
  77. if (copy_to_user(fildes, fd, sizeof(fd)))
  78. error = -EFAULT;
  79. }
  80. return error;
  81. }
  82. long sys_uname(struct old_utsname __user * name)
  83. {
  84. long err;
  85. if (!name)
  86. return -EFAULT;
  87. down_read(&uts_sem);
  88. err = copy_to_user(name, utsname(), sizeof (*name));
  89. up_read(&uts_sem);
  90. return err?-EFAULT:0;
  91. }
  92. long sys_olduname(struct oldold_utsname __user * name)
  93. {
  94. long error;
  95. if (!name)
  96. return -EFAULT;
  97. if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
  98. return -EFAULT;
  99. down_read(&uts_sem);
  100. error = __copy_to_user(&name->sysname, &utsname()->sysname,
  101. __OLD_UTS_LEN);
  102. error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
  103. error |= __copy_to_user(&name->nodename, &utsname()->nodename,
  104. __OLD_UTS_LEN);
  105. error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
  106. error |= __copy_to_user(&name->release, &utsname()->release,
  107. __OLD_UTS_LEN);
  108. error |= __put_user(0, name->release + __OLD_UTS_LEN);
  109. error |= __copy_to_user(&name->version, &utsname()->version,
  110. __OLD_UTS_LEN);
  111. error |= __put_user(0, name->version + __OLD_UTS_LEN);
  112. error |= __copy_to_user(&name->machine, &utsname()->machine,
  113. __OLD_UTS_LEN);
  114. error |= __put_user(0, name->machine + __OLD_UTS_LEN);
  115. up_read(&uts_sem);
  116. error = error ? -EFAULT : 0;
  117. return error;
  118. }
  119. int kernel_execve(const char *filename, char *const argv[], char *const envp[])
  120. {
  121. mm_segment_t fs;
  122. int ret;
  123. fs = get_fs();
  124. set_fs(KERNEL_DS);
  125. ret = um_execve(filename, argv, envp);
  126. set_fs(fs);
  127. return ret;
  128. }