sl@0
|
1 |
// Copyright (c) 1994-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\common\mem.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include "common.h"
|
sl@0
|
19 |
|
sl@0
|
20 |
//This is used in heap.cpp and it is defined here, as a requirement for patchdata
|
sl@0
|
21 |
EXPORT_D extern const TInt KHeapMinCellSize = 0;
|
sl@0
|
22 |
EXPORT_D extern const TInt KHeapShrinkHysRatio = RHeap::EShrinkRatioDflt;
|
sl@0
|
23 |
//NOTE - if these values are changed then the WINS test case value must be updated
|
sl@0
|
24 |
|
sl@0
|
25 |
#ifndef __MEM_MACHINE_CODED__
|
sl@0
|
26 |
|
sl@0
|
27 |
extern "C" {
|
sl@0
|
28 |
|
sl@0
|
29 |
//SL:
|
sl@0
|
30 |
#ifndef __TOOLS__
|
sl@0
|
31 |
// See header file e32cmn.h for the in-source documentation.
|
sl@0
|
32 |
EXPORT_C TAny* memcpy(TAny* aTrg, const TAny* aSrc, unsigned int aLength)
|
sl@0
|
33 |
{
|
sl@0
|
34 |
return memmove(aTrg, aSrc, aLength);
|
sl@0
|
35 |
}
|
sl@0
|
36 |
|
sl@0
|
37 |
// See header file e32cmn.h for the in-source documentation.
|
sl@0
|
38 |
EXPORT_C TAny* memmove(TAny* aTrg, const TAny* aSrc, unsigned int aLength)
|
sl@0
|
39 |
{
|
sl@0
|
40 |
if (aLength==0)
|
sl@0
|
41 |
return((TUint8*)aTrg);
|
sl@0
|
42 |
TInt aLen32=0;
|
sl@0
|
43 |
TUint32* pT32=(TUint32*)aTrg;
|
sl@0
|
44 |
const TUint32* pS32=(TUint32 *)aSrc;
|
sl@0
|
45 |
if (((TInt)pT32&3)==0 && ((TInt)pS32&3)==0)
|
sl@0
|
46 |
aLen32=aLength>>2;
|
sl@0
|
47 |
TInt aLen8=aLength-(aLen32<<2);
|
sl@0
|
48 |
TUint32* pE32=pT32+aLen32;
|
sl@0
|
49 |
TUint8* pT;
|
sl@0
|
50 |
TUint8* pE;
|
sl@0
|
51 |
TUint8* pS;
|
sl@0
|
52 |
if (aTrg<aSrc)
|
sl@0
|
53 |
{
|
sl@0
|
54 |
pS32=(TUint32*)aSrc;
|
sl@0
|
55 |
while (pT32<pE32)
|
sl@0
|
56 |
*pT32++=(*pS32++);
|
sl@0
|
57 |
pT=(TUint8*)pT32;
|
sl@0
|
58 |
pS=(TUint8*)pS32;
|
sl@0
|
59 |
pE=(TUint8*)aTrg+aLength;
|
sl@0
|
60 |
while (pT<pE)
|
sl@0
|
61 |
*pT++=(*pS++);
|
sl@0
|
62 |
}
|
sl@0
|
63 |
else if (aTrg>aSrc)
|
sl@0
|
64 |
{
|
sl@0
|
65 |
pT=(TUint8*)(pT32+aLen32);
|
sl@0
|
66 |
pE=pT+aLen8;
|
sl@0
|
67 |
pS=(TUint8*)aSrc+aLength;
|
sl@0
|
68 |
while (pE>pT)
|
sl@0
|
69 |
*--pE=(*--pS);
|
sl@0
|
70 |
pS32=(TUint32*)pS;
|
sl@0
|
71 |
while (pE32>pT32)
|
sl@0
|
72 |
*--pE32=(*--pS32);
|
sl@0
|
73 |
}
|
sl@0
|
74 |
return aTrg;
|
sl@0
|
75 |
}
|
sl@0
|
76 |
#endif
|
sl@0
|
77 |
|
sl@0
|
78 |
|
sl@0
|
79 |
// See header file e32cmn.h for the in-source documentation.
|
sl@0
|
80 |
EXPORT_C TAny* memclr(TAny* aTrg, unsigned int aLength)
|
sl@0
|
81 |
{
|
sl@0
|
82 |
return memset(aTrg, 0, aLength);
|
sl@0
|
83 |
}
|
sl@0
|
84 |
|
sl@0
|
85 |
|
sl@0
|
86 |
//SL:
|
sl@0
|
87 |
#ifndef __TOOLS__
|
sl@0
|
88 |
|
sl@0
|
89 |
|
sl@0
|
90 |
// See header file e32cmn.h for the in-source documentation.
|
sl@0
|
91 |
EXPORT_C TAny* memset(TAny* aTrg, TInt aValue, unsigned int aLength)
|
sl@0
|
92 |
{
|
sl@0
|
93 |
TInt aLen32=0;
|
sl@0
|
94 |
TUint32 *pM32=(TUint32 *)aTrg;
|
sl@0
|
95 |
if (((TInt)aTrg&3)==0)
|
sl@0
|
96 |
{
|
sl@0
|
97 |
aLen32=aLength>>2;
|
sl@0
|
98 |
TUint32 *pE32=pM32+aLen32;
|
sl@0
|
99 |
TUint c = aValue & 0xff;
|
sl@0
|
100 |
TUint32 fillChar=c+(c<<8)+(c<<16)+(c<<24);
|
sl@0
|
101 |
while (pM32<pE32)
|
sl@0
|
102 |
*pM32++=fillChar;
|
sl@0
|
103 |
}
|
sl@0
|
104 |
TInt aLen8=aLength-(aLen32<<2);
|
sl@0
|
105 |
TUint8 *pM=(TUint8 *)pM32;
|
sl@0
|
106 |
TUint8 *pE=pM+aLen8;
|
sl@0
|
107 |
while (pM<pE)
|
sl@0
|
108 |
*pM++=TUint8(aValue);
|
sl@0
|
109 |
return aTrg;
|
sl@0
|
110 |
}
|
sl@0
|
111 |
|
sl@0
|
112 |
#endif
|
sl@0
|
113 |
|
sl@0
|
114 |
} // extern "C"
|
sl@0
|
115 |
|
sl@0
|
116 |
extern "C" {
|
sl@0
|
117 |
|
sl@0
|
118 |
|
sl@0
|
119 |
|
sl@0
|
120 |
// See header file e32cmn.h for the in-source documentation.
|
sl@0
|
121 |
EXPORT_C TAny* wordmove(TAny* aTrg, const TAny* aSrc, unsigned int aLength)
|
sl@0
|
122 |
{
|
sl@0
|
123 |
__ASSERT_DEBUG((aLength&3)==0,Panic(EWordMoveLengthNotMultipleOf4));
|
sl@0
|
124 |
__ASSERT_DEBUG((((TUint)aSrc)&3)==0,Panic(EWordMoveSourceNotAligned));
|
sl@0
|
125 |
__ASSERT_DEBUG((((TUint)aTrg)&3)==0,Panic(EWordMoveTargetNotAligned));
|
sl@0
|
126 |
if (aLength==0)
|
sl@0
|
127 |
return((TUint8*)aTrg);
|
sl@0
|
128 |
TInt len=aLength>>2;
|
sl@0
|
129 |
TUint32* pT=(TUint32*)aTrg;
|
sl@0
|
130 |
const TUint32* pS=(const TUint32*)aSrc;
|
sl@0
|
131 |
const TUint32* pE=pS+len;
|
sl@0
|
132 |
if (pT<pS)
|
sl@0
|
133 |
{
|
sl@0
|
134 |
while (pS<pE)
|
sl@0
|
135 |
*pT++=(*pS++);
|
sl@0
|
136 |
}
|
sl@0
|
137 |
else if (pT>pS)
|
sl@0
|
138 |
{
|
sl@0
|
139 |
pT+=len;
|
sl@0
|
140 |
while (pE>pS)
|
sl@0
|
141 |
*--pT=(*--pE);
|
sl@0
|
142 |
}
|
sl@0
|
143 |
return aTrg;
|
sl@0
|
144 |
}
|
sl@0
|
145 |
|
sl@0
|
146 |
|
sl@0
|
147 |
|
sl@0
|
148 |
|
sl@0
|
149 |
// See header file e32cmn.h for the in-source documentation.
|
sl@0
|
150 |
EXPORT_C TInt memcompare(const TUint8* aLeft, TInt aLeftL, const TUint8* aRight, TInt aRightL)
|
sl@0
|
151 |
{
|
sl@0
|
152 |
|
sl@0
|
153 |
__ASSERT_DEBUG(aLeftL>=0,Panic(EMemLeftNegative));
|
sl@0
|
154 |
__ASSERT_DEBUG(aRightL>=0,Panic(EMemRightNegative));
|
sl@0
|
155 |
const TUint8 *pE=aLeft+Min(aLeftL,aRightL);
|
sl@0
|
156 |
while (aLeft<pE)
|
sl@0
|
157 |
{
|
sl@0
|
158 |
TInt d=(*aLeft++)-(*aRight++);
|
sl@0
|
159 |
if (d!=0)
|
sl@0
|
160 |
return(d);
|
sl@0
|
161 |
}
|
sl@0
|
162 |
return(aLeftL-aRightL);
|
sl@0
|
163 |
}
|
sl@0
|
164 |
|
sl@0
|
165 |
} // extern "C"
|
sl@0
|
166 |
|
sl@0
|
167 |
|
sl@0
|
168 |
|
sl@0
|
169 |
|
sl@0
|
170 |
#if defined(__GCC32__) && !defined(__KERNEL_MODE__)
|
sl@0
|
171 |
/**
|
sl@0
|
172 |
Compares a block of data at one specified location with a block of data at
|
sl@0
|
173 |
another specified location.
|
sl@0
|
174 |
|
sl@0
|
175 |
The comparison proceeds on a byte for byte basis, the result of the comparison
|
sl@0
|
176 |
is based on the difference of the first bytes to disagree.
|
sl@0
|
177 |
|
sl@0
|
178 |
The data at the two locations are equal if they have the same length and content.
|
sl@0
|
179 |
Where the lengths are different and the shorter section of data is the same
|
sl@0
|
180 |
as the first part of the longer section of data, the shorter is considered
|
sl@0
|
181 |
to be less than the longer.
|
sl@0
|
182 |
|
sl@0
|
183 |
@param aLeft A pointer to the first (or left) block of 8 bit data
|
sl@0
|
184 |
to be compared.
|
sl@0
|
185 |
@param aLeftL The length of the first (or left) block of data to be compared,
|
sl@0
|
186 |
i.e. the number of bytes.
|
sl@0
|
187 |
@param aRight A pointer to the second (or right) block of 8 bit data to be
|
sl@0
|
188 |
compared.
|
sl@0
|
189 |
@param aRightL The length of the second (or right) block of data to be compared
|
sl@0
|
190 |
i.e. the number of bytes.
|
sl@0
|
191 |
|
sl@0
|
192 |
@return Positive, if the first (or left) block of data is greater than the
|
sl@0
|
193 |
second (or right) block of data.
|
sl@0
|
194 |
Negative, if the first (or left) block of data is less than the
|
sl@0
|
195 |
second (or right) block of data.
|
sl@0
|
196 |
Zero, if both the first (or left) and second (or right) blocks of data
|
sl@0
|
197 |
have the same length and the same content.
|
sl@0
|
198 |
*/
|
sl@0
|
199 |
EXPORT_C TInt Mem::Compare(const TUint8* aLeft, TInt aLeftL, const TUint8* aRight, TInt aRightL)
|
sl@0
|
200 |
{
|
sl@0
|
201 |
memcompare(aLeft, aLeftL, aRight, aRightL);
|
sl@0
|
202 |
}
|
sl@0
|
203 |
#endif
|
sl@0
|
204 |
|
sl@0
|
205 |
#else // __MEM_MACHINE_CODED__
|
sl@0
|
206 |
|
sl@0
|
207 |
#if defined(_DEBUG) && defined(__CPU_ARM)
|
sl@0
|
208 |
|
sl@0
|
209 |
GLDEF_C void PanicEWordMoveLengthNotMultipleOf4()
|
sl@0
|
210 |
{
|
sl@0
|
211 |
Panic(EWordMoveLengthNotMultipleOf4);
|
sl@0
|
212 |
}
|
sl@0
|
213 |
|
sl@0
|
214 |
GLDEF_C void PanicEWordMoveSourceNotAligned()
|
sl@0
|
215 |
{
|
sl@0
|
216 |
Panic(EWordMoveSourceNotAligned);
|
sl@0
|
217 |
}
|
sl@0
|
218 |
|
sl@0
|
219 |
GLDEF_C void PanicEWordMoveTargetNotAligned()
|
sl@0
|
220 |
{
|
sl@0
|
221 |
Panic(EWordMoveTargetNotAligned);
|
sl@0
|
222 |
}
|
sl@0
|
223 |
|
sl@0
|
224 |
#endif
|
sl@0
|
225 |
|
sl@0
|
226 |
#endif // __MEM_MACHINE_CODED__
|
sl@0
|
227 |
|
sl@0
|
228 |
#ifndef __KERNEL_MODE__
|
sl@0
|
229 |
//
|
sl@0
|
230 |
// Dummy class for Binary Compatibility purposes
|
sl@0
|
231 |
//
|
sl@0
|
232 |
class Mem1
|
sl@0
|
233 |
{
|
sl@0
|
234 |
public:
|
sl@0
|
235 |
IMPORT_C static TUint8* Copy(TAny* aTrg,const TAny* aSrc,TInt aLength);
|
sl@0
|
236 |
IMPORT_C static TUint8* Move(TAny* aTrg,const TAny* aSrc,TInt aLength);
|
sl@0
|
237 |
IMPORT_C static void Fill(TAny* aTrg,TInt aLength,TChar aChar);
|
sl@0
|
238 |
};
|
sl@0
|
239 |
EXPORT_C void Mem1::Fill(TAny* aTrg,TInt aLength,TChar aChar)
|
sl@0
|
240 |
{ Mem::Fill(aTrg,aLength,aChar); }
|
sl@0
|
241 |
EXPORT_C TUint8* Mem1::Copy(TAny* aTrg, const TAny* aSrc, TInt aLength)
|
sl@0
|
242 |
{ return Mem::Copy(aTrg, aSrc, aLength); }
|
sl@0
|
243 |
EXPORT_C TUint8* Mem1::Move(TAny* aTrg, const TAny* aSrc, TInt aLength)
|
sl@0
|
244 |
{ return Mem::Move(aTrg, aSrc, aLength); }
|
sl@0
|
245 |
|
sl@0
|
246 |
#endif // __KERNEL_MODE__
|