ia64/xen-unstable

view xenolinux-2.4.16-sparse/arch/xeno/mm/get_unmapped_area.c @ 77:024aa2a06c1e

bitkeeper revision 1.7.3.52 (3e1019294uiW6rByAS_Bs30dgMr6AA)

debug
author lynx@idefix.cl.cam.ac.uk
date Mon Dec 30 10:00:09 2002 +0000 (2002-12-30)
parents ddd3b8b09fea
children 336647fd8f40
line source
2 #include <linux/slab.h>
3 #include <linux/shm.h>
4 #include <linux/mman.h>
5 #include <linux/pagemap.h>
6 #include <linux/swap.h>
7 #include <linux/swapctl.h>
8 #include <linux/smp_lock.h>
9 #include <linux/init.h>
10 #include <linux/file.h>
11 #include <linux/fs.h>
12 #include <linux/personality.h>
14 #include <asm/uaccess.h>
15 #include <asm/pgalloc.h>
17 /*
18 static int direct_mapped(unsigned long addr)
19 {
20 direct_mmap_node_t * node;
21 struct list_head * curr;
22 struct list_head * direct_list = &current->mm->context.direct_list;
24 curr = direct_list->next;
25 while(curr != direct_list){
26 node = list_entry(curr, direct_mmap_node_t, list);
27 if(node->addr == addr)
28 break;
29 curr = curr->next;
30 }
32 if(curr == direct_list)
33 return 0;
35 return 1;
36 }
37 */
38 /*
39 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
40 {
41 struct vm_area_struct *vma;
43 if (len > TASK_SIZE)
44 return -ENOMEM;
46 if (addr) {
47 addr = PAGE_ALIGN(addr);
48 vma = find_vma(current->mm, addr);
49 if (TASK_SIZE - len >= addr &&
50 (!vma || addr + len <= vma->vm_start))
51 return addr;
52 }
53 addr = PAGE_ALIGN(TASK_UNMAPPED_BASE);
55 for (vma = find_vma(current->mm, addr); ; vma = vma->vm_next) {
56 if (TASK_SIZE - len < addr)
57 return -ENOMEM;
59 if(current->pid > 100){
60 printk(KERN_ALERT "bd240 debug: gua: vm addr found %lx\n", addr);
61 printk(KERN_ALERT "bd240 debug: gua: first condition %d, %lx, %lx\n",vma, addr + len, vma->vm_start);
62 printk(KERN_ALERT "bd240 debug: gua: second condition %d\n", direct_mapped(addr));
63 }
64 if ((!vma || addr + len <= vma->vm_start) && !direct_mapped(addr))
65 return addr;
67 addr = vma->vm_end;
68 }
69 }
70 */
71 struct list_head *find_direct(struct list_head *list, unsigned long addr)
72 {
73 struct list_head * curr;
74 struct list_head * direct_list = &current->mm->context.direct_list;
75 direct_mmap_node_t * node;
77 for ( curr = direct_list->next; curr != direct_list; curr = curr->next )
78 {
79 node = list_entry(curr, direct_mmap_node_t, list);
80 if( node->vm_start >= addr ){
81 printk(KERN_ALERT "bd240 debug: find_direct: hit %lx\n", node->vm_start);
82 break;
83 }
84 }
86 return curr;
87 }
89 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long
90 addr, unsigned long len, unsigned long pgoff, unsigned long flags)
91 {
92 struct vm_area_struct *vma;
93 direct_mmap_node_t * node;
94 struct list_head * curr;
95 struct list_head * direct_list = &current->mm->context.direct_list;
97 if (len > TASK_SIZE)
98 return -ENOMEM;
100 if ( addr )
101 {
102 addr = PAGE_ALIGN(addr);
103 vma = find_vma(current->mm, addr);
104 curr = find_direct(direct_list, addr);
105 node = list_entry(curr, direct_mmap_node_t, list);
106 if ( (TASK_SIZE - len >= addr) &&
107 (!vma || addr + len <= vma->vm_start) &&
108 ((curr == direct_list) || addr + len <= node->vm_start) )
109 return addr;
110 }
112 addr = PAGE_ALIGN(TASK_UNMAPPED_BASE);
115 /* Find first VMA and direct_map nodes with vm_start > addr */
116 vma = find_vma(current->mm, addr);
117 curr = find_direct(direct_list, addr);
118 node = list_entry(curr, direct_mmap_node_t, list);
120 for ( ; ; )
121 {
122 if ( TASK_SIZE - len < addr ) return -ENOMEM;
124 if ( vma && ((curr == direct_list) || (vma->vm_start < node->vm_start)))
125 {
126 /* Do we fit before VMA node? */
127 if ( addr + len <= vma->vm_start ) return addr;
128 addr = vma->vm_end;
129 vma = vma->vm_next;
130 }
131 else if ( curr != direct_list )
132 {
133 /* Do we fit before direct_map node? */
134 if ( addr + len <= node->vm_start) return addr;
135 addr = node->vm_end;
136 curr = curr->next;
137 node = list_entry(curr, direct_mmap_node_t, list);
138 }
139 else
140 {
141 /* !vma && curr == direct_list */
142 return addr;
143 }
144 }
145 }