122 } |
122 } |
123 |
123 |
124 |
124 |
125 TInt M::MovePage(TPhysAddr aOld, TPhysAddr& aNew, TUint aBlockZoneId, TBool aBlockRest) |
125 TInt M::MovePage(TPhysAddr aOld, TPhysAddr& aNew, TUint aBlockZoneId, TBool aBlockRest) |
126 { |
126 { |
127 TInt r; |
127 // Returns this when page is not paged or managed or free but is a real RAM page. |
|
128 TInt r = KErrNotSupported; |
128 |
129 |
129 // get memory object corresponding to the page... |
130 // get memory object corresponding to the page... |
130 DMemoryObject* memory = 0; |
131 DMemoryObject* memory = 0; |
131 MmuLock::Lock(); |
132 MmuLock::Lock(); |
132 SPageInfo* pi = SPageInfo::SafeFromPhysAddr(aOld&~KPageMask); |
133 SPageInfo* pi = SPageInfo::SafeFromPhysAddr(aOld&~KPageMask); |
134 { |
135 { |
135 if (pi->PagedState() != SPageInfo::EUnpaged) |
136 if (pi->PagedState() != SPageInfo::EUnpaged) |
136 {// The page is paged so let the pager handle it. |
137 {// The page is paged so let the pager handle it. |
137 return ThePager.DiscardPage(pi, aBlockZoneId, aBlockRest); |
138 return ThePager.DiscardPage(pi, aBlockZoneId, aBlockRest); |
138 } |
139 } |
139 if (pi->Type()==SPageInfo::EManaged) |
140 switch (pi->Type()) |
140 memory = pi->Owner(); |
141 { |
141 } |
142 case SPageInfo::EManaged: |
142 MmuLock::Unlock(); |
143 memory = pi->Owner(); |
143 |
144 // Note, whilst we hold the RamAllocLock the page can't change it's use |
144 // Note, whilst we hold the RamAllocLock the page can't change it's use |
145 // and we can safely assume that it still belongs to the memory object |
145 // and we can safely assume that it still belongs to the memory object |
146 // at a fixed page index. |
146 // at a fixed page index. |
147 // Also, as memory objects can't be destroyed whilst they still own pages |
147 // Also, as memory objects can't be destroyed whilst they still own pages |
148 // we can safely access this object without taking an explicit reference, |
148 // we can safely access this object without taking an explicit referernce, |
149 // i.e. we don't need to Open() the memory object. |
149 // i.e. we don't need to Open() the memory object. |
150 MmuLock::Unlock(); |
150 if (!pi) |
151 // move page... |
|
152 r = memory->iManager->MovePage(memory, pi, aNew, aBlockZoneId, aBlockRest); |
|
153 break; |
|
154 case SPageInfo::EUnused: |
|
155 r = KErrNotFound; // This page is free so nothing to do. |
|
156 // Fall through.. |
|
157 default: |
|
158 MmuLock::Unlock(); |
|
159 } |
|
160 } |
|
161 else |
151 {// page info for aOld not found so aOld is not a RAM page... |
162 {// page info for aOld not found so aOld is not a RAM page... |
|
163 MmuLock::Unlock(); |
152 r = KErrArgument; |
164 r = KErrArgument; |
153 } |
|
154 else if(!memory) |
|
155 { |
|
156 // page does not have a memory manager, so we can't move it... |
|
157 r = KErrNotSupported; |
|
158 } |
|
159 else |
|
160 { |
|
161 // move page... |
|
162 r = memory->iManager->MovePage(memory, pi, aNew, aBlockZoneId, aBlockRest); |
|
163 } |
165 } |
164 return r; |
166 return r; |
165 } |
167 } |
|
168 |
|
169 |
|
170 TInt M::MoveAndAllocPage(TPhysAddr aAddr, TZonePageType aPageType) |
|
171 { |
|
172 // Returns this when page is not paged or managed or free but is a real RAM page. |
|
173 TInt r = KErrNotSupported; |
|
174 |
|
175 // get memory object corresponding to the page... |
|
176 DMemoryObject* memory = 0; |
|
177 MmuLock::Lock(); |
|
178 SPageInfo* pi = SPageInfo::SafeFromPhysAddr(aAddr & ~KPageMask); |
|
179 if(pi) |
|
180 { |
|
181 if (pi->PagedState() != SPageInfo::EUnpaged) |
|
182 {// The page is paged so let the pager handle it. |
|
183 return ThePager.DiscardAndAllocPage(pi, aPageType); |
|
184 } |
|
185 switch (pi->Type()) |
|
186 { |
|
187 case SPageInfo::EManaged: |
|
188 memory = pi->Owner(); |
|
189 // Note, whilst we hold the RamAllocLock the page can't change it's use |
|
190 // and we can safely assume that it still belongs to the memory object |
|
191 // at a fixed page index. |
|
192 // Also, as memory objects can't be destroyed whilst they still own pages |
|
193 // we can safely access this object without taking an explicit referernce, |
|
194 // i.e. we don't need to Open() the memory object. |
|
195 MmuLock::Unlock(); |
|
196 // move page... |
|
197 r = memory->iManager->MoveAndAllocPage(memory, pi, aPageType); |
|
198 break; |
|
199 case SPageInfo::EUnused: |
|
200 r = KErrNone; // This page is free so nothing to do. |
|
201 // Fall through.. |
|
202 default: |
|
203 MmuLock::Unlock(); |
|
204 } |
|
205 } |
|
206 else |
|
207 {// page info for aAddr not found so aAddr is not a RAM page... |
|
208 MmuLock::Unlock(); |
|
209 r = KErrArgument; |
|
210 } |
|
211 return r; |
|
212 } |