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\euser\epoc\win32\uc_utl.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include "u32std.h"
|
sl@0
|
19 |
#include <e32base.h>
|
sl@0
|
20 |
#include <e32base_private.h>
|
sl@0
|
21 |
#include <e32hashtab.h>
|
sl@0
|
22 |
#include <emulator.h>
|
sl@0
|
23 |
#include "uc_std.h"
|
sl@0
|
24 |
|
sl@0
|
25 |
typedef void (*TBootEpoc)(TBool);
|
sl@0
|
26 |
|
sl@0
|
27 |
#ifdef __LEAVE_EQUALS_THROW__
|
sl@0
|
28 |
|
sl@0
|
29 |
// Stub versions of TTrap exports to keep X86 and WINS versions of euser.def
|
sl@0
|
30 |
// the same.
|
sl@0
|
31 |
|
sl@0
|
32 |
class TTrap
|
sl@0
|
33 |
{
|
sl@0
|
34 |
public:
|
sl@0
|
35 |
IMPORT_C TInt Trap(TInt& aResult);
|
sl@0
|
36 |
IMPORT_C static void UnTrap();
|
sl@0
|
37 |
};
|
sl@0
|
38 |
|
sl@0
|
39 |
|
sl@0
|
40 |
#ifdef __SYMC__
|
sl@0
|
41 |
|
sl@0
|
42 |
EXPORT_C TInt TTrap::Trap(TInt&)
|
sl@0
|
43 |
{
|
sl@0
|
44 |
/*
|
sl@0
|
45 |
TTrapHandler* h = Exec::PushTrapFrame(this);
|
sl@0
|
46 |
if (h != NULL)
|
sl@0
|
47 |
h->Trap();
|
sl@0
|
48 |
*/
|
sl@0
|
49 |
return 0;
|
sl@0
|
50 |
}
|
sl@0
|
51 |
|
sl@0
|
52 |
EXPORT_C void TTrap::UnTrap()
|
sl@0
|
53 |
{
|
sl@0
|
54 |
}
|
sl@0
|
55 |
|
sl@0
|
56 |
#else
|
sl@0
|
57 |
EXPORT_C TInt TTrap::Trap(TInt&)
|
sl@0
|
58 |
{
|
sl@0
|
59 |
return 0;
|
sl@0
|
60 |
}
|
sl@0
|
61 |
|
sl@0
|
62 |
EXPORT_C void TTrap::UnTrap()
|
sl@0
|
63 |
{
|
sl@0
|
64 |
}
|
sl@0
|
65 |
#endif
|
sl@0
|
66 |
|
sl@0
|
67 |
#endif
|
sl@0
|
68 |
|
sl@0
|
69 |
EXPORT_C void EmptyFunction()
|
sl@0
|
70 |
//Function with an empty body
|
sl@0
|
71 |
{
|
sl@0
|
72 |
}
|
sl@0
|
73 |
|
sl@0
|
74 |
GLDEF_C void Panic(TCdtArchitecturePanic aPanic)
|
sl@0
|
75 |
//
|
sl@0
|
76 |
// Panic the process with USER as the category.
|
sl@0
|
77 |
//
|
sl@0
|
78 |
{
|
sl@0
|
79 |
_LIT(KCategory,"USER-Arch");
|
sl@0
|
80 |
User::Panic(KCategory,aPanic);
|
sl@0
|
81 |
}
|
sl@0
|
82 |
|
sl@0
|
83 |
|
sl@0
|
84 |
|
sl@0
|
85 |
|
sl@0
|
86 |
EXPORT_C TInt User::IsRomAddress(TBool& aBool, TAny* aPtr)
|
sl@0
|
87 |
//
|
sl@0
|
88 |
// The FileServer loads ROM files as ReadOnly Memory Mapped Files
|
sl@0
|
89 |
// We check the access rights of the given address for :
|
sl@0
|
90 |
// Read access
|
sl@0
|
91 |
// No write access
|
sl@0
|
92 |
//
|
sl@0
|
93 |
/**
|
sl@0
|
94 |
Tests whether the specified address is in the ROM.
|
sl@0
|
95 |
|
sl@0
|
96 |
@param aBool True, if the address at aPtr is within the ROM; false,
|
sl@0
|
97 |
otherwise.
|
sl@0
|
98 |
@param aPtr The address to be tested.
|
sl@0
|
99 |
|
sl@0
|
100 |
@return Always KErrNone.
|
sl@0
|
101 |
*/
|
sl@0
|
102 |
{
|
sl@0
|
103 |
const TInt KRomMask = 0xFF;
|
sl@0
|
104 |
const TInt KRomAccess = PAGE_READONLY;
|
sl@0
|
105 |
|
sl@0
|
106 |
aBool=EFalse;
|
sl@0
|
107 |
MEMORY_BASIC_INFORMATION mi;
|
sl@0
|
108 |
|
sl@0
|
109 |
__LOCK_HOST;
|
sl@0
|
110 |
if (VirtualQuery(aPtr, &mi, sizeof(mi)) != 0 && (mi.Protect & KRomMask) == KRomAccess)
|
sl@0
|
111 |
aBool=ETrue;
|
sl@0
|
112 |
return KErrNone;
|
sl@0
|
113 |
}
|
sl@0
|
114 |
|
sl@0
|
115 |
|
sl@0
|
116 |
|
sl@0
|
117 |
|
sl@0
|
118 |
EXPORT_C void BootEpoc(TBool aAutoRun)
|
sl@0
|
119 |
{
|
sl@0
|
120 |
HINSTANCE epoc = LoadLibraryA("ekern.exe");
|
sl@0
|
121 |
if (epoc)
|
sl@0
|
122 |
{
|
sl@0
|
123 |
TBootEpoc ep = (TBootEpoc)GetProcAddress(epoc, "_E32Startup");
|
sl@0
|
124 |
if (ep)
|
sl@0
|
125 |
ep(aAutoRun);
|
sl@0
|
126 |
}
|
sl@0
|
127 |
ExitProcess(102);
|
sl@0
|
128 |
}
|
sl@0
|
129 |
|
sl@0
|
130 |
EXPORT_C void RFastLock::Wait()
|
sl@0
|
131 |
{
|
sl@0
|
132 |
if (InterlockedDecrement((LPLONG)&iCount) < -1)
|
sl@0
|
133 |
RSemaphore::Wait();
|
sl@0
|
134 |
}
|
sl@0
|
135 |
|
sl@0
|
136 |
EXPORT_C void RFastLock::Signal()
|
sl@0
|
137 |
{
|
sl@0
|
138 |
if (InterlockedIncrement((LPLONG)&iCount) < 0)
|
sl@0
|
139 |
RSemaphore::Signal();
|
sl@0
|
140 |
}
|
sl@0
|
141 |
|
sl@0
|
142 |
// Hash an 8 bit string at aPtr, length aLen bytes.
|
sl@0
|
143 |
__NAKED__ TUint32 DefaultStringHash(const TUint8* /*aPtr*/, TInt /*aLen*/)
|
sl@0
|
144 |
{
|
sl@0
|
145 |
_asm push esi
|
sl@0
|
146 |
_asm mov esi, [esp+8]
|
sl@0
|
147 |
_asm mov ecx, [esp+12]
|
sl@0
|
148 |
_asm xor eax, eax
|
sl@0
|
149 |
_asm sub ecx, 4
|
sl@0
|
150 |
_asm jb lt4
|
sl@0
|
151 |
ge4:
|
sl@0
|
152 |
_asm xor eax, [esi]
|
sl@0
|
153 |
_asm add esi, 4
|
sl@0
|
154 |
_asm mov edx, 9E3779B9h
|
sl@0
|
155 |
_asm mul edx
|
sl@0
|
156 |
_asm sub ecx, 4
|
sl@0
|
157 |
_asm jae ge4
|
sl@0
|
158 |
lt4:
|
sl@0
|
159 |
_asm add ecx, 4
|
sl@0
|
160 |
_asm jz done
|
sl@0
|
161 |
_asm xor edx, edx
|
sl@0
|
162 |
_asm cmp ecx, 2
|
sl@0
|
163 |
_asm jbe le2
|
sl@0
|
164 |
_asm mov dl, [esi+2]
|
sl@0
|
165 |
_asm shl edx, 16
|
sl@0
|
166 |
le2:
|
sl@0
|
167 |
_asm cmp ecx, 2
|
sl@0
|
168 |
_asm jb onemore
|
sl@0
|
169 |
_asm mov dh, [esi+1]
|
sl@0
|
170 |
onemore:
|
sl@0
|
171 |
_asm mov dl, [esi]
|
sl@0
|
172 |
_asm xor eax, edx
|
sl@0
|
173 |
_asm mov edx, 9E3779B9h
|
sl@0
|
174 |
_asm mul edx
|
sl@0
|
175 |
done:
|
sl@0
|
176 |
_asm pop esi
|
sl@0
|
177 |
_asm ret
|
sl@0
|
178 |
}
|
sl@0
|
179 |
|
sl@0
|
180 |
// Hash a 16 bit string at aPtr, length aLen bytes.
|
sl@0
|
181 |
__NAKED__ TUint32 DefaultWStringHash(const TUint16* /*aPtr*/, TInt /*aLen*/)
|
sl@0
|
182 |
{
|
sl@0
|
183 |
_asm push esi
|
sl@0
|
184 |
_asm mov esi, [esp+8]
|
sl@0
|
185 |
_asm mov ecx, [esp+12]
|
sl@0
|
186 |
_asm xor eax, eax
|
sl@0
|
187 |
_asm sub ecx, 8
|
sl@0
|
188 |
_asm jb lt8
|
sl@0
|
189 |
ge8:
|
sl@0
|
190 |
_asm mov edx, [esi+4]
|
sl@0
|
191 |
_asm xor eax, [esi]
|
sl@0
|
192 |
_asm add esi, 8
|
sl@0
|
193 |
_asm rol edx, 8
|
sl@0
|
194 |
_asm xor eax, edx
|
sl@0
|
195 |
_asm mov edx, 9E3779B9h
|
sl@0
|
196 |
_asm mul edx
|
sl@0
|
197 |
_asm sub ecx, 8
|
sl@0
|
198 |
_asm jae ge8
|
sl@0
|
199 |
lt8:
|
sl@0
|
200 |
_asm add ecx, 8
|
sl@0
|
201 |
_asm jz done
|
sl@0
|
202 |
_asm xor edx, edx
|
sl@0
|
203 |
_asm cmp ecx, 4
|
sl@0
|
204 |
_asm jbe le4
|
sl@0
|
205 |
_asm mov dx, [esi+4]
|
sl@0
|
206 |
_asm rol edx, 8
|
sl@0
|
207 |
_asm xor eax, edx
|
sl@0
|
208 |
_asm xor edx, edx
|
sl@0
|
209 |
le4:
|
sl@0
|
210 |
_asm cmp ecx, 4
|
sl@0
|
211 |
_asm jb onemore
|
sl@0
|
212 |
_asm mov dx, [esi+2]
|
sl@0
|
213 |
_asm shl edx, 16
|
sl@0
|
214 |
onemore:
|
sl@0
|
215 |
_asm mov dx, [esi]
|
sl@0
|
216 |
_asm xor eax, edx
|
sl@0
|
217 |
_asm mov edx, 9E3779B9h
|
sl@0
|
218 |
_asm mul edx
|
sl@0
|
219 |
done:
|
sl@0
|
220 |
_asm pop esi
|
sl@0
|
221 |
_asm ret
|
sl@0
|
222 |
}
|
sl@0
|
223 |
|
sl@0
|
224 |
/**
|
sl@0
|
225 |
@publishedAll
|
sl@0
|
226 |
@released
|
sl@0
|
227 |
|
sl@0
|
228 |
Calculate a 32 bit hash from a 32 bit integer.
|
sl@0
|
229 |
|
sl@0
|
230 |
@param aInt The integer to be hashed.
|
sl@0
|
231 |
@return The calculated 32 bit hash value.
|
sl@0
|
232 |
*/
|
sl@0
|
233 |
EXPORT_C __NAKED__ TUint32 DefaultHash::Integer(const TInt& /*aInt*/)
|
sl@0
|
234 |
{
|
sl@0
|
235 |
_asm mov edx, [esp+4]
|
sl@0
|
236 |
_asm mov eax, 9E3779B9h
|
sl@0
|
237 |
_asm mul dword ptr [edx]
|
sl@0
|
238 |
_asm ret
|
sl@0
|
239 |
}
|
sl@0
|
240 |
|