vdso.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 <asm/vdso.h>
  18. #include <asm/uasm.h>
  19. /*
  20. * Including <asm/unistd.h> would give use the 64-bit syscall numbers ...
  21. */
  22. #define __NR_O32_sigreturn 4119
  23. #define __NR_O32_rt_sigreturn 4193
  24. #define __NR_N32_rt_sigreturn 6211
  25. static struct page *vdso_page;
  26. static void __init install_trampoline(u32 *tramp, unsigned int sigreturn)
  27. {
  28. uasm_i_addiu(&tramp, 2, 0, sigreturn); /* li v0, sigreturn */
  29. uasm_i_syscall(&tramp, 0);
  30. }
  31. static int __init init_vdso(void)
  32. {
  33. struct mips_vdso *vdso;
  34. vdso_page = alloc_page(GFP_KERNEL);
  35. if (!vdso_page)
  36. panic("Cannot allocate vdso");
  37. vdso = vmap(&vdso_page, 1, 0, PAGE_KERNEL);
  38. if (!vdso)
  39. panic("Cannot map vdso");
  40. clear_page(vdso);
  41. install_trampoline(vdso->rt_signal_trampoline, __NR_rt_sigreturn);
  42. #ifdef CONFIG_32BIT
  43. install_trampoline(vdso->signal_trampoline, __NR_sigreturn);
  44. #else
  45. install_trampoline(vdso->n32_rt_signal_trampoline,
  46. __NR_N32_rt_sigreturn);
  47. install_trampoline(vdso->o32_signal_trampoline, __NR_O32_sigreturn);
  48. install_trampoline(vdso->o32_rt_signal_trampoline,
  49. __NR_O32_rt_sigreturn);
  50. #endif
  51. vunmap(vdso);
  52. return 0;
  53. }
  54. subsys_initcall(init_vdso);
  55. static unsigned long vdso_addr(unsigned long start)
  56. {
  57. return STACK_TOP;
  58. }
  59. int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
  60. {
  61. int ret;
  62. unsigned long addr;
  63. struct mm_struct *mm = current->mm;
  64. down_write(&mm->mmap_sem);
  65. addr = vdso_addr(mm->start_stack);
  66. addr = get_unmapped_area(NULL, addr, PAGE_SIZE, 0, 0);
  67. if (IS_ERR_VALUE(addr)) {
  68. ret = addr;
  69. goto up_fail;
  70. }
  71. ret = install_special_mapping(mm, addr, PAGE_SIZE,
  72. VM_READ|VM_EXEC|
  73. VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
  74. VM_ALWAYSDUMP,
  75. &vdso_page);
  76. if (ret)
  77. goto up_fail;
  78. mm->context.vdso = (void *)addr;
  79. up_fail:
  80. up_write(&mm->mmap_sem);
  81. return ret;
  82. }
  83. const char *arch_vma_name(struct vm_area_struct *vma)
  84. {
  85. if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
  86. return "[vdso]";
  87. return NULL;
  88. }