From 87c1213e45a8d47f4c8023bc302808c3d34c925b Mon Sep 17 00:00:00 2001 From: rtel Date: Wed, 17 Apr 2019 17:16:04 +0000 Subject: [PATCH] Fix potential memory leak in the Win32 FreeRTOS+TCP network interface initialisation sequence. Introduce portMEMORY_BARRIER() macro to assist with memory access ordering when suspending the scheduler if link time optimization is used. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2649 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- .../WinPCap/NetworkInterface.c | 2 ++ FreeRTOS/Source/include/FreeRTOS.h | 4 +++ FreeRTOS/Source/portable/GCC/RISC-V/portASM.S | 25 +++++++++---------- .../Source/portable/GCC/RISC-V/portmacro.h | 23 ++++++++++++----- FreeRTOS/Source/tasks.c | 1 + 5 files changed, 36 insertions(+), 19 deletions(-) diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/WinPCap/NetworkInterface.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/WinPCap/NetworkInterface.c index e8d12a6a7..78b3bdf80 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/WinPCap/NetworkInterface.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/WinPCap/NetworkInterface.c @@ -389,6 +389,8 @@ uint32_t ulNetMask; { printf( "\nAn error occurred setting the packet filter.\n" ); } + + pcap_freecode( &xFilterCode ); } /* Create the buffers used to pass packets between the FreeRTOS simulator diff --git a/FreeRTOS/Source/include/FreeRTOS.h b/FreeRTOS/Source/include/FreeRTOS.h index 7ae621993..e6b62d5a0 100644 --- a/FreeRTOS/Source/include/FreeRTOS.h +++ b/FreeRTOS/Source/include/FreeRTOS.h @@ -241,6 +241,10 @@ extern "C" { #define configASSERT_DEFINED 1 #endif +#ifndef portMEMORY_BARRIER + #define portMEMORY_BARRIER() +#endif + /* The timers module relies on xTaskGetSchedulerState(). */ #if configUSE_TIMERS == 1 diff --git a/FreeRTOS/Source/portable/GCC/RISC-V/portASM.S b/FreeRTOS/Source/portable/GCC/RISC-V/portASM.S index 0adde585d..68b6fa607 100644 --- a/FreeRTOS/Source/portable/GCC/RISC-V/portASM.S +++ b/FreeRTOS/Source/portable/GCC/RISC-V/portASM.S @@ -25,19 +25,6 @@ * 1 tab == 4 spaces! */ -#if __riscv_xlen == 64 - #error Not implemented yet - change lw to ld, and sw to sd. - #define portWORD_SIZE 8 - #define store_x sd - #define load_x ld -#elif __riscv_xlen == 32 - #define portWORD_SIZE 4 - #define store_x sw - #define load_x lw -#else - #error Assembler did not define __riscv_xlen -#endif - /* * The FreeRTOS kernel's RISC-V port is split between the the code that is * common across all currently supported RISC-V chips (implementations of the @@ -68,6 +55,18 @@ * registers. * */ +#if __riscv_xlen == 64 + #define portWORD_SIZE 8 + #define store_x sd + #define load_x ld +#elif __riscv_xlen == 32 + #define store_x sw + #define load_x lw + #define portWORD_SIZE 4 +#else + #error Assembler did not define __riscv_xlen +#endif + #include "freertos_risc_v_chip_specific_extensions.h" /* Check the freertos_risc_v_chip_specific_extensions.h and/or command line diff --git a/FreeRTOS/Source/portable/GCC/RISC-V/portmacro.h b/FreeRTOS/Source/portable/GCC/RISC-V/portmacro.h index 670e62f2e..c43cd92e1 100644 --- a/FreeRTOS/Source/portable/GCC/RISC-V/portmacro.h +++ b/FreeRTOS/Source/portable/GCC/RISC-V/portmacro.h @@ -44,14 +44,25 @@ extern "C" { */ /* Type definitions. */ -#define portSTACK_TYPE uint32_t -#define portBASE_TYPE long +#if __riscv_xlen == 64 + #define portSTACK_TYPE uint64_t + #define portBASE_TYPE int64_t + #define portUBASE_TYPE uint64_t + #define portMAX_DELAY ( TickType_t ) 0xffffffffffffffffUL +#elif __riscv_xlen == 32 + #define portSTACK_TYPE uint32_t + #define portBASE_TYPE int32_t + #define portUBASE_TYPE uint32_t + #define portMAX_DELAY ( TickType_t ) 0xffffffffUL +#else + #error Assembler did not define __riscv_xlen +#endif + typedef portSTACK_TYPE StackType_t; -typedef long BaseType_t; -typedef unsigned long UBaseType_t; -typedef uint32_t TickType_t; -#define portMAX_DELAY ( TickType_t ) 0xffffffffUL +typedef portBASE_TYPE BaseType_t; +typedef portUBASE_TYPE UBaseType_t; +typedef portUBASE_TYPE TickType_t; /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do not need to be guarded with a critical section. */ diff --git a/FreeRTOS/Source/tasks.c b/FreeRTOS/Source/tasks.c index 492bf874e..13aaf135c 100644 --- a/FreeRTOS/Source/tasks.c +++ b/FreeRTOS/Source/tasks.c @@ -2104,6 +2104,7 @@ void vTaskSuspendAll( void ) post in the FreeRTOS support forum before reporting this as a bug! - http://goo.gl/wu4acr */ ++uxSchedulerSuspended; + portMEMORY_BARRIER(); } /*----------------------------------------------------------*/ -- 2.39.5