mem.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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/mm.h>
  9. #include <asm/page.h>
  10. #include <asm/mman.h>
  11. static struct vm_area_struct gate_vma;
  12. static int __init gate_vma_init(void)
  13. {
  14. if (!FIXADDR_USER_START)
  15. return 0;
  16. gate_vma.vm_mm = NULL;
  17. gate_vma.vm_start = FIXADDR_USER_START;
  18. gate_vma.vm_end = FIXADDR_USER_END;
  19. gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
  20. gate_vma.vm_page_prot = __P101;
  21. /*
  22. * Make sure the vDSO gets into every core dump.
  23. * Dumping its contents makes post-mortem fully interpretable later
  24. * without matching up the same kernel and hardware config to see
  25. * what PC values meant.
  26. */
  27. gate_vma.vm_flags |= VM_ALWAYSDUMP;
  28. return 0;
  29. }
  30. __initcall(gate_vma_init);
  31. struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
  32. {
  33. return FIXADDR_USER_START ? &gate_vma : NULL;
  34. }
  35. int in_gate_area_no_mm(unsigned long addr)
  36. {
  37. if (!FIXADDR_USER_START)
  38. return 0;
  39. if ((addr >= FIXADDR_USER_START) && (addr < FIXADDR_USER_END))
  40. return 1;
  41. return 0;
  42. }
  43. int in_gate_area(struct mm_struct *mm, unsigned long addr)
  44. {
  45. struct vm_area_struct *vma = get_gate_vma(mm);
  46. if (!vma)
  47. return 0;
  48. return (addr >= vma->vm_start) && (addr < vma->vm_end);
  49. }