1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Resize RTEMS 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 | #include <rtems/system.h> |
---|
22 | #include <rtems/rtems/status.h> |
---|
23 | #include <rtems/rtems/support.h> |
---|
24 | #include <rtems/score/object.h> |
---|
25 | #include <rtems/rtems/options.h> |
---|
26 | #include <rtems/rtems/region.h> |
---|
27 | #include <rtems/score/states.h> |
---|
28 | #include <rtems/score/thread.h> |
---|
29 | #include <rtems/score/apimutex.h> |
---|
30 | |
---|
31 | rtems_status_code rtems_region_resize_segment( |
---|
32 | rtems_id id, |
---|
33 | void *segment, |
---|
34 | uintptr_t size, |
---|
35 | uintptr_t *old_size |
---|
36 | ) |
---|
37 | { |
---|
38 | uintptr_t avail_size; |
---|
39 | Objects_Locations location; |
---|
40 | uintptr_t osize; |
---|
41 | rtems_status_code return_status; |
---|
42 | Heap_Resize_status status; |
---|
43 | register Region_Control *the_region; |
---|
44 | |
---|
45 | if ( !old_size ) |
---|
46 | return RTEMS_INVALID_ADDRESS; |
---|
47 | |
---|
48 | _RTEMS_Lock_allocator(); |
---|
49 | |
---|
50 | the_region = _Region_Get( id, &location ); |
---|
51 | switch ( location ) { |
---|
52 | |
---|
53 | case OBJECTS_LOCAL: |
---|
54 | |
---|
55 | _Region_Debug_Walk( the_region, 7 ); |
---|
56 | |
---|
57 | status = _Heap_Resize_block( |
---|
58 | &the_region->Memory, |
---|
59 | segment, |
---|
60 | (uint32_t) size, |
---|
61 | &osize, |
---|
62 | &avail_size |
---|
63 | ); |
---|
64 | *old_size = (uint32_t) osize; |
---|
65 | |
---|
66 | _Region_Debug_Walk( the_region, 8 ); |
---|
67 | |
---|
68 | if ( status == HEAP_RESIZE_SUCCESSFUL ) |
---|
69 | _Region_Process_queue( the_region ); /* unlocks allocator */ |
---|
70 | else |
---|
71 | _RTEMS_Unlock_allocator(); |
---|
72 | |
---|
73 | |
---|
74 | if (status == HEAP_RESIZE_SUCCESSFUL) |
---|
75 | return RTEMS_SUCCESSFUL; |
---|
76 | if (status == HEAP_RESIZE_UNSATISFIED) |
---|
77 | return RTEMS_UNSATISFIED; |
---|
78 | return RTEMS_INVALID_ADDRESS; |
---|
79 | break; |
---|
80 | |
---|
81 | #if defined(RTEMS_MULTIPROCESSING) |
---|
82 | case OBJECTS_REMOTE: /* this error cannot be returned */ |
---|
83 | break; |
---|
84 | #endif |
---|
85 | |
---|
86 | case OBJECTS_ERROR: |
---|
87 | default: |
---|
88 | return_status = RTEMS_INVALID_ID; |
---|
89 | break; |
---|
90 | } |
---|
91 | |
---|
92 | _RTEMS_Unlock_allocator(); |
---|
93 | return return_status; |
---|
94 | } |
---|