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