1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | #if HAVE_CONFIG_H1 |
16 | #include "config.h" |
17 | #endif |
18 | |
19 | #include <rtems/system.h> |
20 | #include <rtems/score/address.h> |
21 | #include <rtems/score/chain.h> |
22 | #include <rtems/score/object.h> |
23 | #if defined(RTEMS_MULTIPROCESSING) |
24 | #include <rtems/score/objectmp.h> |
25 | #endif |
26 | #include <rtems/score/thread.h> |
27 | #include <rtems/score/wkspace.h> |
28 | #include <rtems/score/sysstate.h> |
29 | #include <rtems/score/isr.h> |
30 | |
31 | #include <string.h> /* for memcpy() */ |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | void _Objects_Extend_information( |
46 | Objects_Information *information |
47 | ) |
48 | { |
49 | Objects_Control *the_object; |
50 | Chain_Control Inactive; |
51 | uint32_t block_count; |
52 | uint32_t block; |
53 | uint32_t index_base; |
54 | uint32_t minimum_index; |
55 | uint32_t index; |
56 | uint32_t maximum; |
57 | size_t block_size; |
58 | void *new_object_block; |
59 | bool_Bool do_extend; |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | do_extend = true1; |
66 | minimum_index = _Objects_Get_index( information->minimum_id ); |
67 | index_base = minimum_index; |
68 | block = 0; |
69 | |
70 | |
71 | if ( information->object_blocks == NULL((void*)0) ) |
| 1 | Assuming pointer value is null |
|
| |
72 | block_count = 0; |
73 | else { |
74 | block_count = information->maximum / information->allocation_size; |
75 | |
76 | for ( ; block < block_count; block++ ) { |
77 | if ( information->object_blocks[ block ] == NULL((void*)0) ) { |
78 | do_extend = false0; |
79 | break; |
80 | } else |
81 | index_base += information->allocation_size; |
82 | } |
83 | } |
84 | |
85 | maximum = (uint32_t) information->maximum + information->allocation_size; |
86 | |
87 | |
88 | |
89 | |
90 | |
91 | |
92 | if ( maximum > OBJECTS_ID_FINAL_INDEX(0xffffU) ) { |
| |
93 | return; |
94 | } |
95 | |
96 | |
97 | |
98 | |
99 | |
100 | block_size = information->allocation_size * information->size; |
101 | if ( information->auto_extend ) { |
| |
102 | new_object_block = _Workspace_Allocate( block_size ); |
103 | if ( !new_object_block ) |
104 | return; |
105 | } else { |
106 | new_object_block = _Workspace_Allocate_or_fatal_error( block_size ); |
107 | } |
108 | |
109 | |
110 | |
111 | |
112 | if ( do_extend ) { |
| |
113 | ISR_Level level; |
114 | void **object_blocks; |
115 | uint32_t *inactive_per_block; |
116 | Objects_Control **local_table; |
117 | void *old_tables; |
118 | size_t block_size; |
119 | |
120 | |
121 | |
122 | |
123 | |
124 | |
125 | |
126 | |
127 | |
128 | |
129 | |
130 | |
131 | |
132 | |
133 | |
134 | |
135 | |
136 | |
137 | |
138 | |
139 | |
140 | block_count++; |
141 | |
142 | |
143 | |
144 | |
145 | block_size = block_count * |
146 | (sizeof(void *) + sizeof(uint32_t) + sizeof(Objects_Name *)) + |
147 | ((maximum + minimum_index) * sizeof(Objects_Control *)); |
148 | object_blocks = (void**) _Workspace_Allocate( block_size ); |
149 | |
150 | if ( !object_blocks ) { |
| |
151 | _Workspace_Free( new_object_block ); |
152 | return; |
153 | } |
154 | |
155 | |
156 | |
157 | |
158 | inactive_per_block = (uint32_t *) _Addresses_Add_offset( |
159 | object_blocks, block_count * sizeof(void*) ); |
160 | local_table = (Objects_Control **) _Addresses_Add_offset( |
161 | inactive_per_block, block_count * sizeof(uint32_t) ); |
162 | |
163 | |
164 | |
165 | |
166 | |
167 | block_count--; |
168 | |
169 | if ( information->maximum > minimum_index ) { |
| |
170 | |
171 | |
172 | |
173 | |
174 | |
175 | |
176 | memcpy( object_blocks, |
| 8 | Null pointer passed as an argument to a 'nonnull' parameter |
|
177 | information->object_blocks, |
178 | block_count * sizeof(void*) ); |
179 | memcpy( inactive_per_block, |
180 | information->inactive_per_block, |
181 | block_count * sizeof(uint32_t) ); |
182 | memcpy( local_table, |
183 | information->local_table, |
184 | (information->maximum + minimum_index) * sizeof(Objects_Control *) ); |
185 | } else { |
186 | |
187 | |
188 | |
189 | |
190 | for ( index = 0; index < minimum_index; index++ ) { |
191 | local_table[ index ] = NULL((void*)0); |
192 | } |
193 | } |
194 | |
195 | |
196 | |
197 | |
198 | object_blocks[block_count] = NULL((void*)0); |
199 | inactive_per_block[block_count] = 0; |
200 | |
201 | for ( index=index_base ; |
202 | index < ( information->allocation_size + index_base ); |
203 | index++ ) { |
204 | local_table[ index ] = NULL((void*)0); |
205 | } |
206 | |
207 | _ISR_Disable( level )do { (level) = sparc_disable_interrupts(); asm volatile("" :: : "memory"); } while (0); |
208 | |
209 | old_tables = information->object_blocks; |
210 | |
211 | information->object_blocks = object_blocks; |
212 | information->inactive_per_block = inactive_per_block; |
213 | information->local_table = local_table; |
214 | information->maximum = (Objects_Maximum) maximum; |
215 | information->maximum_id = _Objects_Build_id( |
216 | information->the_api, |
217 | information->the_class, |
218 | _Objects_Local_node((uint16_t)1), |
219 | information->maximum |
220 | ); |
221 | |
222 | _ISR_Enable( level )do { asm volatile("" ::: "memory"); sparc_enable_interrupts( level ); } while (0); |
223 | |
224 | if ( old_tables ) |
225 | _Workspace_Free( old_tables ); |
226 | |
227 | block_count++; |
228 | } |
229 | |
230 | |
231 | |
232 | |
233 | information->object_blocks[ block ] = new_object_block; |
234 | |
235 | |
236 | |
237 | |
238 | _Chain_Initialize( |
239 | &Inactive, |
240 | information->object_blocks[ block ], |
241 | information->allocation_size, |
242 | information->size |
243 | ); |
244 | |
245 | |
246 | |
247 | |
248 | index = index_base; |
249 | |
250 | while ((the_object = (Objects_Control *) _Chain_Get( &Inactive )) != NULL((void*)0) ) { |
251 | |
252 | the_object->id = _Objects_Build_id( |
253 | information->the_api, |
254 | information->the_class, |
255 | _Objects_Local_node((uint16_t)1), |
256 | index |
257 | ); |
258 | |
259 | _Chain_Append( &information->Inactive, &the_object->Node ); |
260 | |
261 | index++; |
262 | } |
263 | |
264 | information->inactive_per_block[ block ] = information->allocation_size; |
265 | information->inactive = |
266 | (Objects_Maximum)(information->inactive + information->allocation_size); |
267 | } |