mmap.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * linux/arch/s390/mm/mmap.c
  3. *
  4. * flexible mmap layout support
  5. *
  6. * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina.
  7. * All Rights Reserved.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. *
  24. * Started by Ingo Molnar <mingo@elte.hu>
  25. */
  26. #include <linux/personality.h>
  27. #include <linux/mm.h>
  28. #include <linux/module.h>
  29. #include <asm/pgalloc.h>
  30. /*
  31. * Top of mmap area (just below the process stack).
  32. *
  33. * Leave an at least ~128 MB hole.
  34. */
  35. #define MIN_GAP (128*1024*1024)
  36. #define MAX_GAP (TASK_SIZE/6*5)
  37. static inline unsigned long mmap_base(void)
  38. {
  39. unsigned long gap = current->signal->rlim[RLIMIT_STACK].rlim_cur;
  40. if (gap < MIN_GAP)
  41. gap = MIN_GAP;
  42. else if (gap > MAX_GAP)
  43. gap = MAX_GAP;
  44. return TASK_SIZE - (gap & PAGE_MASK);
  45. }
  46. static inline int mmap_is_legacy(void)
  47. {
  48. #ifdef CONFIG_64BIT
  49. /*
  50. * Force standard allocation for 64 bit programs.
  51. */
  52. if (!test_thread_flag(TIF_31BIT))
  53. return 1;
  54. #endif
  55. return sysctl_legacy_va_layout ||
  56. (current->personality & ADDR_COMPAT_LAYOUT) ||
  57. current->signal->rlim[RLIMIT_STACK].rlim_cur == RLIM_INFINITY;
  58. }
  59. #ifndef CONFIG_64BIT
  60. /*
  61. * This function, called very early during the creation of a new
  62. * process VM image, sets up which VM layout function to use:
  63. */
  64. void arch_pick_mmap_layout(struct mm_struct *mm)
  65. {
  66. /*
  67. * Fall back to the standard layout if the personality
  68. * bit is set, or if the expected stack growth is unlimited:
  69. */
  70. if (mmap_is_legacy()) {
  71. mm->mmap_base = TASK_UNMAPPED_BASE;
  72. mm->get_unmapped_area = arch_get_unmapped_area;
  73. mm->unmap_area = arch_unmap_area;
  74. } else {
  75. mm->mmap_base = mmap_base();
  76. mm->get_unmapped_area = arch_get_unmapped_area_topdown;
  77. mm->unmap_area = arch_unmap_area_topdown;
  78. }
  79. }
  80. EXPORT_SYMBOL_GPL(arch_pick_mmap_layout);
  81. #else
  82. static unsigned long
  83. s390_get_unmapped_area(struct file *filp, unsigned long addr,
  84. unsigned long len, unsigned long pgoff, unsigned long flags)
  85. {
  86. struct mm_struct *mm = current->mm;
  87. int rc;
  88. addr = arch_get_unmapped_area(filp, addr, len, pgoff, flags);
  89. if (addr & ~PAGE_MASK)
  90. return addr;
  91. if (unlikely(mm->context.asce_limit < addr + len)) {
  92. rc = crst_table_upgrade(mm, addr + len);
  93. if (rc)
  94. return (unsigned long) rc;
  95. }
  96. return addr;
  97. }
  98. static unsigned long
  99. s390_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  100. const unsigned long len, const unsigned long pgoff,
  101. const unsigned long flags)
  102. {
  103. struct mm_struct *mm = current->mm;
  104. unsigned long addr = addr0;
  105. int rc;
  106. addr = arch_get_unmapped_area_topdown(filp, addr, len, pgoff, flags);
  107. if (addr & ~PAGE_MASK)
  108. return addr;
  109. if (unlikely(mm->context.asce_limit < addr + len)) {
  110. rc = crst_table_upgrade(mm, addr + len);
  111. if (rc)
  112. return (unsigned long) rc;
  113. }
  114. return addr;
  115. }
  116. /*
  117. * This function, called very early during the creation of a new
  118. * process VM image, sets up which VM layout function to use:
  119. */
  120. void arch_pick_mmap_layout(struct mm_struct *mm)
  121. {
  122. /*
  123. * Fall back to the standard layout if the personality
  124. * bit is set, or if the expected stack growth is unlimited:
  125. */
  126. if (mmap_is_legacy()) {
  127. mm->mmap_base = TASK_UNMAPPED_BASE;
  128. mm->get_unmapped_area = s390_get_unmapped_area;
  129. mm->unmap_area = arch_unmap_area;
  130. } else {
  131. mm->mmap_base = mmap_base();
  132. mm->get_unmapped_area = s390_get_unmapped_area_topdown;
  133. mm->unmap_area = arch_unmap_area_topdown;
  134. }
  135. }
  136. EXPORT_SYMBOL_GPL(arch_pick_mmap_layout);
  137. #endif