vdso.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright (C) 2004 Benjamin Herrenschmidt, IBM Corp.
  3. * <benh@kernel.crashing.org>
  4. * Copyright (C) 2012 ARM Limited
  5. * Copyright (C) 2015 Regents of the University of California
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/mm.h>
  20. #include <linux/slab.h>
  21. #include <linux/binfmts.h>
  22. #include <linux/err.h>
  23. #include <asm/vdso.h>
  24. extern char vdso_start[], vdso_end[];
  25. static unsigned int vdso_pages;
  26. static struct page **vdso_pagelist;
  27. /*
  28. * The vDSO data page.
  29. */
  30. static union {
  31. struct vdso_data data;
  32. u8 page[PAGE_SIZE];
  33. } vdso_data_store __page_aligned_data;
  34. struct vdso_data *vdso_data = &vdso_data_store.data;
  35. static int __init vdso_init(void)
  36. {
  37. unsigned int i;
  38. vdso_pages = (vdso_end - vdso_start) >> PAGE_SHIFT;
  39. vdso_pagelist =
  40. kcalloc(vdso_pages + 1, sizeof(struct page *), GFP_KERNEL);
  41. if (unlikely(vdso_pagelist == NULL)) {
  42. pr_err("vdso: pagelist allocation failed\n");
  43. return -ENOMEM;
  44. }
  45. for (i = 0; i < vdso_pages; i++) {
  46. struct page *pg;
  47. pg = virt_to_page(vdso_start + (i << PAGE_SHIFT));
  48. ClearPageReserved(pg);
  49. vdso_pagelist[i] = pg;
  50. }
  51. vdso_pagelist[i] = virt_to_page(vdso_data);
  52. return 0;
  53. }
  54. arch_initcall(vdso_init);
  55. int arch_setup_additional_pages(struct linux_binprm *bprm,
  56. int uses_interp)
  57. {
  58. struct mm_struct *mm = current->mm;
  59. unsigned long vdso_base, vdso_len;
  60. int ret;
  61. vdso_len = (vdso_pages + 1) << PAGE_SHIFT;
  62. down_write(&mm->mmap_sem);
  63. vdso_base = get_unmapped_area(NULL, 0, vdso_len, 0, 0);
  64. if (IS_ERR_VALUE(vdso_base)) {
  65. ret = vdso_base;
  66. goto end;
  67. }
  68. /*
  69. * Put vDSO base into mm struct. We need to do this before calling
  70. * install_special_mapping or the perf counter mmap tracking code
  71. * will fail to recognise it as a vDSO (since arch_vma_name fails).
  72. */
  73. mm->context.vdso = (void *)vdso_base;
  74. ret = install_special_mapping(mm, vdso_base, vdso_len,
  75. (VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC),
  76. vdso_pagelist);
  77. if (unlikely(ret))
  78. mm->context.vdso = NULL;
  79. end:
  80. up_write(&mm->mmap_sem);
  81. return ret;
  82. }
  83. const char *arch_vma_name(struct vm_area_struct *vma)
  84. {
  85. if (vma->vm_mm && (vma->vm_start == (long)vma->vm_mm->context.vdso))
  86. return "[vdso]";
  87. return NULL;
  88. }
  89. /*
  90. * Function stubs to prevent linker errors when AT_SYSINFO_EHDR is defined
  91. */
  92. int in_gate_area_no_mm(unsigned long addr)
  93. {
  94. return 0;
  95. }
  96. int in_gate_area(struct mm_struct *mm, unsigned long addr)
  97. {
  98. return 0;
  99. }
  100. struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
  101. {
  102. return NULL;
  103. }