Updated Keil MDK documentation to note RTOS and TCP default dependency. Fix for inline error due to tracking code being available too broadly. Use current branch for makedistsmall.sh.

pull/6466/head
David Garske 2023-06-16 12:01:30 -07:00 committed by Lealem Amedie
parent a56fe30c2c
commit 255aa774f2
3 changed files with 85 additions and 78 deletions

View File

@ -16,6 +16,8 @@ This CMSIS pack contains the wolfCrypt and wolfSSL (TLS) libraries including tes
2) Expand "wolfSSL" and check the boxes for wolfCrypt CORE and wolfSSL CORE.
3) If running the wolfCrypt test or any of the TLS examples check those as well.
Note: By default the pack's user_settings.h assumes the CMSIS RTOS v2 and Keil TCP packs are also installed. See below for how to change these settings (`MDK_CONF_THREAD` and `MDK_CONF_NETWORK`).
If the wolfSSL::wolfSSL pack isn't showing:
1) Project -> Manage -> "Select Software Packs"
2) Make sure wolfSSL:wolfSSL is selected to "latest"
@ -30,6 +32,7 @@ If the wolfSSL::wolfSSL pack isn't showing:
3) Configure math library (`MDK_CONF_MATH`). Default 0=SP Math all (sp_int.c)
4) Configure MPU (`MDK_CONF_MPU`): If not STM32, use 0 for none.
5) Configure the RTOS (`MDK_CONF_THREAD`): By default 15 = "CMSIS RTOSv2". For bare-metal use 0. For FreeRTOS use 1.
6) Configure the TCP stack (`MDK_CONF_NETWORK`). By default uses Keil TCP `WOLFSSL_KEIL_TCP_NET`. Use 0 for none or 2 for user io callbacks.
6) For wolfCrypt only (no TLS) add `#define WOLFCRYPT_ONLY` (resolves GetCA errors)
7) Increase stack/heap (if needed). This is typically in the startup.s, but for RTX is in the `RTX_Config.h`. For CMSIS RTOSv2 stack is set in `osThreadAttr_t` on call to `osThreadNew`.

View File

@ -9,6 +9,7 @@
if [ "$1" == "keep" ]; then KEEP="yes"; else KEEP="no"; fi
WOLFSSL_TEMPDIR=$(mktemp -d) || exit $?
WOLFSSL_BRANCH=$(git symbolic-ref --short HEAD)
function cleanup_on_exit() {
if [ "$KEEP" == "no" ];
@ -34,7 +35,7 @@ fi
echo "Setting up work directory..."
git clone -q -n --shared . "$WOLFSSL_TEMPDIR" || exit $?
pushd "$WOLFSSL_TEMPDIR" >/dev/null || exit $?
git checkout -q master || exit $?
git checkout -q "$WOLFSSL_BRANCH"
# cleanup example directories
echo "Removing files not needed..."

View File

@ -24,8 +24,6 @@
#ifndef WOLFSSL_MEM_TRACK_H
#define WOLFSSL_MEM_TRACK_H
#if defined(USE_WOLFSSL_MEMORY) && !defined(WOLFSSL_STATIC_MEMORY)
/* The memory tracker overrides the wolfSSL memory callback system and uses a
* static to track the total, peak and currently allocated bytes.
*
@ -61,7 +59,9 @@
*/
#include "wolfssl/wolfcrypt/settings.h"
#include "wolfssl/wolfcrypt/types.h"
#include "wolfssl/wolfcrypt/logging.h"
#include "wolfssl/wolfcrypt/error-crypt.h"
#include "wolfssl/wolfcrypt/memory.h"
#if defined(WOLFSSL_TRACK_MEMORY) || defined(HAVE_STACK_SIZE) || \
@ -77,13 +77,14 @@
#endif
#endif
#if defined(WOLFSSL_TRACK_MEMORY)
#define DO_MEM_STATS
#if (defined(__linux__) && !defined(WOLFSSL_LINUXKM)) || defined(__MACH__)
#define DO_MEM_LIST
#endif
#endif
/* Track Memory */
#if defined(WOLFSSL_TRACK_MEMORY) && defined(USE_WOLFSSL_MEMORY) && \
!defined(WOLFSSL_STATIC_MEMORY)
#define DO_MEM_STATS
#if (defined(__linux__) && !defined(WOLFSSL_LINUXKM)) || defined(__MACH__)
#define DO_MEM_LIST
#endif
typedef struct memoryStats {
long totalAllocs; /* number of allocations */
@ -93,12 +94,12 @@ typedef struct memoryStats {
long currentBytes; /* total current bytes in use */
#ifdef WOLFSSL_TRACK_MEMORY_VERBOSE
long peakAllocsTripOdometer; /* peak number of concurrent allocations,
* subject to reset by
* wolfCrypt_heap_peak_checkpoint()
*/
* subject to reset by
* wolfCrypt_heap_peak_checkpoint()
*/
long peakBytesTripOdometer; /* peak concurrent bytes, subject to reset
* by wolfCrypt_heap_peak_checkpoint()
*/
* by wolfCrypt_heap_peak_checkpoint()
*/
#endif
} memoryStats;
@ -119,7 +120,8 @@ typedef struct memHint {
typedef struct memoryTrack {
union {
memHint hint;
byte alignit[sizeof(memHint) + ((16-1) & ~(16-1))]; /* make sure we have strong alignment */
/* make sure we have strong alignment */
byte alignit[sizeof(memHint) + ((16-1) & ~(16-1))];
} u;
} memoryTrack;
@ -132,7 +134,7 @@ typedef struct memoryList {
} memoryList;
#endif
#if defined(WOLFSSL_TRACK_MEMORY)
static memoryStats ourMemStats;
#ifdef DO_MEM_LIST
@ -140,7 +142,6 @@ static memoryStats ourMemStats;
static memoryList ourMemList;
static pthread_mutex_t memLock = PTHREAD_MUTEX_INITIALIZER;
#endif
#endif
#ifdef WOLFSSL_DEBUG_MEMORY
static WC_INLINE void* TrackMalloc(size_t sz, const char* func,
@ -169,7 +170,8 @@ static WC_INLINE void* TrackMalloc(size_t sz)
#ifdef WOLFSSL_DEBUG_MEMORY
#ifdef WOLFSSL_DEBUG_MEMORY_PRINT
wc_mem_printf("Alloc: %p -> %u at %s:%d\n", header->thisMemory, (word32)sz, func, line);
wc_mem_printf("Alloc: %p -> %u at %s:%d\n",
header->thisMemory, (word32)sz, func, line);
#else
(void)func;
(void)line;
@ -180,18 +182,23 @@ static WC_INLINE void* TrackMalloc(size_t sz)
ourMemStats.totalAllocs++;
ourMemStats.totalBytes += sz;
ourMemStats.currentBytes += sz;
#ifdef WOLFSSL_TRACK_MEMORY_VERBOSE
if (ourMemStats.peakAllocsTripOdometer < ourMemStats.totalAllocs -
ourMemStats.totalDeallocs) {
ourMemStats.peakAllocsTripOdometer = ourMemStats.totalAllocs -
ourMemStats.totalDeallocs;
}
if (ourMemStats.peakBytesTripOdometer < ourMemStats.currentBytes)
#endif
{
#ifdef WOLFSSL_TRACK_MEMORY_VERBOSE
if (ourMemStats.peakAllocsTripOdometer < ourMemStats.totalAllocs - ourMemStats.totalDeallocs)
ourMemStats.peakAllocsTripOdometer = ourMemStats.totalAllocs - ourMemStats.totalDeallocs;
if (ourMemStats.peakBytesTripOdometer < ourMemStats.currentBytes) {
ourMemStats.peakBytesTripOdometer = ourMemStats.currentBytes;
#endif
if (ourMemStats.currentBytes > ourMemStats.peakBytes)
ourMemStats.peakBytes = ourMemStats.currentBytes;
#ifdef WOLFSSL_TRACK_MEMORY_VERBOSE
}
#endif
#endif
#endif /* DO_MEM_STATS */
#ifdef DO_MEM_LIST
if (pthread_mutex_lock(&memLock) == 0) {
#ifdef WOLFSSL_DEBUG_MEMORY
@ -214,7 +221,7 @@ static WC_INLINE void* TrackMalloc(size_t sz)
pthread_mutex_unlock(&memLock);
}
#endif
#endif /* DO_MEM_LIST */
return header->thisMemory;
}
@ -332,7 +339,6 @@ static WC_INLINE void* TrackRealloc(void* ptr, size_t sz)
return ret;
}
#ifdef WOLFSSL_TRACK_MEMORY
static wolfSSL_Malloc_cb mfDefault = NULL;
static wolfSSL_Free_cb ffDefault = NULL;
static wolfSSL_Realloc_cb rfDefault = NULL;
@ -353,27 +359,26 @@ static WC_INLINE int InitMemoryTracker(void)
#ifdef DO_MEM_LIST
if (pthread_mutex_lock(&memLock) == 0)
#endif
{
#endif
#ifdef DO_MEM_STATS
ourMemStats.totalAllocs = 0;
ourMemStats.totalDeallocs = 0;
ourMemStats.totalBytes = 0;
ourMemStats.peakBytes = 0;
ourMemStats.currentBytes = 0;
#ifdef WOLFSSL_TRACK_MEMORY_VERBOSE
ourMemStats.peakAllocsTripOdometer = 0;
ourMemStats.peakBytesTripOdometer = 0;
#endif
#endif /* DO_MEM_STATS */
#ifdef DO_MEM_STATS
ourMemStats.totalAllocs = 0;
ourMemStats.totalDeallocs = 0;
ourMemStats.totalBytes = 0;
ourMemStats.peakBytes = 0;
ourMemStats.currentBytes = 0;
#ifdef WOLFSSL_TRACK_MEMORY_VERBOSE
ourMemStats.peakAllocsTripOdometer = 0;
ourMemStats.peakBytesTripOdometer = 0;
#endif
#endif
#ifdef DO_MEM_LIST
XMEMSET(&ourMemList, 0, sizeof(ourMemList));
#ifdef DO_MEM_LIST
XMEMSET(&ourMemList, 0, sizeof(ourMemList));
pthread_mutex_unlock(&memLock);
pthread_mutex_unlock(&memLock);
#endif
}
#endif
return ret;
}
@ -382,36 +387,38 @@ static WC_INLINE void ShowMemoryTracker(void)
{
#ifdef DO_MEM_LIST
if (pthread_mutex_lock(&memLock) == 0)
#endif
{
#endif
#ifdef DO_MEM_STATS
wc_mem_printf("total Allocs = %9ld\n", ourMemStats.totalAllocs);
wc_mem_printf("total Deallocs = %9ld\n", ourMemStats.totalDeallocs);
wc_mem_printf("total Bytes = %9ld\n", ourMemStats.totalBytes);
wc_mem_printf("peak Bytes = %9ld\n", ourMemStats.peakBytes);
wc_mem_printf("current Bytes = %9ld\n", ourMemStats.currentBytes);
#endif
#ifdef DO_MEM_STATS
wc_mem_printf("total Allocs = %9ld\n", ourMemStats.totalAllocs);
wc_mem_printf("total Deallocs = %9ld\n", ourMemStats.totalDeallocs);
wc_mem_printf("total Bytes = %9ld\n", ourMemStats.totalBytes);
wc_mem_printf("peak Bytes = %9ld\n", ourMemStats.peakBytes);
wc_mem_printf("current Bytes = %9ld\n", ourMemStats.currentBytes);
#endif
#ifdef DO_MEM_LIST
if (ourMemList.count > 0) {
/* print list of allocations */
memHint* header;
for (header = ourMemList.head; header != NULL; header = header->next) {
#ifdef WOLFSSL_DEBUG_MEMORY
wc_mem_printf("Leak: Ptr %p, Size %u, Func %s, Line %d\n",
(byte*)header + sizeof(memHint), (unsigned int)header->thisSize,
header->func, header->line);
#else
wc_mem_printf("Leak: Ptr %p, Size %u\n",
(byte*)header + sizeof(memHint), (unsigned int)header->thisSize);
#endif
#ifdef DO_MEM_LIST
if (ourMemList.count > 0) {
/* print list of allocations */
memHint* header;
for (header = ourMemList.head;
header != NULL;
header = header->next) {
#ifdef WOLFSSL_DEBUG_MEMORY
wc_mem_printf("Leak: Ptr %p, Size %u, Func %s, Line %d\n",
(byte*)header + sizeof(memHint),
(unsigned int)header->thisSize, header->func, header->line);
#else
wc_mem_printf("Leak: Ptr %p, Size %u\n",
(byte*)header + sizeof(memHint),
(unsigned int)header->thisSize);
#endif
}
}
}
pthread_mutex_unlock(&memLock);
pthread_mutex_unlock(&memLock);
#endif
}
#endif
}
static WC_INLINE int CleanupMemoryTracker(void)
@ -419,9 +426,8 @@ static WC_INLINE int CleanupMemoryTracker(void)
/* restore default allocators */
return wolfSSL_SetAllocators(mfDefault, ffDefault, rfDefault);
}
#endif /* WOLFSSL_TRACK_MEMORY */
#endif /* USE_WOLFSSL_MEMORY && !WOLFSSL_STATIC_MEMORY */
#endif /* WOLFSSL_TRACK_MEMORY && USE_WOLFSSL_MEMORY && \
!WOLFSSL_STATIC_MEMORY */
#ifdef HAVE_STACK_SIZE
@ -432,10 +438,6 @@ static WC_INLINE int CleanupMemoryTracker(void)
#include <sched.h>
#include <unistd.h>
#include <wolfssl/wolfcrypt/types.h>
#include <wolfssl/wolfcrypt/logging.h>
#include <wolfssl/wolfcrypt/error-crypt.h>
typedef void* (*thread_func)(void* args);
#define STACK_CHECK_VAL 0x01
@ -557,7 +559,8 @@ int StackSizeHWMReset(void)
_ret = StackSizeHWMReset(); \
if ((max >= 0) && (HWM > (ssize_t)(max))) { \
wc_mem_printf( \
" relative stack usage at %s L%d exceeds designated max %ld bytes.\n", \
" relative stack usage at %s L%d exceeds designated " \
"max %ld bytes.\n", \
__FILE__, __LINE__, (long int)(max)); \
_ret = -1; \
} \
@ -720,7 +723,8 @@ static WC_INLINE int StackSizeCheck_launch(struct func_args* args,
return 0;
}
static WC_INLINE int StackSizeCheck_reap(pthread_t threadId, void *stack_context)
static WC_INLINE int StackSizeCheck_reap(pthread_t threadId,
void *stack_context)
{
struct stack_size_debug_context *shim_args =
(struct stack_size_debug_context *)stack_context;
@ -755,7 +759,6 @@ static WC_INLINE int StackSizeCheck_reap(pthread_t threadId, void *stack_context
return (int)((size_t)status);
}
#endif /* HAVE_STACK_SIZE */