This commit was generated by cvs2svn to compensate for changes in r10,
[reactos.git] / reactos / include / internal / mm.h
1 /*
2 * Higher level memory managment definitions
3 */
4
5 #ifndef __MM_H
6 #define __MM_H
7
8 #define PAGE_SYSTEM (0x80000000)
9
10 #include <internal/linkage.h>
11 #include <internal/kernel.h>
12 #include <windows.h>
13
14 typedef struct _memory_area
15 /*
16 * PURPOSE: Describes an area of virtual memory
17 */
18 {
19 /*
20 * Access protection
21 */
22 unsigned int access;
23
24 /*
25 * Memory region base
26 */
27 unsigned int base;
28
29 /*
30 * Memory region length
31 */
32 unsigned int length;
33
34 /*
35 * Memory type (Mapped file, mapped from an executable or private)
36 */
37 unsigned int type;
38
39 /*
40 * Memory region state (committed, reserved or free)
41 */
42 unsigned int state;
43
44 /*
45 * Original access protection
46 */
47 unsigned int initial_access;
48
49 /*
50 * Used to maintain the linked list of memory areas
51 */
52 struct _memory_area* previous;
53 struct _memory_area* next;
54
55 /*
56 * True the region is locked
57 */
58 BOOL lock;
59
60 /*
61 * FUNCTION: Decommits all the pages in the regions
62 */
63 void (*free)(struct _memory_area* marea);
64
65 /*
66 * FUNCTION: Handles a page fault by loading the required page
67 * RECEIVES:
68 * marea = the memory area
69 * address = the relative address of the page to load
70 * RETURNS:
71 * TRUE = the access should be restarted
72 * FALSE = the access was illegal and an exception should
73 * be generated
74 * NOTES: This function is guarrented to be called within the context
75 * of the thread which required a page to be loaded
76 */
77 BOOL (*load_page)(struct _memory_area* marea, unsigned int address);
78 } memory_area;
79
80
81 /*
82 * FUNCTION: Gets a page with a restricted max physical address (i.e.
83 * suitable for dma)
84 * RETURNS:
85 * The physical address of the page if it succeeds
86 * NULL if it fails.
87 * NOTES: This is very inefficent because the list isn't sorted. On the
88 * other hand sorting the list would be quite expensive especially if dma
89 * is only used infrequently. Perhaps a special cache of dma pages should
90 * be maintained?
91 */
92 unsigned int get_dma_page(unsigned int max_address);
93
94 /*
95 * FUNCTION: Allocate a page and return its physical address
96 * RETURNS: The physical address of the page allocated
97 */
98 asmlinkage unsigned int get_free_page(void);
99
100 /*
101 * FUNCTION: Adds pages to the free list
102 * ARGUMENTS:
103 * physical_base = Physical address of the base of the region to
104 * be freed
105 * nr = number of continuous pages to free
106 */
107 asmlinkage void free_page(unsigned int physical_base, unsigned int nr);
108
109 /*
110 * FUNCTION: Returns the physical address mapped by a given virtual address
111 * ARGUMENTS:
112 * vaddr = virtual address to query
113 * RETURNS: The physical address if present in memory
114 * Zero if paged out or invalid
115 * NOTE: This doesn't do any synchronization
116 */
117 unsigned int get_page_physical_address(unsigned int vaddr);
118
119 void mark_page_not_writable(unsigned int vaddr);
120
121 void VirtualInit(boot_param* bp);
122
123 /*
124 * FUNCTION: Returns the first memory area starting in the region or the last
125 * one before the start of the region
126 * ARGUMENTS:
127 * list_head = Head of the list of memory areas to search
128 * base = base address of the region
129 * length = length of the region
130 * RETURNS: A pointer to the area found or
131 * NULL if the region was before the first region on the list
132 */
133 memory_area* find_first_marea(memory_area* list_head, unsigned int base,
134 unsigned int length);
135
136 /*
137 * Head of the list of system memory areas
138 */
139 extern memory_area* system_memory_area_list_head;
140
141 /*
142 * Head of the list of user memory areas (this should be per process)
143 */
144 extern memory_area* memory_area_list_head;
145
146 #endif