vsyscall.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. down_write(&mm->mmap_sem);
  59. addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
  60. if (IS_ERR_VALUE(addr)) {
  61. ret = addr;
  62. goto up_fail;
  63. }
  64. ret = install_special_mapping(mm, addr, PAGE_SIZE,
  65. VM_READ | VM_EXEC |
  66. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
  67. syscall_pages);
  68. if (unlikely(ret))
  69. goto up_fail;
  70. current->mm->context.vdso = (void *)addr;
  71. up_fail:
  72. up_write(&mm->mmap_sem);
  73. return ret;
  74. }
  75. const char *arch_vma_name(struct vm_area_struct *vma)
  76. {
  77. if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
  78. return "[vdso]";
  79. return NULL;
  80. }