vdso.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * vDSO implementation for Hexagon
  4. *
  5. * Copyright (c) 2011, The Linux Foundation. All rights reserved.
  6. */
  7. #include <linux/err.h>
  8. #include <linux/mm.h>
  9. #include <linux/vmalloc.h>
  10. #include <linux/binfmts.h>
  11. #include <asm/vdso.h>
  12. static struct page *vdso_page;
  13. /* Create a vDSO page holding the signal trampoline.
  14. * We want this for a non-executable stack.
  15. */
  16. static int __init vdso_init(void)
  17. {
  18. struct hexagon_vdso *vdso;
  19. vdso_page = alloc_page(GFP_KERNEL);
  20. if (!vdso_page)
  21. panic("Cannot allocate vdso");
  22. vdso = vmap(&vdso_page, 1, 0, PAGE_KERNEL);
  23. if (!vdso)
  24. panic("Cannot map vdso");
  25. clear_page(vdso);
  26. /* Install the signal trampoline; currently looks like this:
  27. * r6 = #__NR_rt_sigreturn;
  28. * trap0(#1);
  29. */
  30. vdso->rt_signal_trampoline[0] = __rt_sigtramp_template[0];
  31. vdso->rt_signal_trampoline[1] = __rt_sigtramp_template[1];
  32. vunmap(vdso);
  33. return 0;
  34. }
  35. arch_initcall(vdso_init);
  36. /*
  37. * Called from binfmt_elf. Create a VMA for the vDSO page.
  38. */
  39. int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
  40. {
  41. int ret;
  42. unsigned long vdso_base;
  43. struct mm_struct *mm = current->mm;
  44. if (mmap_write_lock_killable(mm))
  45. return -EINTR;
  46. /* Try to get it loaded right near ld.so/glibc. */
  47. vdso_base = STACK_TOP;
  48. vdso_base = get_unmapped_area(NULL, vdso_base, PAGE_SIZE, 0, 0);
  49. if (IS_ERR_VALUE(vdso_base)) {
  50. ret = vdso_base;
  51. goto up_fail;
  52. }
  53. /* MAYWRITE to allow gdb to COW and set breakpoints. */
  54. ret = install_special_mapping(mm, vdso_base, PAGE_SIZE,
  55. VM_READ|VM_EXEC|
  56. VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
  57. &vdso_page);
  58. if (ret)
  59. goto up_fail;
  60. mm->context.vdso = (void *)vdso_base;
  61. up_fail:
  62. mmap_write_unlock(mm);
  63. return ret;
  64. }
  65. const char *arch_vma_name(struct vm_area_struct *vma)
  66. {
  67. if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
  68. return "[vdso]";
  69. return NULL;
  70. }