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 | #include <rtems/system.h> |
---|
20 | #include <rtems/rtems/status.h> |
---|
21 | #include <rtems/rtems/support.h> |
---|
22 | #include <rtems/score/object.h> |
---|
23 | #include <rtems/rtems/options.h> |
---|
24 | #include <rtems/rtems/region.h> |
---|
25 | #include <rtems/score/states.h> |
---|
26 | #include <rtems/score/thread.h> |
---|
27 | #include <rtems/score/apimutex.h> |
---|
28 | |
---|
29 | /*PAGE |
---|
30 | * |
---|
31 | * rtems_region_resize_segment |
---|
32 | * |
---|
33 | * This directive will try to resize segment to the new size 'size' |
---|
34 | * "in place". |
---|
35 | * |
---|
36 | * Input parameters: |
---|
37 | * id - region id |
---|
38 | * segment - pointer to segment address |
---|
39 | * size - new required size |
---|
40 | * |
---|
41 | * Output parameters: |
---|
42 | * RTEMS_SUCCESSFUL - if successful |
---|
43 | * error code - if unsuccessful |
---|
44 | */ |
---|
45 | |
---|
46 | rtems_status_code rtems_region_resize_segment( |
---|
47 | Objects_Id id, |
---|
48 | void *segment, |
---|
49 | uintptr_t size, |
---|
50 | uintptr_t *old_size |
---|
51 | ) |
---|
52 | { |
---|
53 | uintptr_t avail_size; |
---|
54 | Objects_Locations location; |
---|
55 | uintptr_t osize; |
---|
56 | rtems_status_code return_status = RTEMS_SUCCESSFUL; |
---|
57 | Heap_Resize_status status; |
---|
58 | register Region_Control *the_region; |
---|
59 | |
---|
60 | if ( !old_size ) |
---|
61 | return RTEMS_INVALID_ADDRESS; |
---|
62 | |
---|
63 | _RTEMS_Lock_allocator(); |
---|
64 | |
---|
65 | the_region = _Region_Get( id, &location ); |
---|
66 | switch ( location ) { |
---|
67 | |
---|
68 | case OBJECTS_LOCAL: |
---|
69 | |
---|
70 | _Region_Debug_Walk( the_region, 7 ); |
---|
71 | |
---|
72 | status = _Heap_Resize_block( |
---|
73 | &the_region->Memory, |
---|
74 | segment, |
---|
75 | (uint32_t) size, |
---|
76 | &osize, |
---|
77 | &avail_size |
---|
78 | ); |
---|
79 | *old_size = (uint32_t) osize; |
---|
80 | |
---|
81 | _Region_Debug_Walk( the_region, 8 ); |
---|
82 | |
---|
83 | if ( status == HEAP_RESIZE_SUCCESSFUL && avail_size > 0 ) |
---|
84 | _Region_Process_queue( the_region ); /* unlocks allocator */ |
---|
85 | else |
---|
86 | _RTEMS_Unlock_allocator(); |
---|
87 | |
---|
88 | return |
---|
89 | (status == HEAP_RESIZE_SUCCESSFUL) ? RTEMS_SUCCESSFUL : |
---|
90 | (status == HEAP_RESIZE_UNSATISFIED) ? RTEMS_UNSATISFIED : |
---|
91 | RTEMS_INVALID_ADDRESS; |
---|
92 | break; |
---|
93 | |
---|
94 | #if defined(RTEMS_MULTIPROCESSING) |
---|
95 | case OBJECTS_REMOTE: /* this error cannot be returned */ |
---|
96 | break; |
---|
97 | #endif |
---|
98 | |
---|
99 | case OBJECTS_ERROR: |
---|
100 | return_status = RTEMS_INVALID_ID; |
---|
101 | break; |
---|
102 | } |
---|
103 | |
---|
104 | _RTEMS_Unlock_allocator(); |
---|
105 | return return_status; |
---|
106 | } |
---|