Skip to content
This repository was archived by the owner on Jun 5, 2019. It is now read-only.

Remove custom heap #486

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Application/EraseDeployment/EraseDeployment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

#include "tinyhal.h"

HAL_DECLARE_NULL_HEAP();

void ApplicationEntryPoint()
{
int nSects = 0;
Expand Down
14 changes: 2 additions & 12 deletions Application/MicroBooter/MicroBooter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// <No description>
//
// Microsoft dotNetMF Project
// Copyright �2004 Microsoft Corporation
// Copyright �2004 Microsoft Corporation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do not alter copyright comments/notices in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be accurate there is no change in the copyright notice. I haven't changed that obviously.
Being the copyright symbol that is different I would say that GitHub is having problems with the code page of the file it something like that.
But I'll do my best removing that difference from the file.

// One Microsoft Way, Redmond, Washington 98052-6399 U.S.A.
// All rights reserved.
// MICROSOFT CONFIDENTIAL
Expand All @@ -22,8 +22,6 @@ BOOL MemStreamSeekBlockAddress( BlockStorageStream &stream, UINT32 address );
static SREC_Handler g_SREC;
#endif

HAL_DECLARE_CUSTOM_HEAP( SimpleHeap_Allocate, SimpleHeap_Release, SimpleHeap_ReAllocate );

#pragma arm section zidata = "s_SystemStates"
static INT32 s_SystemStates[SYSTEM_STATE_TOTAL_STATES];
#pragma arm section zidata
Expand Down Expand Up @@ -265,7 +263,7 @@ static BOOL Memory_Read( UINT32 address, UINT32 length, BYTE* data )

if(s_ReadBuffer == NULL)
{
s_ReadBuffer = (UINT8*)private_malloc(readBufferSize);
s_ReadBuffer = (UINT8*)malloc(readBufferSize);

ASSERT(s_ReadBuffer != NULL);
if(s_ReadBuffer == NULL) return FALSE;
Expand Down Expand Up @@ -433,14 +431,6 @@ void BootEntryLoader()

Events_Initialize();

UINT8* BaseAddress;
UINT32 SizeInBytes;

HeapLocation( BaseAddress, SizeInBytes );

// Initialize custom heap with heap block returned from CustomHeapLocation
SimpleHeap_Initialize( BaseAddress, SizeInBytes );

// this is the place where interrupts are enabled after boot for the first time after boot
ENABLE_INTERRUPTS();

Expand Down
2 changes: 1 addition & 1 deletion Application/MicroBooter/SrecProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ BOOL SREC_Handler::Process( char c )

if(!m_Stream.IsXIP())
{
dstExec = (UINT32)private_malloc(m_ImageLength);
dstExec = (UINT32)malloc(m_ImageLength);

MemStreamSeekBlockAddress( m_Stream, m_ImageStart );

Expand Down
48 changes: 24 additions & 24 deletions Application/TinyBooter/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct BitFieldManager
{
const BlockDeviceInfo* deviceInfo = m_blockDevice->GetDeviceInfo();

data = (BYTE*)private_malloc( m_region->BytesPerBlock );
data = (BYTE*)malloc( m_region->BytesPerBlock );

if(data != NULL)
{
Expand All @@ -99,7 +99,7 @@ struct BitFieldManager
ConfigurationSector *pCfg = (ConfigurationSector*)data;
memset( (void*)&pCfg->SignatureCheck[ 0 ], 0xFF, sizeof(pCfg->SignatureCheck) );
m_blockDevice->Write( m_cfgPhysicalAddress, m_region->BytesPerBlock,data, FALSE );
private_free(data);
free(data);
}
else
{
Expand Down Expand Up @@ -150,7 +150,7 @@ struct BitFieldManager
else
{
UINT32 length = m_region->BytesPerBlock;
BYTE* dataptr = (BYTE*)private_malloc(length);
BYTE* dataptr = (BYTE*)malloc(length);

if(dataptr != NULL)
{
Expand All @@ -174,7 +174,7 @@ struct BitFieldManager

// write back to sector, as we only change one bit from 0 to 1, no need to erase sector
m_blockDevice->Write( m_cfgPhysicalAddress, length, dataptr, FALSE );
private_free(dataptr);
free(dataptr);
}

}
Expand Down Expand Up @@ -227,7 +227,7 @@ struct BitFieldManager
UINT32 length = sizeof(ConfigurationSector);

memset( &m_skipCfgSectorCheck, 0xff, sizeof(m_skipCfgSectorCheck) );
data = (BYTE*)private_malloc(length);
data = (BYTE*)malloc(length);
stream.Device->Read( m_cfgPhysicalAddress, length, (BYTE *)data );
configSector = (ConfigurationSector*)data;
m_signatureCheck = NULL;
Expand All @@ -253,7 +253,7 @@ struct BitFieldManager
m_signatureCheck = &m_skipCfgSectorCheck;
}

private_free(data);
free(data);

}
else // XIP device
Expand Down Expand Up @@ -476,7 +476,7 @@ static bool AccessMemory( UINT32 location, UINT32 lengthInBytes, BYTE* buf, int
{
if (mode == AccessMemory_Check)
{
bufPtr = (BYTE*) private_malloc(NumOfBytes);
bufPtr = (BYTE*) malloc(NumOfBytes);
if(!bufPtr) return false;
}

Expand All @@ -486,7 +486,7 @@ static bool AccessMemory( UINT32 location, UINT32 lengthInBytes, BYTE* buf, int
{
if (mode == AccessMemory_Check)
{
private_free(bufPtr);
free(bufPtr);
}

break;
Expand All @@ -495,7 +495,7 @@ static bool AccessMemory( UINT32 location, UINT32 lengthInBytes, BYTE* buf, int
if (mode == AccessMemory_Check)
{
*(UINT32*)buf = SUPPORT_ComputeCRC( bufPtr, NumOfBytes, *(UINT32*)buf );
private_free(bufPtr);
free(bufPtr);
}
}
break;
Expand Down Expand Up @@ -525,18 +525,18 @@ static bool AccessMemory( UINT32 location, UINT32 lengthInBytes, BYTE* buf, int
{
if(g_ConfigBuffer != NULL)
{
private_free(g_ConfigBuffer);
free(g_ConfigBuffer);
}
g_ConfigBufferLength = 0;

// g_ConfigBuffer = (UINT8*)private_malloc(pRegion->BytesPerBlock);
// g_ConfigBuffer = (UINT8*)malloc(pRegion->BytesPerBlock);
// Just allocate the configuration Sector size, configuration block can be large and not necessary to have that buffer.
g_ConfigBuffer = (UINT8*)private_malloc(g_ConfigBufferTotalSize);
g_ConfigBuffer = (UINT8*)malloc(g_ConfigBufferTotalSize);

}
else if(g_ConfigBufferTotalSize < ( g_ConfigBufferLength + lengthInBytes))
{
UINT8* tmp = (UINT8*)private_malloc(g_ConfigBufferLength + lengthInBytes);
UINT8* tmp = (UINT8*)malloc(g_ConfigBufferLength + lengthInBytes);

if(tmp == NULL)
{
Expand All @@ -545,7 +545,7 @@ static bool AccessMemory( UINT32 location, UINT32 lengthInBytes, BYTE* buf, int

memcpy( tmp, g_ConfigBuffer, g_ConfigBufferLength );

private_free(g_ConfigBuffer);
free(g_ConfigBuffer);

g_ConfigBuffer = tmp;
}
Expand Down Expand Up @@ -754,7 +754,7 @@ bool Loader_Engine::SignedDataState::VerifySignature( UINT8* signature, UINT32 l
const BlockDeviceInfo* deviceInfo = m_pDevice->GetDeviceInfo();
if(!deviceInfo->Attribute.SupportsXIP)
{
signCheckedAddr = (BYTE*)private_malloc(m_dataLength);
signCheckedAddr = (BYTE*)malloc(m_dataLength);
if (signCheckedAddr == NULL)
{
EraseMemoryAndReset();
Expand All @@ -764,7 +764,7 @@ bool Loader_Engine::SignedDataState::VerifySignature( UINT8* signature, UINT32 l
if(!m_pDevice->Read( m_dataAddress, m_dataLength, signCheckedAddr ))
{
EraseMemoryAndReset();
private_free(signCheckedAddr);
free(signCheckedAddr);

return false;
}
Expand All @@ -791,7 +791,7 @@ bool Loader_Engine::SignedDataState::VerifySignature( UINT8* signature, UINT32 l

if(!deviceInfo->Attribute.SupportsXIP)
{
private_free(signCheckedAddr);
free(signCheckedAddr);
}

return fret;
Expand Down Expand Up @@ -979,7 +979,7 @@ bool Loader_Engine::ProcessPayload( WP_Message* msg )
LOADER_ENGINE_SETFLAG( this, c_LoaderEngineFlag_ValidConnection );

//--//
#if defined(BIG_ENDIAN)
#if defined(NETMF_TARGET_BIG_ENDIAN)
SwapEndian( msg, msg->m_payload, msg->m_header.m_size, false );
#endif
size_t num;
Expand Down Expand Up @@ -1120,7 +1120,7 @@ bool Loader_Engine::TransmitMessage( const WP_Message* msg, bool fQueue )
UINT32 payloadSize;
UINT32 flags;

#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)
payloadSize = msg->m_header.m_size;
flags = msg->m_header.m_flags;
#else
Expand Down Expand Up @@ -1178,7 +1178,7 @@ void Loader_Engine::ReplyToCommand( WP_Message* msg, bool fSuccess, bool fCritic

msgReply.Initialize( &m_controller );

#if defined(BIG_ENDIAN)
#if defined(NETMF_TARGET_BIG_ENDIAN)
SwapEndian( msg, ptr, size, true );
#endif
msgReply.PrepareReply( msg->m_header, flags, size, (UINT8*)ptr );
Expand All @@ -1203,7 +1203,7 @@ bool Loader_Engine::Monitor_Ping( WP_Message* msg )
CLR_DBG_Commands::Monitor_Ping::Reply cmdReply;
cmdReply.m_source = CLR_DBG_Commands::Monitor_Ping::c_Ping_Source_TinyBooter;

#if defined(BIG_ENDIAN)
#if defined(NETMF_TARGET_BIG_ENDIAN)
cmdReply.m_dbg_flags = CLR_DBG_Commands::Monitor_Ping::c_Ping_DbgFlag_BigEndian;
#endif

Expand Down Expand Up @@ -1542,7 +1542,7 @@ bool Loader_Engine::Monitor_FlashSectorMap( WP_Message* msg )

if(cnt == 1)
{
pData = (struct Flash_Sector*)private_malloc(rangeCount * sizeof(struct Flash_Sector));
pData = (struct Flash_Sector*)malloc(rangeCount * sizeof(struct Flash_Sector));

if(pData == NULL)
{
Expand Down Expand Up @@ -1582,12 +1582,12 @@ bool Loader_Engine::Monitor_FlashSectorMap( WP_Message* msg )

ReplyToCommand(msg, true, false, (void*)pData, rangeCount * sizeof (struct Flash_Sector) );

private_free(pData);
free(pData);

return true;
}

#if defined(BIG_ENDIAN)
#if defined(NETMF_TARGET_BIG_ENDIAN)

UINT32 Loader_Engine::SwapEndianPattern( UINT8* &buffer, UINT32 size, UINT32 count )
{
Expand Down
2 changes: 1 addition & 1 deletion Application/TinyBooter/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ struct Loader_Engine
bool Monitor_SignatureKeyUpdate( WP_Message* msg );
bool EnumerateAndLaunch ( );

#if defined(BIG_ENDIAN)
#if defined(NETMF_TARGET_BIG_ENDIAN)
public:
void SwapDebuggingValue ( UINT8* &msg, UINT32 size );
void SwapEndian ( WP_Message* msg, void* ptr, int size, bool fReply );
Expand Down
4 changes: 2 additions & 2 deletions Application/TinyBooter/ConfigurationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void ConfigurationSectorManager::WriteConfiguration( UINT32 writeOffset, BYTE *d
// Copy the whole block to a buffer, for NonXIP or need to erase block
if ((eraseWrite) || (!m_fSupportsXIP))
{
configurationInBytes =(BYTE*)private_malloc(writeLengthInBytes);
configurationInBytes =(BYTE*)malloc(writeLengthInBytes);

// load data to the local buffer.
if (configurationInBytes)
Expand All @@ -154,7 +154,7 @@ void ConfigurationSectorManager::WriteConfiguration( UINT32 writeOffset, BYTE *d
// rewrite from the start of block
m_device->Write( m_cfgPhysicalAddress, writeLengthInBytes, configurationInBytes, FALSE );

private_free(configurationInBytes);
free(configurationInBytes);


}
Expand Down
2 changes: 1 addition & 1 deletion Application/TinyBooter/CryptoInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ bool CryptoState::VerifySignature( UINT32 keyIndex )
}

// free RAM buffer
private_free(g_ConfigBuffer);
free(g_ConfigBuffer);
g_ConfigBuffer = NULL;

return fRet;
Expand Down
11 changes: 0 additions & 11 deletions Application/TinyBooter/TinyBooter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,11 @@ Loader_Engine g_eng;

//--//

HAL_DECLARE_CUSTOM_HEAP( SimpleHeap_Allocate, SimpleHeap_Release, SimpleHeap_ReAllocate );

//--//

void ApplicationEntryPoint()
{
INT32 timeout = 20000; // 20 second timeout
bool enterBootMode = false;

// crypto API needs to allocate memory. Initialize simple heap for it.
UINT8* BaseAddress;
UINT32 SizeInBytes;

HeapLocation ( BaseAddress, SizeInBytes );
SimpleHeap_Initialize( BaseAddress, SizeInBytes );

g_eng.Initialize( HalSystemConfig.DebuggerPorts[ 0 ] );

// internal reset and stop check
Expand Down
2 changes: 0 additions & 2 deletions Application/TinyBooter/TinyBooterDecompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ typedef unsigned char UINT8;

int LZ77_Decompress( UINT8* inBuf, int inSize, UINT8* outBuf, int outSize );

HAL_DECLARE_NULL_HEAP();

typedef void (*APP_ENTRY_POINT)();

extern "C"
Expand Down
8 changes: 4 additions & 4 deletions CLR/Core/CLR_RT_HeapBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ HRESULT CLR_RT_HeapBlock::LoadFromReference( CLR_RT_HeapBlock& ref )
else if(size == 1) { first = ((CLR_UINT8 *)src)[ 0 ]; }
else { first = ((CLR_UINT16*)src)[ 0 ]; }

#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)
((CLR_UINT32*)&NumericByRef())[ 0 ] = first;
((CLR_UINT32*)&NumericByRef())[ 1 ] = second;
#else
Expand All @@ -403,7 +403,7 @@ HRESULT CLR_RT_HeapBlock::LoadFromReference( CLR_RT_HeapBlock& ref )
((CLR_UINT32*)&NumericByRef())[ 0 ] = second;
((CLR_UINT32*)&NumericByRef())[ 1 ] = first;
}
#endif //BIG_ENDIAN
#endif //NETMF_TARGET_BIG_ENDIAN

TINYCLR_SET_AND_LEAVE(S_OK);
}
Expand Down Expand Up @@ -531,7 +531,7 @@ HRESULT CLR_RT_HeapBlock::StoreToReference( CLR_RT_HeapBlock& ref, int size )
}
}

#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)
CLR_UINT32 first = ((CLR_UINT32*)&obj->NumericByRef())[ 0 ];
CLR_UINT32 second = ((CLR_UINT32*)&obj->NumericByRef())[ 1 ];
#else
Expand All @@ -548,7 +548,7 @@ HRESULT CLR_RT_HeapBlock::StoreToReference( CLR_RT_HeapBlock& ref, int size )
first = ((CLR_UINT32*)&obj->NumericByRef())[ 1 ];
second = ((CLR_UINT32*)&obj->NumericByRef())[ 0 ];
}
#endif //BIG_ENDIAN
#endif //NETMF_TARGET_BIG_ENDIAN

if (sizeArray == 4) { ((CLR_UINT32*)dst)[ 0 ] = (CLR_UINT32)first; }
else if(sizeArray == 8) { ((CLR_UINT32*)dst)[ 0 ] = (CLR_UINT32)first; ((CLR_UINT32*)dst)[ 1 ] = (CLR_UINT32)second; }
Expand Down
2 changes: 1 addition & 1 deletion CLR/Core/CLR_RT_HeapBlock_Array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ HRESULT CLR_RT_HeapBlock_Array::IndexOf( CLR_RT_HeapBlock_Array* array, CLR_RT_H

while(true)
{
#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)
if(memcmp( data, &matchPtr->NumericByRef(), sizeElem ) == 0)
{
index = pos;
Expand Down
2 changes: 0 additions & 2 deletions CLR/Core/CLR_RT_Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ static int s_PreHeapInitIndex = 0;

////////////////////////////////////////////////////////////

HAL_DECLARE_CUSTOM_HEAP( CLR_RT_Memory::Allocate, CLR_RT_Memory::Release, CLR_RT_Memory::ReAllocate );

//--//
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Umm, hold on a sec... This is defining the managed heap APIs. The HAL_DECLARE_CUSTOM_HEAP creates a set of private_xxx APis that are inlined wrappers around the methods listed in the macro. While the entire approach to using a macro like this is dubious at best, we don't want to eliminate the functionality as intended here. The use here is intended to be the managed heap which has lots of internal requirements and assumptions for the collector to work properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you entirely sure about that?!
The name refers to custom heap.
I have build this without this code and it went fine.
I have loaded the image on real hardware a run a test app. Creating and destroying objects. Checked the managed memory going up and down a seeing the GC kicking on. I admit it wasn't nothing fancy or exhaustive but it proved that the managed heap was working.


void CLR_RT_Memory::Reset()
Expand Down
2 changes: 1 addition & 1 deletion CLR/Core/Execution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3067,7 +3067,7 @@ void CLR_RT_ExecutionEngine::StopOnBreakpoint( CLR_DBG_Commands::Debugging_Execu

if(m_breakpointsActiveNum == 1)
{
#if defined(BIG_ENDIAN)
#if defined(NETMF_TARGET_BIG_ENDIAN)
static CLR_DBG_Commands::Debugging_Execution_BreakpointDef s_breakpoint;
CLR_UINT8* data;

Expand Down
2 changes: 1 addition & 1 deletion CLR/Core/Serialization/BinaryFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1635,7 +1635,7 @@ HRESULT CLR_RT_BinaryFormatter::State::AdvanceToTheNextElement()
{
TINYCLR_CHECK_HRESULT(m_parent->ReadBits( val, bits ));

#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)
memcpy( ptr, &val, size );
#else
memcpy( ptr, ((unsigned char*)&val)+(sizeof(val)-size), size );
Expand Down
Loading