source: rtems/cpukit/score/src/apimutex.c @ 1506658c

5
Last change on this file since 1506658c was ba3b6fd, checked in by Josh Oguin <josh.oguin@…>, on 10/28/14 at 16:38:54

apimutex.c: Add _Assert for NULL pointer access

CodeSonar? detects a possible NULL deference here. But it should never
occur in tested code. Memory for the API Mutexes is reserved by confdefs.h
and are all preallocated when the class of objects is initialized.
Allocating a single instance should never fail.

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/**
2 * @file
3 *
4 * @brief Initialization and Allocation for API Mutex Handler
5 *
6 * @ingroup ScoreAPIMutex
7 */
8
9/*
10 *  COPYRIGHT (c) 1989-2007.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.org/license/LICENSE.
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <rtems/score/apimutex.h>
23#include <rtems/score/coremuteximpl.h>
24#include <rtems/score/objectimpl.h>
25
26static Objects_Information _API_Mutex_Information;
27
28void _API_Mutex_Initialization(
29  uint32_t maximum_mutexes
30)
31{
32  _Objects_Initialize_information(
33    &_API_Mutex_Information,     /* object information table */
34    OBJECTS_INTERNAL_API,        /* object API */
35    OBJECTS_INTERNAL_MUTEXES,    /* object class */
36    maximum_mutexes,             /* maximum objects of this class */
37    sizeof( API_Mutex_Control ), /* size of this object's control block */
38    false,                       /* true if the name is a string */
39    0                            /* maximum length of an object name */
40#if defined(RTEMS_MULTIPROCESSING)
41    ,
42    true,                        /* true if this is a global object class */
43    NULL                         /* Proxy extraction support callout */
44#endif
45  );
46}
47
48void _API_Mutex_Allocate(
49  API_Mutex_Control **the_mutex
50)
51{
52  API_Mutex_Control *mutex;
53
54  CORE_mutex_Attributes attr =  {
55    CORE_MUTEX_NESTING_ACQUIRES,
56    false,
57    CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT,
58    0
59  };
60
61  mutex = (API_Mutex_Control *)
62    _Objects_Allocate_unprotected( &_API_Mutex_Information );
63
64  _Assert( mutex != NULL );
65
66  _CORE_mutex_Initialize( &mutex->Mutex, NULL, &attr, false );
67
68  _Objects_Open_u32( &_API_Mutex_Information, &mutex->Object, 1 );
69
70  *the_mutex = mutex;
71}
Note: See TracBrowser for help on using the repository browser.