mem_32.c 994 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2011 Richard Weinberger <richrd@nod.at>
  4. */
  5. #include <linux/mm.h>
  6. #include <asm/elf.h>
  7. static struct vm_area_struct gate_vma;
  8. static int __init gate_vma_init(void)
  9. {
  10. if (!FIXADDR_USER_START)
  11. return 0;
  12. vma_init(&gate_vma, NULL);
  13. gate_vma.vm_start = FIXADDR_USER_START;
  14. gate_vma.vm_end = FIXADDR_USER_END;
  15. gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
  16. gate_vma.vm_page_prot = __P101;
  17. return 0;
  18. }
  19. __initcall(gate_vma_init);
  20. struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
  21. {
  22. return FIXADDR_USER_START ? &gate_vma : NULL;
  23. }
  24. int in_gate_area_no_mm(unsigned long addr)
  25. {
  26. if (!FIXADDR_USER_START)
  27. return 0;
  28. if ((addr >= FIXADDR_USER_START) && (addr < FIXADDR_USER_END))
  29. return 1;
  30. return 0;
  31. }
  32. int in_gate_area(struct mm_struct *mm, unsigned long addr)
  33. {
  34. struct vm_area_struct *vma = get_gate_vma(mm);
  35. if (!vma)
  36. return 0;
  37. return (addr >= vma->vm_start) && (addr < vma->vm_end);
  38. }