vdso.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2009, 2010 Cavium Networks, Inc.
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/err.h>
  10. #include <linux/sched.h>
  11. #include <linux/mm.h>
  12. #include <linux/init.h>
  13. #include <linux/binfmts.h>
  14. #include <linux/elf.h>
  15. #include <linux/vmalloc.h>
  16. #include <linux/unistd.h>
  17. #include <linux/random.h>
  18. #include <asm/vdso.h>
  19. #include <asm/uasm.h>
  20. #include <asm/processor.h>
  21. /*
  22. * Including <asm/unistd.h> would give use the 64-bit syscall numbers ...
  23. */
  24. #define __NR_O32_sigreturn 4119
  25. #define __NR_O32_rt_sigreturn 4193
  26. #define __NR_N32_rt_sigreturn 6211
  27. static struct page *vdso_page;
  28. static void __init install_trampoline(u32 *tramp, unsigned int sigreturn)
  29. {
  30. uasm_i_addiu(&tramp, 2, 0, sigreturn); /* li v0, sigreturn */
  31. uasm_i_syscall(&tramp, 0);
  32. }
  33. static int __init init_vdso(void)
  34. {
  35. struct mips_vdso *vdso;
  36. vdso_page = alloc_page(GFP_KERNEL);
  37. if (!vdso_page)
  38. panic("Cannot allocate vdso");
  39. vdso = vmap(&vdso_page, 1, 0, PAGE_KERNEL);
  40. if (!vdso)
  41. panic("Cannot map vdso");
  42. clear_page(vdso);
  43. install_trampoline(vdso->rt_signal_trampoline, __NR_rt_sigreturn);
  44. #ifdef CONFIG_32BIT
  45. install_trampoline(vdso->signal_trampoline, __NR_sigreturn);
  46. #else
  47. install_trampoline(vdso->n32_rt_signal_trampoline,
  48. __NR_N32_rt_sigreturn);
  49. install_trampoline(vdso->o32_signal_trampoline, __NR_O32_sigreturn);
  50. install_trampoline(vdso->o32_rt_signal_trampoline,
  51. __NR_O32_rt_sigreturn);
  52. #endif
  53. vunmap(vdso);
  54. return 0;
  55. }
  56. subsys_initcall(init_vdso);
  57. static unsigned long vdso_addr(unsigned long start)
  58. {
  59. unsigned long offset = 0UL;
  60. if (current->flags & PF_RANDOMIZE) {
  61. offset = get_random_int();
  62. offset <<= PAGE_SHIFT;
  63. if (TASK_IS_32BIT_ADDR)
  64. offset &= 0xfffffful;
  65. else
  66. offset &= 0xffffffful;
  67. }
  68. return STACK_TOP + offset;
  69. }
  70. int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
  71. {
  72. int ret;
  73. unsigned long addr;
  74. struct mm_struct *mm = current->mm;
  75. down_write(&mm->mmap_sem);
  76. addr = vdso_addr(mm->start_stack);
  77. addr = get_unmapped_area(NULL, addr, PAGE_SIZE, 0, 0);
  78. if (IS_ERR_VALUE(addr)) {
  79. ret = addr;
  80. goto up_fail;
  81. }
  82. ret = install_special_mapping(mm, addr, PAGE_SIZE,
  83. VM_READ|VM_EXEC|
  84. VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
  85. &vdso_page);
  86. if (ret)
  87. goto up_fail;
  88. mm->context.vdso = (void *)addr;
  89. up_fail:
  90. up_write(&mm->mmap_sem);
  91. return ret;
  92. }
  93. const char *arch_vma_name(struct vm_area_struct *vma)
  94. {
  95. if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
  96. return "[vdso]";
  97. return NULL;
  98. }