This source file includes following definitions.
- get_free_page
- expand_stack
- find_vma
- find_vma_intersection
1 #ifndef _LINUX_MM_H
2 #define _LINUX_MM_H
3
4 #include <linux/sched.h>
5 #include <linux/errno.h>
6 #include <linux/kernel.h>
7 #include <linux/string.h>
8
9 extern unsigned long high_memory;
10
11 #include <asm/page.h>
12
13 #ifdef __KERNEL__
14
15 #define VERIFY_READ 0
16 #define VERIFY_WRITE 1
17
18 extern int verify_area(int, const void *, unsigned long);
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 struct vm_area_struct {
36 struct mm_struct * vm_mm;
37 unsigned long vm_start;
38 unsigned long vm_end;
39 pgprot_t vm_page_prot;
40 unsigned short vm_flags;
41
42 short vm_avl_height;
43 struct vm_area_struct * vm_avl_left;
44 struct vm_area_struct * vm_avl_right;
45
46 struct vm_area_struct * vm_next;
47
48
49
50 struct vm_area_struct * vm_next_share;
51 struct vm_area_struct * vm_prev_share;
52
53 struct vm_operations_struct * vm_ops;
54 unsigned long vm_offset;
55 struct inode * vm_inode;
56 unsigned long vm_pte;
57 };
58
59
60
61
62 #define VM_READ 0x0001
63 #define VM_WRITE 0x0002
64 #define VM_EXEC 0x0004
65 #define VM_SHARED 0x0008
66
67 #define VM_MAYREAD 0x0010
68 #define VM_MAYWRITE 0x0020
69 #define VM_MAYEXEC 0x0040
70 #define VM_MAYSHARE 0x0080
71
72 #define VM_GROWSDOWN 0x0100
73 #define VM_GROWSUP 0x0200
74 #define VM_SHM 0x0400
75 #define VM_DENYWRITE 0x0800
76
77 #define VM_EXECUTABLE 0x1000
78 #define VM_LOCKED 0x2000
79
80 #define VM_STACK_FLAGS 0x0177
81
82
83
84
85
86 extern pgprot_t protection_map[16];
87
88
89
90
91
92
93
94 struct vm_operations_struct {
95 void (*open)(struct vm_area_struct * area);
96 void (*close)(struct vm_area_struct * area);
97 void (*unmap)(struct vm_area_struct *area, unsigned long, size_t);
98 void (*protect)(struct vm_area_struct *area, unsigned long, size_t, unsigned int newprot);
99 int (*sync)(struct vm_area_struct *area, unsigned long, size_t, unsigned int flags);
100 void (*advise)(struct vm_area_struct *area, unsigned long, size_t, unsigned int advise);
101 unsigned long (*nopage)(struct vm_area_struct * area, unsigned long address, int write_access);
102 unsigned long (*wppage)(struct vm_area_struct * area, unsigned long address,
103 unsigned long page);
104 int (*swapout)(struct vm_area_struct *, unsigned long, pte_t *);
105 pte_t (*swapin)(struct vm_area_struct *, unsigned long, unsigned long);
106 };
107
108
109
110
111
112
113
114
115
116
117 typedef struct page {
118 unsigned int count;
119 unsigned dirty:16,
120 age:8,
121 uptodate:1,
122 error:1,
123 referenced:1,
124 locked:1,
125 free_after:1,
126 unused:2,
127 reserved:1;
128 struct wait_queue *wait;
129 struct page *next;
130
131 struct page *next_hash;
132 unsigned long offset;
133 struct inode *inode;
134 struct page *write_list;
135
136 struct page *prev;
137 struct page *prev_hash;
138 } mem_map_t;
139
140 extern mem_map_t * mem_map;
141
142
143
144
145
146 #define NR_MEM_LISTS 6
147
148 struct mem_list {
149 struct mem_list * next;
150 struct mem_list * prev;
151 };
152
153 extern struct mem_list free_area_list[NR_MEM_LISTS];
154 extern unsigned int * free_area_map[NR_MEM_LISTS];
155
156
157
158
159
160
161 #define __get_free_page(priority) __get_free_pages((priority),0,~0UL)
162 #define __get_dma_pages(priority, order) __get_free_pages((priority),(order),MAX_DMA_ADDRESS)
163 extern unsigned long __get_free_pages(int priority, unsigned long gfporder, unsigned long max_addr);
164
165 extern inline unsigned long get_free_page(int priority)
166 {
167 unsigned long page;
168
169 page = __get_free_page(priority);
170 if (page)
171 memset((void *) page, 0, PAGE_SIZE);
172 return page;
173 }
174
175
176
177 #define free_page(addr) free_pages((addr),0)
178 extern void free_pages(unsigned long addr, unsigned long order);
179
180 extern void show_free_areas(void);
181 extern unsigned long put_dirty_page(struct task_struct * tsk,unsigned long page,
182 unsigned long address);
183
184 extern void free_page_tables(struct task_struct * tsk);
185 extern void clear_page_tables(struct task_struct * tsk);
186 extern int new_page_tables(struct task_struct * tsk);
187 extern int copy_page_tables(struct task_struct * to);
188
189 extern int zap_page_range(struct mm_struct *mm, unsigned long address, unsigned long size);
190 extern int copy_page_range(struct mm_struct *dst, struct mm_struct *src, struct vm_area_struct *vma);
191 extern int remap_page_range(unsigned long from, unsigned long to, unsigned long size, pgprot_t prot);
192 extern int zeromap_page_range(unsigned long from, unsigned long size, pgprot_t prot);
193
194 extern void vmtruncate(struct inode * inode, unsigned long offset);
195 extern void handle_mm_fault(struct vm_area_struct *vma, unsigned long address, int write_access);
196 extern void do_wp_page(struct task_struct * tsk, struct vm_area_struct * vma, unsigned long address, int write_access);
197 extern void do_no_page(struct task_struct * tsk, struct vm_area_struct * vma, unsigned long address, int write_access);
198
199 extern unsigned long paging_init(unsigned long start_mem, unsigned long end_mem);
200 extern void mem_init(unsigned long start_mem, unsigned long end_mem);
201 extern void show_mem(void);
202 extern void oom(struct task_struct * tsk);
203 extern void si_meminfo(struct sysinfo * val);
204
205
206
207 extern void * vmalloc(unsigned long size);
208 extern void * vremap(unsigned long offset, unsigned long size);
209 extern void vfree(void * addr);
210 extern int vread(char *buf, char *addr, int count);
211
212
213 extern unsigned long do_mmap(struct file * file, unsigned long addr, unsigned long len,
214 unsigned long prot, unsigned long flags, unsigned long off);
215 extern void merge_segments(struct task_struct *, unsigned long, unsigned long);
216 extern void insert_vm_struct(struct task_struct *, struct vm_area_struct *);
217 extern void remove_shared_vm_struct(struct vm_area_struct *);
218 extern void build_mmap_avl(struct mm_struct *);
219 extern void exit_mmap(struct mm_struct *);
220 extern int do_munmap(unsigned long, size_t);
221 extern unsigned long get_unmapped_area(unsigned long, unsigned long);
222
223
224 extern unsigned long page_unuse(unsigned long);
225 extern int shrink_mmap(int, unsigned long);
226 extern void truncate_inode_pages(struct inode *, unsigned long);
227
228 #define GFP_BUFFER 0x00
229 #define GFP_ATOMIC 0x01
230 #define GFP_USER 0x02
231 #define GFP_KERNEL 0x03
232 #define GFP_NOBUFFER 0x04
233 #define GFP_NFS 0x05
234
235
236
237
238 #define GFP_DMA 0x80
239
240 #define GFP_LEVEL_MASK 0xf
241
242
243
244 static inline int expand_stack(struct vm_area_struct * vma, unsigned long address)
245 {
246 unsigned long grow;
247
248 address &= PAGE_MASK;
249 if (vma->vm_end - address > current->rlim[RLIMIT_STACK].rlim_cur)
250 return -ENOMEM;
251 grow = vma->vm_start - address;
252 vma->vm_start = address;
253 vma->vm_offset -= grow;
254 vma->vm_mm->total_vm += grow >> PAGE_SHIFT;
255 if (vma->vm_flags & VM_LOCKED)
256 vma->vm_mm->locked_vm += grow >> PAGE_SHIFT;
257 return 0;
258 }
259
260 #define avl_empty (struct vm_area_struct *) NULL
261
262
263 static inline struct vm_area_struct * find_vma (struct task_struct * task, unsigned long addr)
264 {
265 struct vm_area_struct * result = NULL;
266 struct vm_area_struct * tree;
267
268 if (!task->mm)
269 return NULL;
270 for (tree = task->mm->mmap_avl ; ; ) {
271 if (tree == avl_empty)
272 return result;
273 if (tree->vm_end > addr) {
274 if (tree->vm_start <= addr)
275 return tree;
276 result = tree;
277 tree = tree->vm_avl_left;
278 } else
279 tree = tree->vm_avl_right;
280 }
281 }
282
283
284
285 static inline struct vm_area_struct * find_vma_intersection (struct task_struct * task, unsigned long start_addr, unsigned long end_addr)
286 {
287 struct vm_area_struct * vma;
288
289 vma = find_vma(task,start_addr);
290 if (!vma || end_addr <= vma->vm_start)
291 return NULL;
292 return vma;
293 }
294
295 #endif
296
297 #endif