vma.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (C) 2011 Richard Weinberger <richrd@nod.at>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/slab.h>
  9. #include <linux/sched.h>
  10. #include <linux/mm.h>
  11. #include <asm/page.h>
  12. #include <asm/elf.h>
  13. #include <linux/init.h>
  14. static unsigned int __read_mostly vdso_enabled = 1;
  15. unsigned long um_vdso_addr;
  16. extern unsigned long task_size;
  17. extern char vdso_start[], vdso_end[];
  18. static struct page **vdsop;
  19. static int __init init_vdso(void)
  20. {
  21. struct page *um_vdso;
  22. BUG_ON(vdso_end - vdso_start > PAGE_SIZE);
  23. um_vdso_addr = task_size - PAGE_SIZE;
  24. vdsop = kmalloc(sizeof(struct page *), GFP_KERNEL);
  25. if (!vdsop)
  26. goto oom;
  27. um_vdso = alloc_page(GFP_KERNEL);
  28. if (!um_vdso) {
  29. kfree(vdsop);
  30. goto oom;
  31. }
  32. copy_page(page_address(um_vdso), vdso_start);
  33. *vdsop = um_vdso;
  34. return 0;
  35. oom:
  36. printk(KERN_ERR "Cannot allocate vdso\n");
  37. vdso_enabled = 0;
  38. return -ENOMEM;
  39. }
  40. subsys_initcall(init_vdso);
  41. int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
  42. {
  43. int err;
  44. struct mm_struct *mm = current->mm;
  45. if (!vdso_enabled)
  46. return 0;
  47. down_write(&mm->mmap_sem);
  48. err = install_special_mapping(mm, um_vdso_addr, PAGE_SIZE,
  49. VM_READ|VM_EXEC|
  50. VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
  51. vdsop);
  52. up_write(&mm->mmap_sem);
  53. return err;
  54. }