Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
...
#define TX_SOURCE_CODE
#include "txm_module.h"
#include "txm_module_manager_util.h"
...
...
_txm_module_manager_object_memory_check(TXM_MODULE_INSTANCE *, ULONG, ULONG)
...
...
_txm_module_manager_created_object_check(TXM_MODULE_INSTANCE *, void *)
...
...
_txm_module_manager_object_size_check(ULONG, ULONG)
...
...
_txm_module_manager_object_name_compare(CHAR *, UINT, CHAR *)
...
_txm_module_manager_util_code_allocation_size_and_alignment_get(TXM_MODULE_PREAMBLE *, ULONG *, ULONG *)
Files
loading...
CodeScopeSTM32 Libraries and Samplesthreadxcommon_modules/module_manager/src/txm_module_manager_util.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ ... /**************************************************************************/ /**************************************************************************/ /** */ /** ThreadX Component */ /** */ /** Module Manager */ /** */... /**************************************************************************/ /**************************************************************************/ /* Include necessary system files. */ #define TX_SOURCE_CODE #include "txm_module.h" #include "txm_module_manager_util.h" ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _txm_module_manager_object_memory_check PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Scott Larson, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function checks if the object is inside a module's object pool */ /* or, if it's a privileged module, inside the module's data area. */ /* */ /* INPUT */ /* */ /* module_instance Module instance that the object */ /* belongs to */ /* object_ptr Pointer to object to check */ /* object_size Size of the object to check */ /* */ /* OUTPUT */ /* */ /* status Whether the object resides in a */ /* valid location */ /* */ /* CALLS */ /* */ /* None */ /* */ /* CALLED BY */ /* */ /* _txm_module_manager_kernel_dispatch Kernel dispatch function */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 09-30-2020 Scott Larson Initial Version 6.1 */ /* */... /**************************************************************************/ UINT _txm_module_manager_object_memory_check(TXM_MODULE_INSTANCE *module_instance, ALIGN_TYPE object_ptr, ULONG object_size) { /* Is the object pointer from the module manager's object pool? */ if ((_txm_module_manager_object_pool_created == TX_TRUE) && (object_ptr >= (ALIGN_TYPE) _txm_module_manager_object_pool.tx_byte_pool_start) && ((object_ptr+object_size) <= (ALIGN_TYPE) (_txm_module_manager_object_pool.tx_byte_pool_start + _txm_module_manager_object_pool.tx_byte_pool_size))) { /* Object is from manager object pool. */ return(TX_SUCCESS); }if ((_txm_module_manager_object_pool_created == TX_TRUE) && (object_ptr >= (ALIGN_TYPE) _txm_module_manager_object_pool.tx_byte_pool_start) && ((object_ptr+object_size) <= (ALIGN_TYPE) (_txm_module_manager_object_pool.tx_byte_pool_start + _txm_module_manager_object_pool.tx_byte_pool_size))) { ... } /* If memory protection is not required, check if object is in module data. */ else if (!(module_instance -> txm_module_instance_property_flags & TXM_MODULE_MEMORY_PROTECTION)) { if ((object_ptr >= (ALIGN_TYPE) module_instance -> txm_module_instance_data_start) && ((object_ptr+object_size) <= (ALIGN_TYPE) module_instance -> txm_module_instance_data_end)) { /* Object is from the local module memory. */ return(TX_SUCCESS); }if ((object_ptr >= (ALIGN_TYPE) module_instance -> txm_module_instance_data_start) && ((object_ptr+object_size) <= (ALIGN_TYPE) module_instance -> txm_module_instance_data_end)) { ... } }else if (!(module_instance -> txm_module_instance_property_flags & TXM_MODULE_MEMORY_PROTECTION)) { ... } /* Object is from invalid memory. */ return(TXM_MODULE_INVALID_MEMORY); }{ ... } ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _txm_module_manager_created_object_check PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Scott Larson, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This functions checks if the specified object was created by the */ /* specified module */ /* */ /* INPUT */ /* */ /* module_instance The module instance to check */ /* object_ptr The object to check */ /* */ /* OUTPUT */ /* */ /* status Whether the module created the */ /* object */ /* */ /* CALLS */ /* */ /* None */ /* */ /* CALLED BY */ /* */ /* txm_module_manager*_stop Module manager stop functions */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 09-30-2020 Scott Larson Initial Version 6.1 */ /* */... /**************************************************************************/ UCHAR _txm_module_manager_created_object_check(TXM_MODULE_INSTANCE *module_instance, VOID *object_ptr) { TXM_MODULE_ALLOCATED_OBJECT *allocated_object_ptr; /* Determine if the socket control block is inside the module. */ if ( (((CHAR *) object_ptr) >= ((CHAR *) module_instance -> txm_module_instance_data_start)) && (((CHAR *) object_ptr) < ((CHAR *) module_instance -> txm_module_instance_data_end))) { return TX_TRUE; }if ((((CHAR *) object_ptr) >= ((CHAR *) module_instance -> txm_module_instance_data_start)) && (((CHAR *) object_ptr) < ((CHAR *) module_instance -> txm_module_instance_data_end))) { ... } /* Determine if this object control block was allocated by this module instance. */ else if (_txm_module_manager_object_pool_created) { /* Determine if the current object is from the pool of dynamically allocated objects. */ if ((((UCHAR *) object_ptr) >= _txm_module_manager_object_pool.tx_byte_pool_start) && (((UCHAR *) object_ptr) < (_txm_module_manager_object_pool.tx_byte_pool_start + _txm_module_manager_object_pool.tx_byte_pool_size))) { /* Pickup object pointer. */ allocated_object_ptr = (TXM_MODULE_ALLOCATED_OBJECT *) object_ptr; /* Move back to get the header information. */ allocated_object_ptr--; /* Now determine if this object belongs to this module. */ if (allocated_object_ptr -> txm_module_allocated_object_module_instance == module_instance) { return TX_TRUE; }if (allocated_object_ptr -> txm_module_allocated_object_module_instance == module_instance) { ... } }if ((((UCHAR *) object_ptr) >= _txm_module_manager_object_pool.tx_byte_pool_start) && (((UCHAR *) object_ptr) < (_txm_module_manager_object_pool.tx_byte_pool_start + _txm_module_manager_object_pool.tx_byte_pool_size))) { ... } }else if (_txm_module_manager_object_pool_created) { ... } return TX_FALSE; }{ ... } ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _txm_module_manager_object_size_check PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Scott Larson, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function checks if the specified object's size matches what is */ /* inside the object pool. */ /* */ /* INPUT */ /* */ /* object_ptr Pointer to object to check */ /* object_size Size of the object to check */ /* */ /* OUTPUT */ /* */ /* status Whether the object's size matches */ /* what's inside the object pool */ /* */ /* CALLS */ /* */ /* None */ /* */ /* CALLED BY */ /* */ /* _txm_module_manager_kernel_dispatch Kernel dispatch function */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 09-30-2020 Scott Larson Initial Version 6.1 */ /* */... /**************************************************************************/ UINT _txm_module_manager_object_size_check(ALIGN_TYPE object_ptr, ULONG object_size) { TXM_MODULE_ALLOCATED_OBJECT *module_allocated_object_ptr; UINT return_value; /* Pickup the allocated object pointer. */ module_allocated_object_ptr = ((TXM_MODULE_ALLOCATED_OBJECT *) object_ptr) - 1; /* Does the allocated memory match the expected object size? */ if (module_allocated_object_ptr -> txm_module_object_size == object_size) return_value = TX_SUCCESS; else return_value = TXM_MODULE_INVALID_MEMORY; return(return_value); }{ ... } ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _txm_module_manager_name_compare PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Scott Larson, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function compares the specified object names. */ /* */ /* INPUT */ /* */ /* search_name String pointer to the object's */ /* name being searched for */ /* search_name_length Length of search_name */ /* object_name String pointer to an object's name*/ /* to compare the search name to */ /* */ /* OUTPUT */ /* */ /* status Whether the names are equal */ /* */ /* CALLS */ /* */ /* None */ /* */ /* CALLED BY */ /* */ /* *_object_pointer_get Kernel dispatch function */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 09-30-2020 Scott Larson Initial Version 6.1 */ /* */... /**************************************************************************/ UINT _txm_module_manager_object_name_compare(CHAR *search_name, UINT search_name_length, CHAR *object_name) { CHAR search_name_char; CHAR object_name_char; /* Is the object name null? Note that the search name has already been checked by the caller. *//* ... */ if (object_name == TX_NULL) { /* The strings can't match. */ return(TX_FALSE); }if (object_name == TX_NULL) { ... } /* Loop through the names. */ while (1) { /* Get the current characters from each name. */ search_name_char = *search_name; object_name_char = *object_name; /* Check for match. */ if (search_name_char == object_name_char) { /* Are they null-terminators? */ if (search_name_char == '\0') { /* The strings match. */ return(TX_TRUE); }if (search_name_char == '\0') { ... } }if (search_name_char == object_name_char) { ... } else { /* The strings don't match. */ return(TX_FALSE); }else { ... } /* Are we at the end of the search name? */ if (search_name_length == 0) { /* The strings don't match. */ return(TX_FALSE); }if (search_name_length == 0) { ... } /* Move to next character. */ search_name++; object_name++; search_name_length--; }while (1) { ... } }{ ... } ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _txm_module_manager_util_code_allocation_size_and_alignment_get */ /* PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Scott Larson, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function returns the required alignment and allocation size */ /* for a module's code area. */ /* */ /* INPUT */ /* */ /* module_preamble Preamble of module to return code */ /* values for */ /* code_alignment_dest Address to return code alignment */ /* code_allocation_size_desk Address to return code allocation */ /* size */ /* */ /* OUTPUT */ /* */ /* status Success if no math overflow */ /* occurred during calculation */ /* */ /* CALLS */ /* */ /* None */ /* */ /* CALLED BY */ /* */ /* txm_module_manager_*_load Module load functions */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 09-30-2020 Scott Larson Initial Version 6.1 */ /* */... /**************************************************************************/ UINT _txm_module_manager_util_code_allocation_size_and_alignment_get(TXM_MODULE_PREAMBLE *module_preamble, ULONG *code_alignment_dest, ULONG *code_allocation_size_dest) { ULONG code_size; ULONG code_alignment; ULONG data_size_ignored; ULONG data_alignment_ignored; /* Pickup the module code size. */ code_size = module_preamble -> txm_module_preamble_code_size; /* Adjust the size of the module elements to be aligned to the default alignment. */ TXM_MODULE_MANAGER_UTIL_MATH_ADD_ULONG(code_size, TXM_MODULE_CODE_ALIGNMENT, code_size); code_size = ((code_size - 1)/TXM_MODULE_CODE_ALIGNMENT) * TXM_MODULE_CODE_ALIGNMENT; /* Setup the default code and data alignments. */ code_alignment = (ULONG) TXM_MODULE_CODE_ALIGNMENT; /* Get the port-specific alignment for the code size. Note we only want code so we pass 'null' values for data. */ data_size_ignored = 1; data_alignment_ignored = 1; TXM_MODULE_MANAGER_ALIGNMENT_ADJUST(module_preamble, code_size, code_alignment, data_size_ignored, data_alignment_ignored) /* Calculate the code memory allocation size. */ TXM_MODULE_MANAGER_UTIL_MATH_ADD_ULONG(code_size, code_alignment, *code_allocation_size_dest); /* Write the alignment result into the caller's destination address. */ *code_alignment_dest = code_alignment; /* Return success. */ return(TX_SUCCESS); }{ ... }