|
1 // Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // e32\memmodel\epoc\direct\mprocess.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include <memmodel.h> |
|
19 #include <kernel/cache.h> |
|
20 |
|
21 #define iMState iWaitLink.iSpare1 |
|
22 |
|
23 _LIT(KDollarDat,"$DAT"); |
|
24 |
|
25 /******************************************** |
|
26 * Process |
|
27 ********************************************/ |
|
28 void DMemModelProcess::Destruct() |
|
29 { |
|
30 DProcess::Destruct(); |
|
31 } |
|
32 |
|
33 TInt DMemModelProcess::NewChunk(DChunk*& aChunk, SChunkCreateInfo& aInfo, TLinAddr& aRunAddr) |
|
34 { |
|
35 aChunk=NULL; |
|
36 DMemModelChunk* pC=new DMemModelChunk; |
|
37 if (!pC) |
|
38 return KErrNoMemory; |
|
39 pC->iChunkType=aInfo.iType; |
|
40 if (!aInfo.iGlobal && (iAttributes & DMemModelProcess::EPrivate)!=0) |
|
41 pC->iAttributes |= DMemModelChunk::EPrivate; |
|
42 pC->iOwningProcess=(aInfo.iGlobal)?NULL:this; |
|
43 TInt r=pC->Create(aInfo); |
|
44 if (r==KErrNone && (aInfo.iOperations & SChunkCreateInfo::EAdjust)) |
|
45 { |
|
46 if (aInfo.iRunAddress!=0) |
|
47 pC->SetFixedAddress(aInfo.iRunAddress,aInfo.iPreallocated); |
|
48 if (aInfo.iPreallocated==0) |
|
49 { |
|
50 if (pC->iAttributes & DChunk::EDisconnected) |
|
51 { |
|
52 r=pC->Commit(aInfo.iInitialBottom,aInfo.iInitialTop-aInfo.iInitialBottom); |
|
53 } |
|
54 else if (pC->iAttributes & DChunk::EDoubleEnded) |
|
55 { |
|
56 r=pC->AdjustDoubleEnded(aInfo.iInitialBottom,aInfo.iInitialTop); |
|
57 } |
|
58 else |
|
59 { |
|
60 r=pC->Adjust(aInfo.iInitialTop); |
|
61 } |
|
62 } |
|
63 if (r==KErrNone) |
|
64 { |
|
65 aRunAddr=(TLinAddr)pC->Base(); |
|
66 } |
|
67 } |
|
68 if (r==KErrNone) |
|
69 { |
|
70 pC->iDestroyedDfc = aInfo.iDestroyedDfc; |
|
71 aChunk=(DChunk*)pC; |
|
72 } |
|
73 else |
|
74 pC->Close(NULL); // NULL since chunk can't have been added to process |
|
75 return r; |
|
76 } |
|
77 |
|
78 TInt DMemModelProcess::DoCreate(TBool aKernelProcess, TProcessCreateInfo&) |
|
79 { |
|
80 __KTRACE_OPT(KPROC,Kern::Printf("DMemModelProcess::DoCreate %O",this)) |
|
81 if (aKernelProcess) |
|
82 iAttributes=ESupervisor|EPrivate; |
|
83 else |
|
84 iAttributes=0; |
|
85 return KErrNone; |
|
86 } |
|
87 |
|
88 TInt DMemModelProcess::CreateDataBssStackArea(TProcessCreateInfo& aInfo) |
|
89 { |
|
90 __KTRACE_OPT(KPROC,Kern::Printf("DMemModelProcess::CreateDataBssStackArea %O",this)); |
|
91 TInt dataBssSize=MM::RoundToBlockSize(aInfo.iTotalDataSize); |
|
92 TInt r=KErrNone; |
|
93 DMemModelCodeSeg* cs=(DMemModelCodeSeg*)iTempCodeSeg; |
|
94 if (!cs->iXIP && dataBssSize) |
|
95 { |
|
96 // only RAM loaded processes need data chunks |
|
97 // ROM processes have their .data/.bss areas reserved by ROMBUILD |
|
98 SChunkCreateInfo cinfo; |
|
99 cinfo.iGlobal=EFalse; |
|
100 cinfo.iAtt=TChunkCreate::ENormal; |
|
101 cinfo.iForceFixed=EFalse; |
|
102 cinfo.iOperations=SChunkCreateInfo::EAdjust|SChunkCreateInfo::EAdd; |
|
103 cinfo.iType=EUserData; |
|
104 cinfo.iMaxSize=dataBssSize; |
|
105 cinfo.iInitialBottom=0; |
|
106 cinfo.iInitialTop=dataBssSize; |
|
107 cinfo.iPreallocated=0; |
|
108 cinfo.iName.Set(KDollarDat); |
|
109 cinfo.iOwner=this; |
|
110 cinfo.iRunAddress=0; |
|
111 r=NewChunk((DChunk*&)iDataBssStackChunk, cinfo, iDataBssRunAddress); |
|
112 __KTRACE_OPT(KPROC,Kern::Printf("RAM process, ret=%d, data at %08x+%x",r,iDataBssRunAddress,dataBssSize)); |
|
113 } |
|
114 else if (cs->iXIP) |
|
115 { |
|
116 iDataBssRunAddress=cs->RomInfo().iDataBssLinearBase; |
|
117 __KTRACE_OPT(KPROC,Kern::Printf("ROM process, data at %08x+%x",iDataBssRunAddress,dataBssSize)); |
|
118 } |
|
119 return r; |
|
120 } |
|
121 |
|
122 TInt DMemModelProcess::AddChunk(DChunk* aChunk,TBool isReadOnly) |
|
123 { |
|
124 return KErrNone; |
|
125 } |
|
126 |
|
127 void DMemModelProcess::FinalRelease() |
|
128 { |
|
129 } |
|
130 |
|
131 void DMemModelProcess::RemoveDllData() |
|
132 // |
|
133 // Call with CodeSegLock held |
|
134 // |
|
135 { |
|
136 } |
|
137 |
|
138 TInt DMemModelProcess::MapCodeSeg(DCodeSeg*) |
|
139 { |
|
140 return KErrNone; |
|
141 } |
|
142 |
|
143 void DMemModelProcess::UnmapCodeSeg(DCodeSeg*) |
|
144 { |
|
145 } |
|
146 |
|
147 TInt DMemModelProcess::NewShPool(DShPool*& /* aPool */, TShPoolCreateInfo& /* aInfo */) |
|
148 { |
|
149 return KErrNotSupported; |
|
150 } |
|
151 |
|
152 TInt DThread::RawRead(const TAny* aSrc, TAny* aDest, TInt aLength, TInt aFlags, TIpcExcTrap* /*aExcTrap*/) |
|
153 // |
|
154 // Read from the thread's process. |
|
155 // aSrc is run address of memory to read |
|
156 // aDest is current address of destination |
|
157 // Enter and leave with system locked |
|
158 // |
|
159 { |
|
160 const TUint8* pS=(const TUint8*)aSrc; |
|
161 TUint8* pD=(TUint8*)aDest; |
|
162 TBool check=ETrue; |
|
163 while (aLength) |
|
164 { |
|
165 if (check) |
|
166 { |
|
167 if (iMState==EDead) |
|
168 return KErrDied; |
|
169 __KTRACE_OPT(KTHREAD2,Kern::Printf("DThread::Read %08x",pS)); |
|
170 } |
|
171 TInt l=Min(aLength,K::MaxMemCopyInOneGo); |
|
172 memcpy(pD,pS,l); |
|
173 pD+=l; |
|
174 pS+=l; |
|
175 aLength-=l; |
|
176 if (aLength) |
|
177 check=NKern::FlashSystem(); |
|
178 } |
|
179 return KErrNone; |
|
180 } |
|
181 |
|
182 TInt DThread::RawWrite(const TAny* aDest, const TAny* aSrc, TInt aLength, TInt aFlags, DThread* anOriginatingThread, TIpcExcTrap* /*aExcTrap*/) |
|
183 // |
|
184 // Write to the thread's process. |
|
185 // aDest is run address of memory to write |
|
186 // aSrc is current address of destination |
|
187 // anOriginatingThread is the thread on behalf of which this operation is performed (eg client of device driver). |
|
188 // Enter and leave with system locked |
|
189 // |
|
190 { |
|
191 TUint8* pD=(TUint8*)aDest; |
|
192 const TUint8* pS=(const TUint8*)aSrc; |
|
193 TBool check=ETrue; |
|
194 while (aLength) |
|
195 { |
|
196 if (check) |
|
197 { |
|
198 if (iMState==EDead) |
|
199 return KErrDied; |
|
200 __KTRACE_OPT(KTHREAD2,Kern::Printf("DThread::Write %08x",pD)); |
|
201 } |
|
202 TInt l=Min(aLength,K::MaxMemCopyInOneGo); |
|
203 memcpy(pD,pS,l); |
|
204 pD+=l; |
|
205 pS+=l; |
|
206 aLength-=l; |
|
207 if (aLength) |
|
208 check=NKern::FlashSystem(); |
|
209 } |
|
210 return KErrNone; |
|
211 } |
|
212 |
|
213 #ifdef __DEBUGGER_SUPPORT__ |
|
214 TInt CodeModifier::SafeWriteCode(DProcess* /*aProcess*/, TLinAddr /*aAddress*/, TInt /*aSize*/, TUint /*aValue*/, void* /*aOldValue*/) |
|
215 { |
|
216 return KErrNotSupported; |
|
217 } |
|
218 TInt CodeModifier::WriteCode(TLinAddr /*aAddress*/, TInt /*aSize*/, TUint /*aValue*/, void* /*aOldValue*/) |
|
219 { |
|
220 return KErrNotSupported; |
|
221 } |
|
222 #endif //__DEBUGGER_SUPPORT__ |
|
223 |
|
224 TInt DThread::ReadAndParseDesHeader(const TAny* aSrc, TDesHeader& aDest) |
|
225 // |
|
226 // Read and parse the header of a remote descriptor. |
|
227 // Enter and leave with system locked. |
|
228 // |
|
229 { |
|
230 TRawDesHeader& header = (TRawDesHeader&)aDest; |
|
231 static const TUint8 LengthLookup[16]={4,8,12,8,12,0,0,0,0,0,0,0,0,0,0,0}; |
|
232 const TUint32* pS=(const TUint32*)aSrc; |
|
233 if (!pS || (TInt(pS)&3)!=0) |
|
234 return KErrBadDescriptor; |
|
235 if (Kern::SafeRead(pS,&header,sizeof(TUint32))) |
|
236 return KErrBadDescriptor; |
|
237 TInt type=header[0]>>KShiftDesType8; |
|
238 TInt l=LengthLookup[type]; |
|
239 if (l==0) |
|
240 return KErrBadDescriptor; |
|
241 if (l>(TInt)sizeof(TUint32) && Kern::SafeRead(pS+1,&header[1],l-sizeof(TUint32))) |
|
242 return KErrBadDescriptor; |
|
243 return K::ParseDesHeader(aSrc, header, aDest); |
|
244 } |
|
245 |
|
246 DChunk* DThread::OpenSharedChunk(const TAny* aAddress, TBool /*aWrite*/, TInt& aOffset) |
|
247 { |
|
248 DMemModelChunk* chunk=0; |
|
249 DObjectCon& chunks=*K::Containers[EChunk]; |
|
250 NKern::LockSystem(); |
|
251 chunks.Lock()->Wait(); |
|
252 TInt count=chunks.Count(); |
|
253 TInt i; |
|
254 TUint offset=0; |
|
255 for(i=0;i<count;i++) |
|
256 { |
|
257 DMemModelChunk* pC=(DMemModelChunk*)chunks[i]; |
|
258 offset = (TUint)aAddress-(TUint)pC->Base(); |
|
259 if(offset<TUint(pC->iMaxSize)) |
|
260 { |
|
261 chunk = pC; |
|
262 break; |
|
263 } |
|
264 } |
|
265 chunks.Lock()->Signal(); |
|
266 |
|
267 if(!chunk) |
|
268 return 0; |
|
269 |
|
270 if((chunk->iChunkType!=ESharedKernelSingle && chunk->iChunkType!=ESharedKernelMultiple)) |
|
271 return 0; |
|
272 if(chunk->Open()!=KErrNone) |
|
273 return 0; |
|
274 aOffset = offset; |
|
275 return chunk; |
|
276 } |
|
277 |
|
278 TInt DThread::PrepareMemoryForDMA(const TAny* aLinAddr, TInt aSize, TPhysAddr* aPhysicalPageList) |
|
279 { |
|
280 return KErrNotSupported; |
|
281 } |
|
282 |
|
283 TInt DThread::ReleaseMemoryFromDMA(const TAny* aLinAddr, TInt aSize, TPhysAddr* aPhysicalPageList) |
|
284 { |
|
285 return KErrNotSupported; |
|
286 } |
|
287 |