vdso.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
  3. #include <linux/kernel.h>
  4. #include <linux/err.h>
  5. #include <linux/sched.h>
  6. #include <linux/mm.h>
  7. #include <linux/init.h>
  8. #include <linux/binfmts.h>
  9. #include <linux/elf.h>
  10. #include <linux/vmalloc.h>
  11. #include <linux/unistd.h>
  12. #include <linux/uaccess.h>
  13. #include <asm/vdso.h>
  14. #include <asm/cacheflush.h>
  15. static struct page *vdso_page;
  16. static int __init init_vdso(void)
  17. {
  18. struct csky_vdso *vdso;
  19. int err = 0;
  20. vdso_page = alloc_page(GFP_KERNEL);
  21. if (!vdso_page)
  22. panic("Cannot allocate vdso");
  23. vdso = vmap(&vdso_page, 1, 0, PAGE_KERNEL);
  24. if (!vdso)
  25. panic("Cannot map vdso");
  26. clear_page(vdso);
  27. err = setup_vdso_page(vdso->rt_signal_retcode);
  28. if (err)
  29. panic("Cannot set signal return code, err: %x.", err);
  30. dcache_wb_range((unsigned long)vdso, (unsigned long)vdso + 16);
  31. vunmap(vdso);
  32. return 0;
  33. }
  34. subsys_initcall(init_vdso);
  35. int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
  36. {
  37. int ret;
  38. unsigned long addr;
  39. struct mm_struct *mm = current->mm;
  40. down_write(&mm->mmap_sem);
  41. addr = get_unmapped_area(NULL, STACK_TOP, PAGE_SIZE, 0, 0);
  42. if (IS_ERR_VALUE(addr)) {
  43. ret = addr;
  44. goto up_fail;
  45. }
  46. ret = install_special_mapping(
  47. mm,
  48. addr,
  49. PAGE_SIZE,
  50. VM_READ|VM_EXEC|VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
  51. &vdso_page);
  52. if (ret)
  53. goto up_fail;
  54. mm->context.vdso = (void *)addr;
  55. up_fail:
  56. up_write(&mm->mmap_sem);
  57. return ret;
  58. }
  59. const char *arch_vma_name(struct vm_area_struct *vma)
  60. {
  61. if (vma->vm_mm == NULL)
  62. return NULL;
  63. if (vma->vm_start == (long)vma->vm_mm->context.vdso)
  64. return "[vdso]";
  65. else
  66. return NULL;
  67. }