|
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 // |
|
15 |
|
16 #include <x86_mem.h> |
|
17 #include "mm.h" |
|
18 |
|
19 |
|
20 TInt DX86PlatThread::SetupContext(SThreadCreateInfo& aInfo) |
|
21 { |
|
22 switch(iThreadType) |
|
23 { |
|
24 case EThreadSupervisor: |
|
25 case EThreadMinimalSupervisor: |
|
26 case EThreadInitial: |
|
27 case EThreadAPInitial: |
|
28 break; |
|
29 case EThreadUser: |
|
30 break; |
|
31 } |
|
32 iNThread.SetAddressSpace(iOwningProcess); |
|
33 iNThread.SetAttributes(KThreadAttAddressSpace); |
|
34 #ifdef __SMP__ |
|
35 iCpuRestoreCookie = -1; |
|
36 #else |
|
37 // OK to get this thread's owning process os asid as the process can't free |
|
38 // it's asid while this thread is being created because the current thread |
|
39 // has the same owning process. |
|
40 MM::IpcAliasPde(iAliasPdePtr,((DMemModelProcess*)iOwningProcess)->OsAsid()); |
|
41 #endif |
|
42 return KErrNone; |
|
43 } |
|
44 |
|
45 TIpcExcTrap::TExcLocation TIpcExcTrap::ExcLocation(DThread* aThread, TAny* aContext) |
|
46 { |
|
47 TX86ExcInfo& info=*(TX86ExcInfo*)aContext; |
|
48 if (info.iExcId==EX86VectorPageFault) |
|
49 { |
|
50 TLinAddr va=(TLinAddr)info.iFaultAddress; |
|
51 |
|
52 TLinAddr aliasAddr = ((DMemModelThread*)aThread)->iAliasLinAddr; |
|
53 TBool remoteError; |
|
54 if(aliasAddr) |
|
55 remoteError = TUint(va^aliasAddr)<TUint(KPageSize); |
|
56 else |
|
57 // The second clause in the statement below was "va < iRemoteBase + iSize". |
|
58 // iRemoteBase + iSize might conceivably wrap round. |
|
59 // The usual fix for this is to change |
|
60 // va >= base && va < base + size |
|
61 // to va >= base && (va - base) < size |
|
62 // but this requires the first clause (va >= base) so that va-base doesn't wrap negative. |
|
63 // Since the first clause in this expression is va >= (iRemoteBase & ~3) |
|
64 // we have to re-write the expression as follows: |
|
65 // Let base' = iRemoteBase & ~3 |
|
66 // so base = base' + (base & 3) |
|
67 // then we have va >= base' && va < base' + (base & 3) + iSize |
|
68 // (effectively the & ~3 on the first clause extends the range downwards by base & 3) |
|
69 remoteError = va>=(iRemoteBase&~3) && |
|
70 (va - (iRemoteBase & ~3)) < iSize + (iRemoteBase & 3); |
|
71 if (remoteError) |
|
72 return EExcRemote; |
|
73 |
|
74 // Third clause was va < iLocalBase + iSize, fixed as in the "remoteError =" line above |
|
75 if (iLocalBase && va>=(iLocalBase&~3) && |
|
76 (va - (iLocalBase & ~3)) < iSize + (iLocalBase & 3)) |
|
77 return EExcLocal; |
|
78 } |
|
79 else if (info.iExcId==EX86VectorGPF) |
|
80 { |
|
81 TUint16 ds=(TUint16)info.iDs; |
|
82 TUint16 es=(TUint16)info.iEs; |
|
83 TUint16 seg=iDir?ds:es; // write -> local read -> DS restricted, else ES restricted |
|
84 if (seg==KRing3DS || seg==KRing3CS) |
|
85 return EExcLocal; |
|
86 } |
|
87 return EExcUnknown; |
|
88 } |