vdso.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (C) 2015 Imagination Technologies
  3. * Author: Alex Smith <alex.smith@imgtec.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. */
  10. #include <linux/binfmts.h>
  11. #include <linux/elf.h>
  12. #include <linux/err.h>
  13. #include <linux/init.h>
  14. #include <linux/mm.h>
  15. #include <linux/sched.h>
  16. #include <linux/slab.h>
  17. #include <asm/abi.h>
  18. #include <asm/vdso.h>
  19. /* Kernel-provided data used by the VDSO. */
  20. static union mips_vdso_data vdso_data __page_aligned_data;
  21. /*
  22. * Mapping for the VDSO data pages. The real pages are mapped manually, as
  23. * what we map and where within the area they are mapped is determined at
  24. * runtime.
  25. */
  26. static struct page *no_pages[] = { NULL };
  27. static struct vm_special_mapping vdso_vvar_mapping = {
  28. .name = "[vvar]",
  29. .pages = no_pages,
  30. };
  31. static void __init init_vdso_image(struct mips_vdso_image *image)
  32. {
  33. unsigned long num_pages, i;
  34. BUG_ON(!PAGE_ALIGNED(image->data));
  35. BUG_ON(!PAGE_ALIGNED(image->size));
  36. num_pages = image->size / PAGE_SIZE;
  37. for (i = 0; i < num_pages; i++) {
  38. image->mapping.pages[i] =
  39. virt_to_page(image->data + (i * PAGE_SIZE));
  40. }
  41. }
  42. static int __init init_vdso(void)
  43. {
  44. init_vdso_image(&vdso_image);
  45. #ifdef CONFIG_MIPS32_O32
  46. init_vdso_image(&vdso_image_o32);
  47. #endif
  48. #ifdef CONFIG_MIPS32_N32
  49. init_vdso_image(&vdso_image_n32);
  50. #endif
  51. return 0;
  52. }
  53. subsys_initcall(init_vdso);
  54. int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
  55. {
  56. struct mips_vdso_image *image = current->thread.abi->vdso;
  57. struct mm_struct *mm = current->mm;
  58. unsigned long base, vdso_addr;
  59. struct vm_area_struct *vma;
  60. int ret;
  61. down_write(&mm->mmap_sem);
  62. base = get_unmapped_area(NULL, 0, PAGE_SIZE + image->size, 0, 0);
  63. if (IS_ERR_VALUE(base)) {
  64. ret = base;
  65. goto out;
  66. }
  67. vdso_addr = base + PAGE_SIZE;
  68. vma = _install_special_mapping(mm, base, PAGE_SIZE,
  69. VM_READ | VM_MAYREAD,
  70. &vdso_vvar_mapping);
  71. if (IS_ERR(vma)) {
  72. ret = PTR_ERR(vma);
  73. goto out;
  74. }
  75. /* Map data page. */
  76. ret = remap_pfn_range(vma, base,
  77. virt_to_phys(&vdso_data) >> PAGE_SHIFT,
  78. PAGE_SIZE, PAGE_READONLY);
  79. if (ret)
  80. goto out;
  81. /* Map VDSO image. */
  82. vma = _install_special_mapping(mm, vdso_addr, image->size,
  83. VM_READ | VM_EXEC |
  84. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
  85. &image->mapping);
  86. if (IS_ERR(vma)) {
  87. ret = PTR_ERR(vma);
  88. goto out;
  89. }
  90. mm->context.vdso = (void *)vdso_addr;
  91. ret = 0;
  92. out:
  93. up_write(&mm->mmap_sem);
  94. return ret;
  95. }