param & param_shmem: enable locking

We need to protect access to the param_values array. This is dynamically
allocated and resized (utarray_reserve() calls realloc). If some thread
was iterating the array while another was resizing the array, the first one
would iterate on a freed array, thus accessing invalid memory.

On NuttX this could lead to hardfaults in rare conditions.

Unfortunately we need to initialize the semaphore on startup, by calling
sem_init(). This adds a param_init() method called by every board/config
that uses the params (at least I think I've found all of them)
This commit is contained in:
Beat Küng
2017-02-17 11:27:08 +01:00
committed by Lorenz Meier
parent fa3a6b890c
commit df8f0da70c
22 changed files with 106 additions and 23 deletions
@@ -70,6 +70,7 @@
#include <systemlib/cpuload.h>
#include <systemlib/perf_counter.h>
#include <systemlib/param/param.h>
#if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE)
#include <systemlib/systemlib.h>
@@ -194,6 +195,8 @@ __EXPORT int board_app_initialize(uintptr_t arg)
/* configure the high-resolution time/callout interface */
hrt_init();
param_init();
/* configure the DMA allocator */
dma_alloc_init();
@@ -72,6 +72,7 @@
#include <systemlib/err.h>
#include <systemlib/hardfault_log.h>
#include <systemlib/systemlib.h>
#include <systemlib/param/param.h>
# if defined(FLASH_BASED_PARAMS)
# include <systemlib/flashparams/flashfs.h>
@@ -173,6 +174,8 @@ __EXPORT int board_app_initialize(uintptr_t arg)
/* configure the high-resolution time/callout interface */
hrt_init();
param_init();
/* configure CPU load estimation */
#ifdef CONFIG_SCHED_INSTRUMENTATION
cpuload_initialize_once();
+3
View File
@@ -79,6 +79,7 @@
#include <systemlib/hardfault_log.h>
#include <systemlib/systemlib.h>
#include <systemlib/param/param.h>
/****************************************************************************
* Pre-Processor Definitions
@@ -242,6 +243,8 @@ __EXPORT int board_app_initialize(uintptr_t arg)
/* configure the high-resolution time/callout interface */
hrt_init();
param_init();
/* configure the DMA allocator */
if (board_dma_alloc_init() < 0) {
@@ -71,6 +71,7 @@
#include <systemlib/err.h>
#include <systemlib/hardfault_log.h>
#include <systemlib/systemlib.h>
#include <systemlib/param/param.h>
/****************************************************************************
* Pre-Processor Definitions
@@ -164,6 +165,8 @@ __EXPORT int board_app_initialize(uintptr_t arg)
/* configure the high-resolution time/callout interface */
hrt_init();
param_init();
/* configure CPU load estimation */
#ifdef CONFIG_SCHED_INSTRUMENTATION
cpuload_initialize_once();
+3
View File
@@ -69,6 +69,7 @@
#include <drivers/drv_led.h>
#include <systemlib/cpuload.h>
#include <systemlib/param/param.h>
#if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE)
#include <systemlib/systemlib.h>
@@ -179,6 +180,8 @@ __EXPORT int board_app_initialize(uintptr_t arg)
/* configure the high-resolution time/callout interface */
hrt_init();
param_init();
/* set up the serial DMA polling */
static struct hrt_call serial_dma_call;
struct timespec ts;
@@ -79,6 +79,7 @@
#include <systemlib/hardfault_log.h>
#include <systemlib/systemlib.h>
#include <systemlib/param/param.h>
/****************************************************************************
* Pre-Processor Definitions
@@ -228,6 +229,8 @@ __EXPORT int board_app_initialize(uintptr_t arg)
hrt_init();
param_init();
/* configure the DMA allocator */
if (board_dma_alloc_init() < 0) {
@@ -72,6 +72,7 @@
#include <systemlib/cpuload.h>
#include <systemlib/perf_counter.h>
#include <systemlib/param/param.h>
/****************************************************************************
* Pre-Processor Definitions
@@ -165,6 +166,8 @@ __EXPORT int board_app_initialize(uintptr_t arg)
/* configure the high-resolution time/callout interface */
hrt_init();
param_init();
/* configure CPU load estimation */
#ifdef CONFIG_SCHED_INSTRUMENTATION
cpuload_initialize_once();
@@ -69,6 +69,7 @@
#include <drivers/drv_led.h>
#include <systemlib/cpuload.h>
#include <systemlib/param/param.h>
#if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE)
#include <systemlib/systemlib.h>
@@ -172,6 +173,8 @@ __EXPORT int board_app_initialize(uintptr_t arg)
/* configure the high-resolution time/callout interface */
hrt_init();
param_init();
/* set up the serial DMA polling */
static struct hrt_call serial_dma_call;
struct timespec ts;
@@ -69,6 +69,7 @@
#include <drivers/drv_led.h>
#include <systemlib/cpuload.h>
#include <systemlib/param/param.h>
#if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE)
#include <systemlib/systemlib.h>
@@ -173,6 +174,8 @@ __EXPORT int board_app_initialize(uintptr_t arg)
/* configure the high-resolution time/callout interface */
hrt_init();
param_init();
/* set up the serial DMA polling */
static struct hrt_call serial_dma_call;
struct timespec ts;
@@ -69,6 +69,7 @@
#include <drivers/drv_led.h>
#include <systemlib/cpuload.h>
#include <systemlib/param/param.h>
/****************************************************************************
* Pre-Processor Definitions
@@ -189,6 +190,8 @@ __EXPORT int board_app_initialize(uintptr_t arg)
/* configure the high-resolution time/callout interface */
hrt_init();
param_init();
/* configure CPU load estimation */
#ifdef CONFIG_SCHED_INSTRUMENTATION
cpuload_initialize_once();
@@ -79,6 +79,7 @@
#include <systemlib/hardfault_log.h>
#include <systemlib/systemlib.h>
#include <systemlib/param/param.h>
/****************************************************************************
* Pre-Processor Definitions
@@ -237,6 +238,8 @@ __EXPORT int board_app_initialize(uintptr_t arg)
/* configure the high-resolution time/callout interface */
hrt_init();
param_init();
/* configure the DMA allocator */
if (board_dma_alloc_init() < 0) {
@@ -80,6 +80,7 @@
#include <systemlib/hardfault_log.h>
#include <systemlib/systemlib.h>
#include <systemlib/param/param.h>
/****************************************************************************
* Pre-Processor Definitions
@@ -250,6 +251,8 @@ __EXPORT int board_app_initialize(uintptr_t arg)
/* configure the high-resolution time/callout interface */
hrt_init();
param_init();
/* configure the DMA allocator */
if (board_dma_alloc_init() < 0) {
@@ -80,6 +80,7 @@
#include <systemlib/hardfault_log.h>
#include <systemlib/systemlib.h>
#include <systemlib/param/param.h>
/****************************************************************************
* Pre-Processor Definitions
@@ -266,6 +267,8 @@ __EXPORT int board_app_initialize(uintptr_t arg)
/* configure the high-resolution time/callout interface */
hrt_init();
param_init();
/* configure the DMA allocator */
if (board_dma_alloc_init() < 0) {
@@ -80,6 +80,7 @@
#include <systemlib/hardfault_log.h>
#include <systemlib/systemlib.h>
#include <systemlib/param/param.h>
#include "up_internal.h"
/****************************************************************************
@@ -311,6 +312,8 @@ __EXPORT int board_app_initialize(uintptr_t arg)
/* configure the high-resolution time/callout interface */
hrt_init();
param_init();
/* configure the DMA allocator */
if (board_dma_alloc_init() < 0) {
@@ -80,6 +80,7 @@
#include <systemlib/hardfault_log.h>
#include <systemlib/systemlib.h>
#include <systemlib/param/param.h>
#include "up_internal.h"
/****************************************************************************
@@ -250,6 +251,8 @@ __EXPORT int board_app_initialize(uintptr_t arg)
/* configure the high-resolution time/callout interface */
hrt_init();
param_init();
/* configure the DMA allocator */
if (board_dma_alloc_init() < 0) {
@@ -69,6 +69,7 @@
#include <drivers/drv_led.h>
#include <systemlib/cpuload.h>
#include <systemlib/param/param.h>
#if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE)
#include <systemlib/systemlib.h>
@@ -165,6 +166,8 @@ __EXPORT int board_app_initialize(uintptr_t arg)
/* configure the high-resolution time/callout interface */
hrt_init();
param_init();
/* set up the serial DMA polling */
static struct hrt_call serial_dma_call;
struct timespec ts;
+3
View File
@@ -72,6 +72,7 @@
#include <systemlib/err.h>
#include <systemlib/hardfault_log.h>
#include <systemlib/systemlib.h>
#include <systemlib/param/param.h>
# if defined(FLASH_BASED_PARAMS)
# include <systemlib/flashparams/flashfs.h>
@@ -200,6 +201,8 @@ __EXPORT int board_app_initialize(uintptr_t arg)
/* configure the high-resolution time/callout interface */
hrt_init();
param_init();
/* configure the DMA allocator */
if (board_dma_alloc_init() < 0) {