vdso.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * vDSO implementation for Hexagon
  3. *
  4. * Copyright (c) 2011, The Linux Foundation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 and
  8. * only version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. * 02110-1301, USA.
  19. */
  20. #include <linux/err.h>
  21. #include <linux/mm.h>
  22. #include <linux/vmalloc.h>
  23. #include <linux/binfmts.h>
  24. #include <asm/vdso.h>
  25. static struct page *vdso_page;
  26. /* Create a vDSO page holding the signal trampoline.
  27. * We want this for a non-executable stack.
  28. */
  29. static int __init vdso_init(void)
  30. {
  31. struct hexagon_vdso *vdso;
  32. vdso_page = alloc_page(GFP_KERNEL);
  33. if (!vdso_page)
  34. panic("Cannot allocate vdso");
  35. vdso = vmap(&vdso_page, 1, 0, PAGE_KERNEL);
  36. if (!vdso)
  37. panic("Cannot map vdso");
  38. clear_page(vdso);
  39. /* Install the signal trampoline; currently looks like this:
  40. * r6 = #__NR_rt_sigreturn;
  41. * trap0(#1);
  42. */
  43. vdso->rt_signal_trampoline[0] = __rt_sigtramp_template[0];
  44. vdso->rt_signal_trampoline[1] = __rt_sigtramp_template[1];
  45. vunmap(vdso);
  46. return 0;
  47. }
  48. arch_initcall(vdso_init);
  49. /*
  50. * Called from binfmt_elf. Create a VMA for the vDSO page.
  51. */
  52. int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
  53. {
  54. int ret;
  55. unsigned long vdso_base;
  56. struct mm_struct *mm = current->mm;
  57. if (down_write_killable(&mm->mmap_sem))
  58. return -EINTR;
  59. /* Try to get it loaded right near ld.so/glibc. */
  60. vdso_base = STACK_TOP;
  61. vdso_base = get_unmapped_area(NULL, vdso_base, PAGE_SIZE, 0, 0);
  62. if (IS_ERR_VALUE(vdso_base)) {
  63. ret = vdso_base;
  64. goto up_fail;
  65. }
  66. /* MAYWRITE to allow gdb to COW and set breakpoints. */
  67. ret = install_special_mapping(mm, vdso_base, PAGE_SIZE,
  68. VM_READ|VM_EXEC|
  69. VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
  70. &vdso_page);
  71. if (ret)
  72. goto up_fail;
  73. mm->context.vdso = (void *)vdso_base;
  74. up_fail:
  75. up_write(&mm->mmap_sem);
  76. return ret;
  77. }
  78. const char *arch_vma_name(struct vm_area_struct *vma)
  79. {
  80. if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
  81. return "[vdso]";
  82. return NULL;
  83. }