source: rtems/cpukit/score/src/wkspace.c @ d7c3883

4.115
Last change on this file since d7c3883 was 8249054, checked in by Sebastian Huber <sebastian.huber@…>, on 02/16/11 at 07:37:35

2011-02-16 Sebastian Huber <sebastian.huber@…>

  • score/src/wkspace.c: Removed NULL pointer check from _Workspace_Free().
  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*
2 *  Workspace Handler
3 *
4 *  COPYRIGHT (c) 1989-2009.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <rtems/system.h>
19#include <rtems/config.h>
20#include <rtems/score/wkspace.h>
21#include <rtems/score/interr.h>
22
23#include <string.h>  /* for memset */
24
25/* #define DEBUG_WORKSPACE */
26#if defined(DEBUG_WORKSPACE)
27  #include <rtems/bspIo.h>
28#endif
29
30/*
31 *  _Workspace_Handler_initialization
32 */
33void _Workspace_Handler_initialization(void)
34{
35  uintptr_t memory_available = 0;
36  void *starting_address = Configuration.work_space_start;
37  uintptr_t size = Configuration.work_space_size;
38
39  if ( Configuration.do_zero_of_workspace )
40   memset( starting_address, 0, size );
41
42  memory_available = _Heap_Initialize(
43    &_Workspace_Area,
44    starting_address,
45    size,
46    CPU_HEAP_ALIGNMENT
47  );
48
49  if ( memory_available == 0 )
50    _Internal_error_Occurred(
51      INTERNAL_ERROR_CORE,
52      true,
53      INTERNAL_ERROR_TOO_LITTLE_WORKSPACE
54    );
55}
56
57/*
58 *  _Workspace_Allocate
59 */
60void *_Workspace_Allocate(
61  size_t   size
62)
63{
64  void *memory;
65
66  memory = _Heap_Allocate( &_Workspace_Area, size );
67  #if defined(DEBUG_WORKSPACE)
68    printk(
69      "Workspace_Allocate(%d) from %p/%p -> %p\n",
70      size,
71      __builtin_return_address( 0 ),
72      __builtin_return_address( 1 ),
73      memory
74    );
75  #endif
76  return memory;
77}
78
79/*
80 *  _Workspace_Free
81 */
82void _Workspace_Free(
83  void *block
84)
85{
86  #if defined(DEBUG_WORKSPACE)
87    printk(
88      "Workspace_Free(%p) from %p/%p\n",
89      block,
90      __builtin_return_address( 0 ),
91      __builtin_return_address( 1 )
92    );
93  #endif
94  _Heap_Free( &_Workspace_Area, block );
95}
96
97/*
98 *  _Workspace_Allocate_or_fatal_error
99 */
100void *_Workspace_Allocate_or_fatal_error(
101  size_t      size
102)
103{
104  void *memory;
105
106  memory = _Heap_Allocate( &_Workspace_Area, size );
107  #if defined(DEBUG_WORKSPACE)
108    printk(
109      "Workspace_Allocate_or_fatal_error(%d) from %p/%p -> %p\n",
110      size,
111      __builtin_return_address( 0 ),
112      __builtin_return_address( 1 ),
113      memory
114    );
115  #endif
116
117  if ( memory == NULL )
118    _Internal_error_Occurred(
119      INTERNAL_ERROR_CORE,
120      true,
121      INTERNAL_ERROR_WORKSPACE_ALLOCATION
122    );
123
124  return memory;
125}
Note: See TracBrowser for help on using the repository browser.