vsyscall.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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,
  55. int executable_stack)
  56. {
  57. struct mm_struct *mm = current->mm;
  58. unsigned long addr;
  59. int ret;
  60. down_write(&mm->mmap_sem);
  61. addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
  62. if (IS_ERR_VALUE(addr)) {
  63. ret = addr;
  64. goto up_fail;
  65. }
  66. ret = install_special_mapping(mm, addr, PAGE_SIZE,
  67. VM_READ | VM_EXEC |
  68. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC |
  69. VM_ALWAYSDUMP,
  70. syscall_pages);
  71. if (unlikely(ret))
  72. goto up_fail;
  73. current->mm->context.vdso = (void *)addr;
  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. }
  84. struct vm_area_struct *get_gate_vma(struct task_struct *task)
  85. {
  86. return NULL;
  87. }
  88. int in_gate_area(struct task_struct *task, unsigned long address)
  89. {
  90. return 0;
  91. }
  92. int in_gate_area_no_task(unsigned long address)
  93. {
  94. return 0;
  95. }