mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-19 00:43:34 +08:00
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:
@@ -46,7 +46,7 @@
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include "systemlib/param/param.h"
|
||||
#include <systemlib/param/param.h>
|
||||
#include "hrt_work.h"
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include "px4_time.h"
|
||||
@@ -76,6 +76,7 @@ void init_once()
|
||||
work_queues_init();
|
||||
hrt_work_queue_init();
|
||||
hrt_init();
|
||||
param_init();
|
||||
|
||||
#ifdef CONFIG_SHMEM
|
||||
PX4_DEBUG("Syncing params to shared memory\n");
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <semaphore.h>
|
||||
#include "systemlib/param/param.h"
|
||||
#include <systemlib/param/param.h>
|
||||
#include "hrt_work.h"
|
||||
#include "px4_log.h"
|
||||
|
||||
@@ -106,6 +106,7 @@ void init_once(void)
|
||||
work_queues_init();
|
||||
hrt_work_queue_init();
|
||||
hrt_init();
|
||||
param_init();
|
||||
|
||||
/* Shared memory param sync*/
|
||||
init_params();
|
||||
|
||||
Reference in New Issue
Block a user