sl@0
|
1 |
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32\memmodel\epoc\direct\mcodeseg.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <memmodel.h>
|
sl@0
|
19 |
#include <kernel/cache.h>
|
sl@0
|
20 |
|
sl@0
|
21 |
DCodeSeg* M::NewCodeSeg(TCodeSegCreateInfo&)
|
sl@0
|
22 |
{
|
sl@0
|
23 |
__KTRACE_OPT(KDLL,Kern::Printf("M::NewCodeSeg"));
|
sl@0
|
24 |
return new DMemModelCodeSeg;
|
sl@0
|
25 |
}
|
sl@0
|
26 |
|
sl@0
|
27 |
|
sl@0
|
28 |
DEpocCodeSegMemory* DEpocCodeSegMemory::New(DEpocCodeSeg* aCodeSeg)
|
sl@0
|
29 |
{
|
sl@0
|
30 |
return new DMemModelCodeSegMemory(aCodeSeg);
|
sl@0
|
31 |
}
|
sl@0
|
32 |
|
sl@0
|
33 |
|
sl@0
|
34 |
DMemModelCodeSegMemory::DMemModelCodeSegMemory(DEpocCodeSeg* aCodeSeg)
|
sl@0
|
35 |
: DEpocCodeSegMemory(aCodeSeg)
|
sl@0
|
36 |
{
|
sl@0
|
37 |
}
|
sl@0
|
38 |
|
sl@0
|
39 |
|
sl@0
|
40 |
DMemModelCodeSeg::DMemModelCodeSeg()
|
sl@0
|
41 |
{
|
sl@0
|
42 |
}
|
sl@0
|
43 |
|
sl@0
|
44 |
|
sl@0
|
45 |
DMemModelCodeSeg::~DMemModelCodeSeg()
|
sl@0
|
46 |
//
|
sl@0
|
47 |
// Destructor
|
sl@0
|
48 |
//
|
sl@0
|
49 |
{
|
sl@0
|
50 |
__KTRACE_OPT(KDLL,Kern::Printf("DMemModelCodeSeg::Destruct %C", this));
|
sl@0
|
51 |
if (!iXIP && iMemory)
|
sl@0
|
52 |
{
|
sl@0
|
53 |
SRamCodeInfo& ri=RamInfo();
|
sl@0
|
54 |
if (ri.iCodeLoadAddr)
|
sl@0
|
55 |
{
|
sl@0
|
56 |
TInt code_size=MM::RoundToBlockSize(ri.iCodeSize+ri.iDataSize);
|
sl@0
|
57 |
MM::FreeRegion(ri.iCodeLoadAddr, code_size);
|
sl@0
|
58 |
}
|
sl@0
|
59 |
if (iDataAlloc)
|
sl@0
|
60 |
{
|
sl@0
|
61 |
TInt data_size=MM::RoundToBlockSize(ri.iDataSize+ri.iBssSize);
|
sl@0
|
62 |
MM::FreeRegion(iDataAlloc, data_size);
|
sl@0
|
63 |
}
|
sl@0
|
64 |
}
|
sl@0
|
65 |
Kern::Free(iKernelData);
|
sl@0
|
66 |
DEpocCodeSeg::Destruct();
|
sl@0
|
67 |
}
|
sl@0
|
68 |
|
sl@0
|
69 |
TInt DMemModelCodeSeg::DoCreateRam(TCodeSegCreateInfo& aInfo, DProcess* aProcess)
|
sl@0
|
70 |
{
|
sl@0
|
71 |
__KTRACE_OPT(KDLL,Kern::Printf("DMemModelCodeSeg::DoCreateRam %C proc %O", this, aProcess));
|
sl@0
|
72 |
DMemModelProcess* p=(DMemModelProcess*)aProcess;
|
sl@0
|
73 |
TBool kernel=( (iAttr&(ECodeSegAttKernel|ECodeSegAttGlobal)) == ECodeSegAttKernel );
|
sl@0
|
74 |
SRamCodeInfo& ri=RamInfo();
|
sl@0
|
75 |
iSize = MM::RoundToBlockSize(ri.iCodeSize+ri.iDataSize);
|
sl@0
|
76 |
TInt total_data_size=ri.iDataSize+ri.iBssSize;
|
sl@0
|
77 |
TInt r=MM::AllocRegion(ri.iCodeLoadAddr, iSize);
|
sl@0
|
78 |
if (r!=KErrNone)
|
sl@0
|
79 |
return r;
|
sl@0
|
80 |
ri.iCodeRunAddr=ri.iCodeLoadAddr;
|
sl@0
|
81 |
if (ri.iDataSize)
|
sl@0
|
82 |
ri.iDataLoadAddr=ri.iCodeLoadAddr+ri.iCodeSize;
|
sl@0
|
83 |
if (kernel)
|
sl@0
|
84 |
{
|
sl@0
|
85 |
if (total_data_size)
|
sl@0
|
86 |
{
|
sl@0
|
87 |
iKernelData=Kern::Alloc(total_data_size);
|
sl@0
|
88 |
if (!iKernelData)
|
sl@0
|
89 |
return KErrNoMemory;
|
sl@0
|
90 |
ri.iDataRunAddr=(TLinAddr)iKernelData;
|
sl@0
|
91 |
}
|
sl@0
|
92 |
return KErrNone;
|
sl@0
|
93 |
}
|
sl@0
|
94 |
if (total_data_size && p)
|
sl@0
|
95 |
SetAttachProcess(p);
|
sl@0
|
96 |
if (total_data_size && !IsExe())
|
sl@0
|
97 |
{
|
sl@0
|
98 |
TInt data_alloc_size=MM::RoundToBlockSize(total_data_size);
|
sl@0
|
99 |
TInt r=MM::AllocRegion(iDataAlloc, data_alloc_size);
|
sl@0
|
100 |
if (r!=KErrNone)
|
sl@0
|
101 |
return r;
|
sl@0
|
102 |
ri.iDataRunAddr=iDataAlloc;
|
sl@0
|
103 |
}
|
sl@0
|
104 |
return r;
|
sl@0
|
105 |
}
|
sl@0
|
106 |
|
sl@0
|
107 |
TInt DMemModelCodeSeg::DoCreateXIP(DProcess* aProcess)
|
sl@0
|
108 |
{
|
sl@0
|
109 |
__KTRACE_OPT(KDLL,Kern::Printf("DMemModelCodeSeg::DoCreateXIP %C proc %O", this, aProcess));
|
sl@0
|
110 |
DMemModelProcess* p=(DMemModelProcess*)aProcess;
|
sl@0
|
111 |
TInt r=KErrNone;
|
sl@0
|
112 |
TBool kernel=( (iAttr&(ECodeSegAttKernel|ECodeSegAttGlobal)) == ECodeSegAttKernel );
|
sl@0
|
113 |
const TRomImageHeader& rih=RomInfo();
|
sl@0
|
114 |
if (!kernel && aProcess)
|
sl@0
|
115 |
{
|
sl@0
|
116 |
// XIP images with static data are specific to a single process
|
sl@0
|
117 |
if (rih.iFlags&KRomImageFlagDataPresent)
|
sl@0
|
118 |
SetAttachProcess(p);
|
sl@0
|
119 |
}
|
sl@0
|
120 |
return r;
|
sl@0
|
121 |
}
|
sl@0
|
122 |
|
sl@0
|
123 |
TInt DMemModelCodeSeg::Loaded(TCodeSegCreateInfo& aInfo)
|
sl@0
|
124 |
{
|
sl@0
|
125 |
if (!iXIP)
|
sl@0
|
126 |
{
|
sl@0
|
127 |
// Clean DCache for specified area, Invalidate ICache/BTB for specified area
|
sl@0
|
128 |
TLinAddr code_base=RamInfo().iCodeRunAddr;
|
sl@0
|
129 |
Cache::IMB_Range(code_base, RamInfo().iCodeSize);
|
sl@0
|
130 |
}
|
sl@0
|
131 |
return DEpocCodeSeg::Loaded(aInfo);
|
sl@0
|
132 |
}
|
sl@0
|
133 |
|
sl@0
|
134 |
void DMemModelCodeSeg::ReadExportDir(TUint32* aDest)
|
sl@0
|
135 |
{
|
sl@0
|
136 |
__KTRACE_OPT(KDLL,Kern::Printf("DMemModelCodeSeg::ReadExportDir %08x",aDest));
|
sl@0
|
137 |
if (!iXIP)
|
sl@0
|
138 |
{
|
sl@0
|
139 |
SRamCodeInfo& ri=RamInfo();
|
sl@0
|
140 |
TInt size=(ri.iExportDirCount+1)*sizeof(TLinAddr);
|
sl@0
|
141 |
kumemput32(aDest, (const TUint32*)(ri.iExportDir-sizeof(TUint32)), size);
|
sl@0
|
142 |
}
|
sl@0
|
143 |
}
|
sl@0
|
144 |
|
sl@0
|
145 |
TBool DMemModelCodeSeg::OpenCheck(DProcess* aProcess)
|
sl@0
|
146 |
{
|
sl@0
|
147 |
return FindCheck(aProcess);
|
sl@0
|
148 |
}
|
sl@0
|
149 |
|
sl@0
|
150 |
TBool DMemModelCodeSeg::FindCheck(DProcess* aProcess)
|
sl@0
|
151 |
{
|
sl@0
|
152 |
__KTRACE_OPT(KDLL,Kern::Printf("CSEG:%08x Compat? proc=%O",this,aProcess));
|
sl@0
|
153 |
if (!aProcess)
|
sl@0
|
154 |
return !iAttachProcess; // can't reuse same code segment for a new instance of the process
|
sl@0
|
155 |
DMemModelProcess& p=*(DMemModelProcess*)aProcess;
|
sl@0
|
156 |
DCodeSeg* pPSeg=p.CodeSeg();
|
sl@0
|
157 |
if (iAttachProcess && iAttachProcess!=aProcess)
|
sl@0
|
158 |
return EFalse;
|
sl@0
|
159 |
if (iExeCodeSeg && iExeCodeSeg!=pPSeg)
|
sl@0
|
160 |
return EFalse;
|
sl@0
|
161 |
__ASSERT_DEBUG( (iAttachProcess || !(iMark & EMarkDataPresent)), MM::Panic(MM::ECodeSegCheckInconsistent));
|
sl@0
|
162 |
return ETrue;
|
sl@0
|
163 |
}
|
sl@0
|
164 |
|