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 <linux/init.h>
  13. unsigned int __read_mostly vdso_enabled = 1;
  14. unsigned long um_vdso_addr;
  15. extern unsigned long task_size;
  16. extern char vdso_start[], vdso_end[];
  17. static struct page **vdsop;
  18. static int __init init_vdso(void)
  19. {
  20. struct page *um_vdso;
  21. BUG_ON(vdso_end - vdso_start > PAGE_SIZE);
  22. um_vdso_addr = task_size - PAGE_SIZE;
  23. vdsop = kmalloc(sizeof(struct page *), GFP_KERNEL);
  24. if (!vdsop)
  25. goto oom;
  26. um_vdso = alloc_page(GFP_KERNEL);
  27. if (!um_vdso) {
  28. kfree(vdsop);
  29. goto oom;
  30. }
  31. copy_page(page_address(um_vdso), vdso_start);
  32. *vdsop = um_vdso;
  33. return 0;
  34. oom:
  35. printk(KERN_ERR "Cannot allocate vdso\n");
  36. vdso_enabled = 0;
  37. return -ENOMEM;
  38. }
  39. subsys_initcall(init_vdso);
  40. int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
  41. {
  42. int err;
  43. struct mm_struct *mm = current->mm;
  44. if (!vdso_enabled)
  45. return 0;
  46. down_write(&mm->mmap_sem);
  47. err = install_special_mapping(mm, um_vdso_addr, PAGE_SIZE,
  48. VM_READ|VM_EXEC|
  49. VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
  50. vdsop);
  51. up_write(&mm->mmap_sem);
  52. return err;
  53. }