vsyscall.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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/slab.h>
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/gfp.h>
  18. #include <linux/module.h>
  19. #include <linux/elf.h>
  20. #include <linux/sched.h>
  21. #include <linux/err.h>
  22. /*
  23. * Should the kernel map a VDSO page into processes and pass its
  24. * address down to glibc upon exec()?
  25. */
  26. unsigned int __read_mostly vdso_enabled = 1;
  27. EXPORT_SYMBOL_GPL(vdso_enabled);
  28. static int __init vdso_setup(char *s)
  29. {
  30. vdso_enabled = simple_strtoul(s, NULL, 0);
  31. return 1;
  32. }
  33. __setup("vdso=", vdso_setup);
  34. /*
  35. * These symbols are defined by vsyscall.o to mark the bounds
  36. * of the ELF DSO images included therein.
  37. */
  38. extern const char vsyscall_trapa_start, vsyscall_trapa_end;
  39. static struct page *syscall_pages[1];
  40. int __init vsyscall_init(void)
  41. {
  42. void *syscall_page = (void *)get_zeroed_page(GFP_ATOMIC);
  43. syscall_pages[0] = virt_to_page(syscall_page);
  44. /*
  45. * XXX: Map this page to a fixmap entry if we get around
  46. * to adding the page to ELF core dumps
  47. */
  48. memcpy(syscall_page,
  49. &vsyscall_trapa_start,
  50. &vsyscall_trapa_end - &vsyscall_trapa_start);
  51. return 0;
  52. }
  53. /* Setup a VMA at program startup for the vsyscall page */
  54. int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
  55. {
  56. struct mm_struct *mm = current->mm;
  57. unsigned long addr;
  58. int ret;
  59. down_write(&mm->mmap_sem);
  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. VM_ALWAYSDUMP,
  69. syscall_pages);
  70. if (unlikely(ret))
  71. goto up_fail;
  72. current->mm->context.vdso = (void *)addr;
  73. up_fail:
  74. up_write(&mm->mmap_sem);
  75. return ret;
  76. }
  77. const char *arch_vma_name(struct vm_area_struct *vma)
  78. {
  79. if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
  80. return "[vdso]";
  81. return NULL;
  82. }
  83. struct vm_area_struct *get_gate_vma(struct task_struct *task)
  84. {
  85. return NULL;
  86. }
  87. int in_gate_area(struct task_struct *task, unsigned long address)
  88. {
  89. return 0;
  90. }
  91. int in_gate_area_no_task(unsigned long address)
  92. {
  93. return 0;
  94. }