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