1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief RTEMS Return Region Segment |
---|
5 | * @ingroup ClassicRegion |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2007. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.com/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #ifdef RTEMS_REGION_SHRED_ON_FREE |
---|
22 | #include <string.h> |
---|
23 | |
---|
24 | #ifndef RTEMS_REGION_FREE_SHRED_PATTERN |
---|
25 | #define RTEMS_REGION_FREE_SHRED_PATTERN 0x00 |
---|
26 | #endif |
---|
27 | #endif |
---|
28 | |
---|
29 | #include <rtems/system.h> |
---|
30 | #include <rtems/rtems/status.h> |
---|
31 | #include <rtems/rtems/support.h> |
---|
32 | #include <rtems/rtems/options.h> |
---|
33 | #include <rtems/rtems/regionimpl.h> |
---|
34 | #include <rtems/score/thread.h> |
---|
35 | #include <rtems/score/apimutex.h> |
---|
36 | |
---|
37 | rtems_status_code rtems_region_return_segment( |
---|
38 | rtems_id id, |
---|
39 | void *segment |
---|
40 | ) |
---|
41 | { |
---|
42 | Objects_Locations location; |
---|
43 | rtems_status_code return_status; |
---|
44 | #ifdef RTEMS_REGION_FREE_SHRED_PATTERN |
---|
45 | uint32_t size; |
---|
46 | #endif |
---|
47 | int status; |
---|
48 | register Region_Control *the_region; |
---|
49 | |
---|
50 | _RTEMS_Lock_allocator(); |
---|
51 | |
---|
52 | the_region = _Region_Get( id, &location ); |
---|
53 | switch ( location ) { |
---|
54 | |
---|
55 | case OBJECTS_LOCAL: |
---|
56 | |
---|
57 | _Region_Debug_Walk( the_region, 3 ); |
---|
58 | |
---|
59 | #ifdef RTEMS_REGION_FREE_SHRED_PATTERN |
---|
60 | if ( !_Heap_Size_of_alloc_area( &the_region->Memory, segment, &size ) ) |
---|
61 | return_status = RTEMS_INVALID_ADDRESS; |
---|
62 | else { |
---|
63 | memset( segment, (RTEMS_REGION_FREE_SHRED_PATTERN & 0xFF), size ); |
---|
64 | #endif |
---|
65 | status = _Region_Free_segment( the_region, segment ); |
---|
66 | |
---|
67 | _Region_Debug_Walk( the_region, 4 ); |
---|
68 | |
---|
69 | if ( !status ) |
---|
70 | return_status = RTEMS_INVALID_ADDRESS; |
---|
71 | else { |
---|
72 | the_region->number_of_used_blocks -= 1; |
---|
73 | |
---|
74 | _Region_Process_queue(the_region); /* unlocks allocator */ |
---|
75 | |
---|
76 | return RTEMS_SUCCESSFUL; |
---|
77 | } |
---|
78 | #ifdef RTEMS_REGION_FREE_SHRED_PATTERN |
---|
79 | } |
---|
80 | #endif |
---|
81 | break; |
---|
82 | |
---|
83 | #if defined(RTEMS_MULTIPROCESSING) |
---|
84 | case OBJECTS_REMOTE: /* this error cannot be returned */ |
---|
85 | break; |
---|
86 | #endif |
---|
87 | |
---|
88 | case OBJECTS_ERROR: |
---|
89 | default: |
---|
90 | return_status = RTEMS_INVALID_ID; |
---|
91 | break; |
---|
92 | } |
---|
93 | |
---|
94 | _RTEMS_Unlock_allocator(); |
---|
95 | return return_status; |
---|
96 | } |
---|