mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 11:56:10 +08:00
sched/signal/sig_initialize.c: Add some checks for allocation failures.
This commit is contained in:
@@ -42,6 +42,8 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <queue.h>
|
#include <queue.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include <nuttx/kmalloc.h>
|
#include <nuttx/kmalloc.h>
|
||||||
|
|
||||||
#include "signal/signal.h"
|
#include "signal/signal.h"
|
||||||
@@ -137,22 +139,24 @@ static sigpendq_t *nxsig_alloc_pendingsignalblock(sq_queue_t *siglist,
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static sigq_t *nxsig_alloc_block(sq_queue_t *siglist, uint16_t nsigs,
|
static FAR sigq_t *nxsig_alloc_block(sq_queue_t *siglist, uint16_t nsigs,
|
||||||
uint8_t sigtype)
|
uint8_t sigtype)
|
||||||
{
|
{
|
||||||
FAR sigq_t *sigqalloc;
|
FAR sigq_t *sigqalloc;
|
||||||
FAR sigq_t *sigq;
|
FAR sigq_t *sigq;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Allocate a block of pending signal actions */
|
/* Allocate a block of pending signal actions. */
|
||||||
|
|
||||||
sigqalloc = (FAR sigq_t *)kmm_malloc((sizeof(sigq_t)) * nsigs);
|
sigqalloc = (FAR sigq_t *)kmm_malloc((sizeof(sigq_t)) * nsigs);
|
||||||
|
if (sigqalloc != NULL)
|
||||||
sigq = sigqalloc;
|
|
||||||
for (i = 0; i < nsigs; i++)
|
|
||||||
{
|
{
|
||||||
sigq->type = sigtype;
|
sigq = sigqalloc;
|
||||||
sq_addlast((FAR sq_entry_t *)sigq++, siglist);
|
for (i = 0; i < nsigs; i++)
|
||||||
|
{
|
||||||
|
sigq->type = sigtype;
|
||||||
|
sq_addlast((FAR sq_entry_t *)sigq++, siglist);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return sigqalloc;
|
return sigqalloc;
|
||||||
@@ -179,11 +183,14 @@ static sigpendq_t *nxsig_alloc_pendingsignalblock(sq_queue_t *siglist,
|
|||||||
sigpendalloc =
|
sigpendalloc =
|
||||||
(FAR sigpendq_t *)kmm_malloc((sizeof(sigpendq_t)) * nsigs);
|
(FAR sigpendq_t *)kmm_malloc((sizeof(sigpendq_t)) * nsigs);
|
||||||
|
|
||||||
sigpend = sigpendalloc;
|
if (sigpendalloc != NULL)
|
||||||
for (i = 0; i < nsigs; i++)
|
|
||||||
{
|
{
|
||||||
sigpend->type = sigtype;
|
sigpend = sigpendalloc;
|
||||||
sq_addlast((FAR sq_entry_t *)sigpend++, siglist);
|
for (i = 0; i < nsigs; i++)
|
||||||
|
{
|
||||||
|
sigpend->type = sigtype;
|
||||||
|
sq_addlast((FAR sq_entry_t *)sigpend++, siglist);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return sigpendalloc;
|
return sigpendalloc;
|
||||||
@@ -217,11 +224,13 @@ void nxsig_initialize(void)
|
|||||||
nxsig_alloc_block(&g_sigpendingaction,
|
nxsig_alloc_block(&g_sigpendingaction,
|
||||||
NUM_PENDING_ACTIONS,
|
NUM_PENDING_ACTIONS,
|
||||||
SIG_ALLOC_FIXED);
|
SIG_ALLOC_FIXED);
|
||||||
|
DEBUGASSERT(g_sigpendingactionalloc != NULL);
|
||||||
|
|
||||||
g_sigpendingirqactionalloc =
|
g_sigpendingirqactionalloc =
|
||||||
nxsig_alloc_block(&g_sigpendingirqaction,
|
nxsig_alloc_block(&g_sigpendingirqaction,
|
||||||
NUM_PENDING_INT_ACTIONS,
|
NUM_PENDING_INT_ACTIONS,
|
||||||
SIG_ALLOC_IRQ);
|
SIG_ALLOC_IRQ);
|
||||||
|
DEBUGASSERT(g_sigpendingirqactionalloc != NULL);
|
||||||
|
|
||||||
nxsig_alloc_actionblock();
|
nxsig_alloc_actionblock();
|
||||||
|
|
||||||
@@ -229,11 +238,13 @@ void nxsig_initialize(void)
|
|||||||
nxsig_alloc_pendingsignalblock(&g_sigpendingsignal,
|
nxsig_alloc_pendingsignalblock(&g_sigpendingsignal,
|
||||||
NUM_SIGNALS_PENDING,
|
NUM_SIGNALS_PENDING,
|
||||||
SIG_ALLOC_FIXED);
|
SIG_ALLOC_FIXED);
|
||||||
|
DEBUGASSERT(g_sigpendingsignalalloc != NULL);
|
||||||
|
|
||||||
g_sigpendingirqsignalalloc =
|
g_sigpendingirqsignalalloc =
|
||||||
nxsig_alloc_pendingsignalblock(&g_sigpendingirqsignal,
|
nxsig_alloc_pendingsignalblock(&g_sigpendingirqsignal,
|
||||||
NUM_INT_SIGNALS_PENDING,
|
NUM_INT_SIGNALS_PENDING,
|
||||||
SIG_ALLOC_IRQ);
|
SIG_ALLOC_IRQ);
|
||||||
|
DEBUGASSERT(g_sigpendingirqsignalalloc != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -255,9 +266,12 @@ void nxsig_alloc_actionblock(void)
|
|||||||
g_sigactionalloc =
|
g_sigactionalloc =
|
||||||
(FAR sigactq_t *)kmm_malloc((sizeof(sigactq_t)) * NUM_SIGNAL_ACTIONS);
|
(FAR sigactq_t *)kmm_malloc((sizeof(sigactq_t)) * NUM_SIGNAL_ACTIONS);
|
||||||
|
|
||||||
sigact = g_sigactionalloc;
|
if (g_sigactionalloc != NULL)
|
||||||
for (i = 0; i < NUM_SIGNAL_ACTIONS; i++)
|
|
||||||
{
|
{
|
||||||
sq_addlast((FAR sq_entry_t *)sigact++, &g_sigfreeaction);
|
sigact = g_sigactionalloc;
|
||||||
|
for (i = 0; i < NUM_SIGNAL_ACTIONS; i++)
|
||||||
|
{
|
||||||
|
sq_addlast((FAR sq_entry_t *)sigact++, &g_sigfreeaction);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ int prctl(int option, ...)
|
|||||||
* pid==0 meaning "this thread")
|
* pid==0 meaning "this thread")
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!pid)
|
if (pid == 0)
|
||||||
{
|
{
|
||||||
tcb = this_task();
|
tcb = this_task();
|
||||||
}
|
}
|
||||||
@@ -109,7 +109,7 @@ int prctl(int option, ...)
|
|||||||
* sched_gettcb()
|
* sched_gettcb()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!tcb)
|
if (tcb == NULL)
|
||||||
{
|
{
|
||||||
serr("ERROR: Pid does not correspond to a task: %d\n", pid);
|
serr("ERROR: Pid does not correspond to a task: %d\n", pid);
|
||||||
errcode = ESRCH;
|
errcode = ESRCH;
|
||||||
@@ -118,7 +118,7 @@ int prctl(int option, ...)
|
|||||||
|
|
||||||
/* A pointer to the task name storage must also be provided */
|
/* A pointer to the task name storage must also be provided */
|
||||||
|
|
||||||
if (!name)
|
if (name == NULL)
|
||||||
{
|
{
|
||||||
serr("ERROR: No name provide\n");
|
serr("ERROR: No name provide\n");
|
||||||
errcode = EFAULT;
|
errcode = EFAULT;
|
||||||
|
|||||||
Reference in New Issue
Block a user