《操作系统》的实验代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.8 KiB

12 years ago
12 years ago
12 years ago
  1. #ifndef __KERN_MM_VMM_H__
  2. #define __KERN_MM_VMM_H__
  3. #include <defs.h>
  4. #include <list.h>
  5. #include <memlayout.h>
  6. #include <sync.h>
  7. //pre define
  8. struct mm_struct;
  9. // the virtual continuous memory area(vma), [vm_start, vm_end),
  10. // addr belong to a vma means vma.vm_start<= addr <vma.vm_end
  11. struct vma_struct {
  12. struct mm_struct *vm_mm; // the set of vma using the same PDT
  13. uintptr_t vm_start; // start addr of vma
  14. uintptr_t vm_end; // end addr of vma, not include the vm_end itself
  15. uint32_t vm_flags; // flags of vma
  16. list_entry_t list_link; // linear list link which sorted by start addr of vma
  17. };
  18. #define le2vma(le, member) \
  19. to_struct((le), struct vma_struct, member)
  20. #define VM_READ 0x00000001
  21. #define VM_WRITE 0x00000002
  22. #define VM_EXEC 0x00000004
  23. // the control struct for a set of vma using the same PDT
  24. struct mm_struct {
  25. list_entry_t mmap_list; // linear list link which sorted by start addr of vma
  26. struct vma_struct *mmap_cache; // current accessed vma, used for speed purpose
  27. pde_t *pgdir; // the PDT of these vma
  28. int map_count; // the count of these vma
  29. void *sm_priv; // the private data for swap manager
  30. };
  31. struct vma_struct *find_vma(struct mm_struct *mm, uintptr_t addr);
  32. struct vma_struct *vma_create(uintptr_t vm_start, uintptr_t vm_end, uint32_t vm_flags);
  33. void insert_vma_struct(struct mm_struct *mm, struct vma_struct *vma);
  34. struct mm_struct *mm_create(void);
  35. void mm_destroy(struct mm_struct *mm);
  36. void vmm_init(void);
  37. int do_pgfault(struct mm_struct *mm, uint32_t error_code, uintptr_t addr);
  38. extern volatile unsigned int pgfault_num;
  39. extern struct mm_struct *check_mm_struct;
  40. #endif /* !__KERN_MM_VMM_H__ */