source: rtems/cpukit/rtems/src/regioncreate.c @ 71689a07

Last change on this file since 71689a07 was 71689a07, checked in by Sebastian Huber <sebastian.huber@…>, on 09/30/20 at 14:22:04

rtems: Canonicalize name and id checks

Check the name followed by the id check in all create directives.

Compare pointers against NULL. Fix formatting.

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup ClassicRegion Regions
5 *
6 * @brief rtems_region_create
7 */
8
9/*
10 *  COPYRIGHT (c) 1989-1999.
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#ifdef HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <rtems/rtems/regionimpl.h>
23#include <rtems/rtems/attrimpl.h>
24#include <rtems/rtems/support.h>
25#include <rtems/score/apimutex.h>
26#include <rtems/score/threadqimpl.h>
27#include <rtems/sysinit.h>
28
29rtems_status_code rtems_region_create(
30  rtems_name          name,
31  void               *starting_address,
32  uintptr_t           length,
33  uintptr_t           page_size,
34  rtems_attribute     attribute_set,
35  rtems_id           *id
36)
37{
38  rtems_status_code  return_status;
39  Region_Control    *the_region;
40
41  if ( !rtems_is_name_valid( name ) ) {
42    return RTEMS_INVALID_NAME;
43  }
44
45  if ( id == NULL ) {
46    return RTEMS_INVALID_ADDRESS;
47  }
48
49  if ( starting_address == NULL ) {
50    return RTEMS_INVALID_ADDRESS;
51  }
52
53  the_region = _Region_Allocate();
54
55    if ( !the_region )
56      return_status = RTEMS_TOO_MANY;
57
58    else {
59      _Thread_queue_Object_initialize( &the_region->Wait_queue );
60
61      if ( _Attributes_Is_priority( attribute_set ) ) {
62        the_region->wait_operations = &_Thread_queue_Operations_priority;
63      } else {
64        the_region->wait_operations = &_Thread_queue_Operations_FIFO;
65      }
66
67      the_region->maximum_segment_size = _Heap_Initialize(
68        &the_region->Memory, starting_address, length, page_size
69      );
70
71      if ( !the_region->maximum_segment_size ) {
72        _Region_Free( the_region );
73        return_status = RTEMS_INVALID_SIZE;
74      } else {
75        the_region->attribute_set = attribute_set;
76
77        _Objects_Open(
78          &_Region_Information,
79          &the_region->Object,
80          (Objects_Name) name
81        );
82
83        *id = the_region->Object.id;
84        return_status = RTEMS_SUCCESSFUL;
85      }
86    }
87
88  _Objects_Allocator_unlock();
89
90  return return_status;
91}
92
93static void _Region_Manager_initialization( void )
94{
95  _Objects_Initialize_information( &_Region_Information );
96}
97
98RTEMS_SYSINIT_ITEM(
99  _Region_Manager_initialization,
100  RTEMS_SYSINIT_CLASSIC_REGION,
101  RTEMS_SYSINIT_ORDER_MIDDLE
102);
Note: See TracBrowser for help on using the repository browser.