|
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 // e32\memmodel\epoc\direct\mkernel.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include <memmodel.h> |
|
19 |
|
20 EXPORT_C TInt Kern::FreeRamInBytes() |
|
21 { |
|
22 return MM::RamAllocator->Avail()<<MM::RamBlockShift; |
|
23 } |
|
24 |
|
25 /******************************************** |
|
26 * Thread |
|
27 ********************************************/ |
|
28 |
|
29 TInt DThread::AllocateSupervisorStack() |
|
30 { |
|
31 __KTRACE_OPT(KTHREAD,Kern::Printf("DThread::AllocateSupervisorStack %O %x",this,iSupervisorStackSize)); |
|
32 iSupervisorStackSize=MM::RoundToBlockSize(iSupervisorStackSize); |
|
33 if (iThreadType!=EThreadInitial) |
|
34 { |
|
35 TAny* p=Kern::Alloc(iSupervisorStackSize); // just allocate on kernel heap |
|
36 if (!p) |
|
37 return KErrNoMemory; |
|
38 iSupervisorStack=p; |
|
39 iSupervisorStackAllocated = TRUE; |
|
40 __KTRACE_OPT(KTHREAD,Kern::Printf("Supervisor stack at %x, size %x",iSupervisorStack,iSupervisorStackSize)); |
|
41 } |
|
42 return KErrNone; |
|
43 } |
|
44 |
|
45 void DThread::FreeSupervisorStack() |
|
46 { |
|
47 __KTRACE_OPT(KTHREAD,Kern::Printf("DThread::FreeSupervisorStack %O",this)); |
|
48 if (iSupervisorStackAllocated) |
|
49 { |
|
50 TAny* pStack = __e32_atomic_swp_ord_ptr(&iSupervisorStack, 0); |
|
51 if (pStack && iThreadType!=EThreadInitial) |
|
52 { |
|
53 __KTRACE_OPT(KTHREAD,Kern::Printf("Freeing supervisor stack at %08x, size %x",pStack,iSupervisorStackSize)); |
|
54 Kern::Free(pStack); |
|
55 } |
|
56 } |
|
57 iSupervisorStackAllocated = FALSE; |
|
58 } |
|
59 |
|
60 TInt DThread::AllocateUserStack(TInt aSize, TBool /*aPaged*/) |
|
61 { |
|
62 __KTRACE_OPT(KTHREAD,Kern::Printf("DThread::AllocateUserStack %O %x",this,aSize)); |
|
63 |
|
64 aSize=MM::RoundToBlockSize(aSize); |
|
65 if (aSize>PP::MaxUserThreadStack) |
|
66 return KErrTooBig; |
|
67 TInt r; |
|
68 MM::WaitRamAlloc(); |
|
69 r=MM::AllocRegion(iUserStackRunAddress, aSize); |
|
70 if (r==KErrNone) |
|
71 iUserStackSize=aSize; |
|
72 else |
|
73 { |
|
74 iUserStackSize=0; |
|
75 MM::AllocFailed=ETrue; |
|
76 } |
|
77 MM::SignalRamAlloc(); |
|
78 __KTRACE_OPT(KTHREAD,Kern::Printf("User stack run address at %x",iUserStackRunAddress)); |
|
79 return r; |
|
80 } |
|
81 |
|
82 void DThread::FreeUserStack() |
|
83 { |
|
84 __KTRACE_OPT(KTHREAD,Kern::Printf("DThread::FreeUserStack %O",this)); |
|
85 TLinAddr usr_stack_size = (TLinAddr)__e32_atomic_swp_ord32(&iUserStackSize, 0); |
|
86 if (usr_stack_size) |
|
87 { |
|
88 __KTRACE_OPT(KTHREAD,Kern::Printf("Freeing user stack at %x+%x",iUserStackRunAddress,usr_stack_size)); |
|
89 MM::WaitRamAlloc(); |
|
90 MM::FreeRegion(iUserStackRunAddress, usr_stack_size); |
|
91 iUserStackRunAddress=0; |
|
92 MM::SignalRamAlloc(); |
|
93 } |
|
94 } |
|
95 |