Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\memmodel\epoc\direct\mprocess.cpp
19 #include <kernel/cache.h>
21 #define iMState iWaitLink.iSpare1
23 _LIT(KDollarDat,"$DAT");
25 /********************************************
27 ********************************************/
28 void DMemModelProcess::Destruct()
33 TInt DMemModelProcess::NewChunk(DChunk*& aChunk, SChunkCreateInfo& aInfo, TLinAddr& aRunAddr)
36 DMemModelChunk* pC=new DMemModelChunk;
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))
46 if (aInfo.iRunAddress!=0)
47 pC->SetFixedAddress(aInfo.iRunAddress,aInfo.iPreallocated);
48 if (aInfo.iPreallocated==0)
50 if (pC->iAttributes & DChunk::EDisconnected)
52 r=pC->Commit(aInfo.iInitialBottom,aInfo.iInitialTop-aInfo.iInitialBottom);
54 else if (pC->iAttributes & DChunk::EDoubleEnded)
56 r=pC->AdjustDoubleEnded(aInfo.iInitialBottom,aInfo.iInitialTop);
60 r=pC->Adjust(aInfo.iInitialTop);
65 aRunAddr=(TLinAddr)pC->Base();
70 pC->iDestroyedDfc = aInfo.iDestroyedDfc;
74 pC->Close(NULL); // NULL since chunk can't have been added to process
78 TInt DMemModelProcess::DoCreate(TBool aKernelProcess, TProcessCreateInfo&)
80 __KTRACE_OPT(KPROC,Kern::Printf("DMemModelProcess::DoCreate %O",this))
82 iAttributes=ESupervisor|EPrivate;
88 TInt DMemModelProcess::CreateDataBssStackArea(TProcessCreateInfo& aInfo)
90 __KTRACE_OPT(KPROC,Kern::Printf("DMemModelProcess::CreateDataBssStackArea %O",this));
91 TInt dataBssSize=MM::RoundToBlockSize(aInfo.iTotalDataSize);
93 DMemModelCodeSeg* cs=(DMemModelCodeSeg*)iTempCodeSeg;
94 if (!cs->iXIP && dataBssSize)
96 // only RAM loaded processes need data chunks
97 // ROM processes have their .data/.bss areas reserved by ROMBUILD
98 SChunkCreateInfo cinfo;
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);
111 r=NewChunk((DChunk*&)iDataBssStackChunk, cinfo, iDataBssRunAddress);
112 __KTRACE_OPT(KPROC,Kern::Printf("RAM process, ret=%d, data at %08x+%x",r,iDataBssRunAddress,dataBssSize));
116 iDataBssRunAddress=cs->RomInfo().iDataBssLinearBase;
117 __KTRACE_OPT(KPROC,Kern::Printf("ROM process, data at %08x+%x",iDataBssRunAddress,dataBssSize));
122 TInt DMemModelProcess::AddChunk(DChunk* aChunk,TBool isReadOnly)
127 void DMemModelProcess::FinalRelease()
131 void DMemModelProcess::RemoveDllData()
133 // Call with CodeSegLock held
138 TInt DMemModelProcess::MapCodeSeg(DCodeSeg*)
143 void DMemModelProcess::UnmapCodeSeg(DCodeSeg*)
147 TInt DMemModelProcess::NewShPool(DShPool*& /* aPool */, TShPoolCreateInfo& /* aInfo */)
149 return KErrNotSupported;
152 TInt DThread::RawRead(const TAny* aSrc, TAny* aDest, TInt aLength, TInt aFlags, TIpcExcTrap* /*aExcTrap*/)
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
160 const TUint8* pS=(const TUint8*)aSrc;
161 TUint8* pD=(TUint8*)aDest;
169 __KTRACE_OPT(KTHREAD2,Kern::Printf("DThread::Read %08x",pS));
171 TInt l=Min(aLength,K::MaxMemCopyInOneGo);
177 check=NKern::FlashSystem();
182 TInt DThread::RawWrite(const TAny* aDest, const TAny* aSrc, TInt aLength, TInt aFlags, DThread* anOriginatingThread, TIpcExcTrap* /*aExcTrap*/)
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
191 TUint8* pD=(TUint8*)aDest;
192 const TUint8* pS=(const TUint8*)aSrc;
200 __KTRACE_OPT(KTHREAD2,Kern::Printf("DThread::Write %08x",pD));
202 TInt l=Min(aLength,K::MaxMemCopyInOneGo);
208 check=NKern::FlashSystem();
213 #ifdef __DEBUGGER_SUPPORT__
214 TInt CodeModifier::SafeWriteCode(DProcess* /*aProcess*/, TLinAddr /*aAddress*/, TInt /*aSize*/, TUint /*aValue*/, void* /*aOldValue*/)
216 return KErrNotSupported;
218 TInt CodeModifier::WriteCode(TLinAddr /*aAddress*/, TInt /*aSize*/, TUint /*aValue*/, void* /*aOldValue*/)
220 return KErrNotSupported;
222 #endif //__DEBUGGER_SUPPORT__
224 TInt DThread::ReadAndParseDesHeader(const TAny* aSrc, TDesHeader& aDest)
226 // Read and parse the header of a remote descriptor.
227 // Enter and leave with system locked.
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];
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);
246 DChunk* DThread::OpenSharedChunk(const TAny* aAddress, TBool /*aWrite*/, TInt& aOffset)
248 DMemModelChunk* chunk=0;
249 DObjectCon& chunks=*K::Containers[EChunk];
251 chunks.Lock()->Wait();
252 TInt count=chunks.Count();
257 DMemModelChunk* pC=(DMemModelChunk*)chunks[i];
258 offset = (TUint)aAddress-(TUint)pC->Base();
259 if(offset<TUint(pC->iMaxSize))
265 chunks.Lock()->Signal();
270 if((chunk->iChunkType!=ESharedKernelSingle && chunk->iChunkType!=ESharedKernelMultiple))
272 if(chunk->Open()!=KErrNone)
278 TInt DThread::PrepareMemoryForDMA(const TAny* aLinAddr, TInt aSize, TPhysAddr* aPhysicalPageList)
280 return KErrNotSupported;
283 TInt DThread::ReleaseMemoryFromDMA(const TAny* aLinAddr, TInt aSize, TPhysAddr* aPhysicalPageList)
285 return KErrNotSupported;