Enable mbedTLS dynamic memory allocation in user mode on Windows (#1373)

* change user mode openthread to enable dynamic memory allocation in mbedtls

* complete merge by adding OPENTHREAD_MULTIPLE_INSTANCE to last file

* remove some extraneous changes that got pulled in accidentally

* fix spacing

* fix crash in existing tests due to this change

* fix x86 build
This commit is contained in:
Jorge Vergara
2017-02-23 22:01:59 -08:00
committed by Jonathan Hui
parent 1587835134
commit f3817e76cf
17 changed files with 77 additions and 10 deletions
+1
View File
@@ -49,6 +49,7 @@
%(PreprocessorDefinitions)
MBEDTLS_CONFIG_FILE="mbedtls-config.h";
OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";
OPENTHREAD_MULTIPLE_INSTANCE;
</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
<UseFullPaths>true</UseFullPaths>
@@ -40,6 +40,7 @@
%(PreprocessorDefinitions);
MBEDTLS_CONFIG_FILE="mbedtls-config.h";
OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";
OPENTHREAD_MULTIPLE_INSTANCE;
</PreprocessorDefinitions>
<AdditionalIncludeDirectories>
%(AdditionalIncludeDirectories);
@@ -40,6 +40,7 @@
%(PreprocessorDefinitions);
MBEDTLS_CONFIG_FILE="mbedtls-config.h";
OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";
OPENTHREAD_MULTIPLE_INSTANCE;
</PreprocessorDefinitions>
<AdditionalIncludeDirectories>
%(AdditionalIncludeDirectories);
@@ -40,6 +40,7 @@
%(PreprocessorDefinitions);
MBEDTLS_CONFIG_FILE="mbedtls-config.h";
OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";
OPENTHREAD_MULTIPLE_INSTANCE;
</PreprocessorDefinitions>
<AdditionalIncludeDirectories>
%(AdditionalIncludeDirectories);
+2 -1
View File
@@ -40,6 +40,7 @@
%(PreprocessorDefinitions);
MBEDTLS_CONFIG_FILE="mbedtls-config.h";
OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";
OPENTHREAD_MULTIPLE_INSTANCE;
</PreprocessorDefinitions>
<AdditionalIncludeDirectories>
%(AdditionalIncludeDirectories);
@@ -210,4 +211,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
@@ -174,9 +174,6 @@
<ClCompile Include="..\..\src\core\thread\network_data_local.cpp">
<Filter>Source Files\thread</Filter>
</ClCompile>
<ClCompile Include="..\..\src\core\thread\network_diag.cpp">
<Filter>Source Files\thread</Filter>
</ClCompile>
<ClCompile Include="..\..\src\core\thread\panid_query_server.cpp">
<Filter>Source Files\thread</Filter>
</ClCompile>
@@ -501,4 +498,4 @@
<Filter>Header Files\common</Filter>
</ClInclude>
</ItemGroup>
</Project>
</Project>
+3 -2
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="openthread.configuration.props" />
<Import Project="openthread.configuration.props" />
<PropertyGroup Label="Globals">
<ProjectGuid>{4111C8BB-D354-4348-AD3C-EB6832E84831}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
@@ -38,7 +38,8 @@
<ClCompile>
<PreprocessorDefinitions>
;%(PreprocessorDefinitions);
MBEDTLS_CONFIG_FILE="mbedtls-config.h"
MBEDTLS_CONFIG_FILE="mbedtls-config.h";
OPENTHREAD_MULTIPLE_INSTANCE;
</PreprocessorDefinitions>
<AdditionalIncludeDirectories>
..\..\include;
+1
View File
@@ -39,6 +39,7 @@
<PreprocessorDefinitions>
%(PreprocessorDefinitions);
OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";
OPENTHREAD_MULTIPLE_INSTANCE;
</PreprocessorDefinitions>
<AdditionalIncludeDirectories>
%(AdditionalIncludeDirectories);
+1
View File
@@ -39,6 +39,7 @@
<PreprocessorDefinitions>
%(PreprocessorDefinitions);
OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";
OPENTHREAD_MULTIPLE_INSTANCE;
</PreprocessorDefinitions>
<AdditionalIncludeDirectories>
%(AdditionalIncludeDirectories);
+1
View File
@@ -39,6 +39,7 @@
<PreprocessorDefinitions>
%(PreprocessorDefinitions);
OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";
OPENTHREAD_MULTIPLE_INSTANCE;
</PreprocessorDefinitions>
<AdditionalIncludeDirectories>
%(AdditionalIncludeDirectories);
+12
View File
@@ -40,6 +40,18 @@
#include <platform/platform.h>
#include <assert.h>
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
void *otPlatCAlloc(size_t aNum, size_t aSize)
{
return calloc(aNum, aSize);
}
void otPlatFree(void *aPtr)
{
free(aPtr);
}
#endif
void otSignalTaskletPending(otInstance *aInstance)
{
(void)aInstance;
+12
View File
@@ -40,6 +40,18 @@
#include <ncp/ncp.h>
#include <platform/platform.h>
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
void *otPlatCAlloc(size_t aNum, size_t aSize)
{
return calloc(aNum, aSize);
}
void otPlatFree(void *aPtr)
{
free(aPtr);
}
#endif
void otSignalTaskletPending(otInstance *aInstance)
{
(void)aInstance;
+2
View File
@@ -33,7 +33,9 @@
#include <crypto/mbedtls.hpp>
#include <string.h>
#ifndef OPENTHREAD_MULTIPLE_INSTANCE
static Thread::Crypto::MbedTls mbedtls;
#endif
/**
* Verifies test vectors from IEEE 802.15.4-2006 Annex C Section C.2.1
+2 -2
View File
@@ -110,7 +110,7 @@ void TestFuzz(uint32_t aSeconds)
#endif
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
uint64_t otInstanceBufferLength = 0;
size_t otInstanceBufferLength = 0;
uint8_t *otInstanceBuffer = NULL;
// Call to query the buffer size
@@ -119,7 +119,7 @@ void TestFuzz(uint32_t aSeconds)
// Call to allocate the buffer
otInstanceBuffer = (uint8_t *)malloc(otInstanceBufferLength);
VerifyOrQuit(otInstanceBuffer != NULL, "Failed to allocate otInstance");
memset(&otInstanceBuffer, 0, otInstanceBufferLength);
memset(otInstanceBuffer, 0, otInstanceBufferLength);
// Initialize Openthread with the buffer
aInstance = otInstanceInit(otInstanceBuffer, &otInstanceBufferLength);
+3 -1
View File
@@ -34,7 +34,9 @@
#include <crypto/hmac_sha256.hpp>
#include <crypto/mbedtls.hpp>
static Thread::Crypto::MbedTls mbedtls;
#ifndef OPENTHREAD_MULTIPLE_INSTANCE
static Thread::Crypto::MbedTls mMbedTls;
#endif
void TestHmacSha256(void)
{
+21
View File
@@ -192,7 +192,23 @@ void TestMessageQueueOtApis(void)
ThreadError error;
otMessage message;
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
size_t otInstanceBufferLength = 0;
uint8_t *otInstanceBuffer = NULL;
// Call to query the buffer size
(void)otInstanceInit(NULL, &otInstanceBufferLength);
// Call to allocate the buffer
otInstanceBuffer = (uint8_t *)malloc(otInstanceBufferLength);
assert(otInstanceBuffer);
// Initialize Openthread with the buffer
instance = otInstanceInit(otInstanceBuffer, &otInstanceBufferLength);
#else
instance = otInstanceInit();
#endif
VerifyOrQuit(instance != NULL, "Failed to get and init an otInstance.\n");
for (int i = 0; i < kNumTestMessages; i++)
@@ -251,6 +267,11 @@ void TestMessageQueueOtApis(void)
// Remove all element and make sure queue is empty
SuccessOrQuit(otMessageQueueDequeue(&queue, msg[2]), "Failed to dequeue a message from otMessageQueue.\n");
VerifyMessageQueueContentUsingOtApi(&queue, 0);
otInstanceFinalize(instance);
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
free(otInstanceBuffer);
#endif
}
#ifdef ENABLE_TEST_MAIN
+12
View File
@@ -81,6 +81,18 @@ bool sDiagMode = false;
extern "C" {
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
void *otPlatCAlloc(size_t aNum, size_t aSize)
{
return calloc(aNum, aSize);
}
void otPlatFree(void *aPtr)
{
free(aPtr);
}
#endif
void otSignalTaskletPending(otInstance *)
{
}