vsyscall.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * arch/sh/kernel/vsyscall/vsyscall.c
  3. *
  4. * Copyright (C) 2006 Paul Mundt
  5. *
  6. * vDSO randomization
  7. * Copyright(C) 2005-2006, Red Hat, Inc., Ingo Molnar
  8. *
  9. * This file is subject to the terms and conditions of the GNU General Public
  10. * License. See the file "COPYING" in the main directory of this archive
  11. * for more details.
  12. */
  13. #include <linux/mm.h>
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/gfp.h>
  17. #include <linux/module.h>
  18. #include <linux/elf.h>
  19. #include <linux/sched.h>
  20. #include <linux/err.h>
  21. /*
  22. * Should the kernel map a VDSO page into processes and pass its
  23. * address down to glibc upon exec()?
  24. */
  25. unsigned int __read_mostly vdso_enabled = 1;
  26. EXPORT_SYMBOL_GPL(vdso_enabled);
  27. static int __init vdso_setup(char *s)
  28. {
  29. vdso_enabled = simple_strtoul(s, NULL, 0);
  30. return 1;
  31. }
  32. __setup("vdso=", vdso_setup);
  33. /*
  34. * These symbols are defined by vsyscall.o to mark the bounds
  35. * of the ELF DSO images included therein.
  36. */
  37. extern const char vsyscall_trapa_start, vsyscall_trapa_end;
  38. static struct page *syscall_pages[1];
  39. int __init vsyscall_init(void)
  40. {
  41. void *syscall_page = (void *)get_zeroed_page(GFP_ATOMIC);
  42. syscall_pages[0] = virt_to_page(syscall_page);
  43. /*
  44. * XXX: Map this page to a fixmap entry if we get around
  45. * to adding the page to ELF core dumps
  46. */
  47. memcpy(syscall_page,
  48. &vsyscall_trapa_start,
  49. &vsyscall_trapa_end - &vsyscall_trapa_start);
  50. return 0;
  51. }
  52. /* Setup a VMA at program startup for the vsyscall page */
  53. int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
  54. {
  55. struct mm_struct *mm = current->mm;
  56. unsigned long addr;
  57. int ret;
  58. if (down_write_killable(&mm->mmap_sem))
  59. return -EINTR;
  60. addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
  61. if (IS_ERR_VALUE(addr)) {
  62. ret = addr;
  63. goto up_fail;
  64. }
  65. ret = install_special_mapping(mm, addr, PAGE_SIZE,
  66. VM_READ | VM_EXEC |
  67. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
  68. syscall_pages);
  69. if (unlikely(ret))
  70. goto up_fail;
  71. current->mm->context.vdso = (void *)addr;
  72. up_fail:
  73. up_write(&mm->mmap_sem);
  74. return ret;
  75. }
  76. const char *arch_vma_name(struct vm_area_struct *vma)
  77. {
  78. if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
  79. return "[vdso]";
  80. return NULL;
  81. }