1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** ThreadX Component                                                     */
17 /**                                                                       */
18 /**   Module Manager                                                      */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 #define TX_SOURCE_CODE
24 
25 #include "tx_api.h"
26 #include "tx_initialize.h"
27 #include "tx_mutex.h"
28 #include "tx_thread.h"
29 #include "tx_byte_pool.h"
30 #include "txm_module.h"
31 #include "txm_module_manager_util.h"
32 
33 
34 /**************************************************************************/
35 /*                                                                        */
36 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _txm_module_manager_in_place_load                   PORTABLE C      */
39 /*                                                           6.1          */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    Scott Larson, Microsoft Corporation                                 */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This function ensures the code-related parts of the module preamble */
47 /*    are valid and calls _txm_module_manager_internal_load to load the   */
48 /*    data and prepare the module for execution.                          */
49 /*                                                                        */
50 /*  INPUT                                                                 */
51 /*                                                                        */
52 /*    module_instance                   Module instance pointer           */
53 /*    module_name                       Module name pointer               */
54 /*    module_location                   Module code location              */
55 /*                                                                        */
56 /*  OUTPUT                                                                */
57 /*                                                                        */
58 /*    status                            Completion status                 */
59 /*                                                                        */
60 /*  CALLS                                                                 */
61 /*                                                                        */
62 /*    _txm_module_manager_internal_load Load data and prepare module for  */
63 /*                                        execution                       */
64 /*                                                                        */
65 /*  CALLED BY                                                             */
66 /*                                                                        */
67 /*    Application code                                                    */
68 /*                                                                        */
69 /*  RELEASE HISTORY                                                       */
70 /*                                                                        */
71 /*    DATE              NAME                      DESCRIPTION             */
72 /*                                                                        */
73 /*  09-30-2020      Scott Larson            Initial Version 6.1           */
74 /*                                                                        */
75 /**************************************************************************/
_txm_module_manager_in_place_load(TXM_MODULE_INSTANCE * module_instance,CHAR * module_name,VOID * module_location)76 UINT  _txm_module_manager_in_place_load(TXM_MODULE_INSTANCE *module_instance, CHAR *module_name, VOID *module_location)
77 {
78 
79 TXM_MODULE_PREAMBLE     *module_preamble;
80 ULONG                   code_size;
81 ULONG                   code_alignment;
82 ULONG                   code_allocation_size_ignored;
83 UINT                    status;
84 
85 
86     /* Pickup the module's information.  */
87     module_preamble =  (TXM_MODULE_PREAMBLE *) module_location;
88 
89     /* Pickup the basic module sizes.  */
90     code_size =  module_preamble -> txm_module_preamble_code_size;
91 
92     /* Check for valid sizes.  */
93     if (code_size == 0)
94     {
95 
96         /* Invalid module preamble.  */
97         return(TXM_MODULE_INVALID);
98     }
99 
100     /* Get the amount of the bytes we need to allocate for the module's code
101        as well as the required alignment. Note that because this is an in-place
102        load, we only want the code alignment so we can check it.  */
103     status =  _txm_module_manager_util_code_allocation_size_and_alignment_get(module_preamble, &code_alignment, &code_allocation_size_ignored);
104     if (status != TX_SUCCESS)
105     {
106 
107         /* Math overflow error occurred.  */
108         return(status);
109     }
110 
111     /* Since this is an in-place load, check the alignment of the module's instruction area (code).  */
112     TXM_MODULE_MANAGER_CHECK_CODE_ALIGNMENT(module_location, code_alignment)
113 
114     /* Now load the module in-place.  */
115     status =  _txm_module_manager_internal_load(module_instance, module_name, module_location,
116                                                 code_size, TX_NULL, 0);
117 
118     /* Return status.  */
119     return(status);
120 }
121