sys_x86_64.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * linux/arch/x86_64/kernel/sys_x86_64.c
  3. */
  4. #include <linux/errno.h>
  5. #include <linux/sched.h>
  6. #include <linux/syscalls.h>
  7. #include <linux/mm.h>
  8. #include <linux/smp.h>
  9. #include <linux/smp_lock.h>
  10. #include <linux/sem.h>
  11. #include <linux/msg.h>
  12. #include <linux/shm.h>
  13. #include <linux/stat.h>
  14. #include <linux/mman.h>
  15. #include <linux/file.h>
  16. #include <linux/utsname.h>
  17. #include <linux/personality.h>
  18. #include <asm/uaccess.h>
  19. #include <asm/ia32.h>
  20. /*
  21. * sys_pipe() is the normal C calling standard for creating
  22. * a pipe. It's not the way Unix traditionally does this, though.
  23. */
  24. asmlinkage long sys_pipe(int __user *fildes)
  25. {
  26. int fd[2];
  27. int error;
  28. error = do_pipe(fd);
  29. if (!error) {
  30. if (copy_to_user(fildes, fd, 2*sizeof(int)))
  31. error = -EFAULT;
  32. }
  33. return error;
  34. }
  35. asmlinkage long sys_mmap(unsigned long addr, unsigned long len, unsigned long prot, unsigned long flags,
  36. unsigned long fd, unsigned long off)
  37. {
  38. long error;
  39. struct file * file;
  40. error = -EINVAL;
  41. if (off & ~PAGE_MASK)
  42. goto out;
  43. error = -EBADF;
  44. file = NULL;
  45. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  46. if (!(flags & MAP_ANONYMOUS)) {
  47. file = fget(fd);
  48. if (!file)
  49. goto out;
  50. }
  51. down_write(&current->mm->mmap_sem);
  52. error = do_mmap_pgoff(file, addr, len, prot, flags, off >> PAGE_SHIFT);
  53. up_write(&current->mm->mmap_sem);
  54. if (file)
  55. fput(file);
  56. out:
  57. return error;
  58. }
  59. static void find_start_end(unsigned long flags, unsigned long *begin,
  60. unsigned long *end)
  61. {
  62. if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
  63. /* This is usually used needed to map code in small
  64. model, so it needs to be in the first 31bit. Limit
  65. it to that. This means we need to move the
  66. unmapped base down for this case. This can give
  67. conflicts with the heap, but we assume that glibc
  68. malloc knows how to fall back to mmap. Give it 1GB
  69. of playground for now. -AK */
  70. *begin = 0x40000000;
  71. *end = 0x80000000;
  72. } else {
  73. *begin = TASK_UNMAPPED_BASE;
  74. *end = TASK_SIZE;
  75. }
  76. }
  77. unsigned long
  78. arch_get_unmapped_area(struct file *filp, unsigned long addr,
  79. unsigned long len, unsigned long pgoff, unsigned long flags)
  80. {
  81. struct mm_struct *mm = current->mm;
  82. struct vm_area_struct *vma;
  83. unsigned long start_addr;
  84. unsigned long begin, end;
  85. find_start_end(flags, &begin, &end);
  86. if (len > end)
  87. return -ENOMEM;
  88. if (addr) {
  89. addr = PAGE_ALIGN(addr);
  90. vma = find_vma(mm, addr);
  91. if (end - len >= addr &&
  92. (!vma || addr + len <= vma->vm_start))
  93. return addr;
  94. }
  95. if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
  96. && len <= mm->cached_hole_size) {
  97. mm->cached_hole_size = 0;
  98. mm->free_area_cache = begin;
  99. }
  100. addr = mm->free_area_cache;
  101. if (addr < begin)
  102. addr = begin;
  103. start_addr = addr;
  104. full_search:
  105. for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
  106. /* At this point: (!vma || addr < vma->vm_end). */
  107. if (end - len < addr) {
  108. /*
  109. * Start a new search - just in case we missed
  110. * some holes.
  111. */
  112. if (start_addr != begin) {
  113. start_addr = addr = begin;
  114. mm->cached_hole_size = 0;
  115. goto full_search;
  116. }
  117. return -ENOMEM;
  118. }
  119. if (!vma || addr + len <= vma->vm_start) {
  120. /*
  121. * Remember the place where we stopped the search:
  122. */
  123. mm->free_area_cache = addr + len;
  124. return addr;
  125. }
  126. if (addr + mm->cached_hole_size < vma->vm_start)
  127. mm->cached_hole_size = vma->vm_start - addr;
  128. addr = vma->vm_end;
  129. }
  130. }
  131. asmlinkage long sys_uname(struct new_utsname __user * name)
  132. {
  133. int err;
  134. down_read(&uts_sem);
  135. err = copy_to_user(name, &system_utsname, sizeof (*name));
  136. up_read(&uts_sem);
  137. if (personality(current->personality) == PER_LINUX32)
  138. err |= copy_to_user(&name->machine, "i686", 5);
  139. return err ? -EFAULT : 0;
  140. }
  141. asmlinkage long sys_time64(long __user * tloc)
  142. {
  143. struct timeval now;
  144. int i;
  145. do_gettimeofday(&now);
  146. i = now.tv_sec;
  147. if (tloc) {
  148. if (put_user(i,tloc))
  149. i = -EFAULT;
  150. }
  151. return i;
  152. }