1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** USBX Component                                                        */
16 /**                                                                       */
17 /**   Utility                                                             */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 
23 /**************************************************************************/
24 /*                                                                        */
25 /*  COMPONENT DEFINITION                                   RELEASE        */
26 /*                                                                        */
27 /*    ux_utility.h                                        PORTABLE C      */
28 /*                                                           6.3.0        */
29 /*  AUTHOR                                                                */
30 /*                                                                        */
31 /*    Chaoqiong Xiao, Microsoft Corporation                               */
32 /*                                                                        */
33 /*  DESCRIPTION                                                           */
34 /*                                                                        */
35 /*    This file contains all the header and extern functions used by the  */
36 /*    USBX components that utilize utility functions.                     */
37 /*                                                                        */
38 /*  RELEASE HISTORY                                                       */
39 /*                                                                        */
40 /*    DATE              NAME                      DESCRIPTION             */
41 /*                                                                        */
42 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
43 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
44 /*                                            added timer delete, used UX */
45 /*                                            prefix to refer to TX       */
46 /*                                            symbols instead of using    */
47 /*                                            them directly,              */
48 /*                                            resulting in version 6.1    */
49 /*  01-31-2022     Chaoqiong Xiao           Modified comment(s),          */
50 /*                                            added standalone support,   */
51 /*                                            resulting in version 6.1.10 */
52 /*  04-25-2022     Chaoqiong Xiao           Modified comment(s),          */
53 /*                                            fixed standalone compile,   */
54 /*                                            resulting in version 6.1.11 */
55 /*  07-29-2022     Chaoqiong Xiao           Modified comment(s),          */
56 /*                                            added macros for RTOS calls,*/
57 /*                                            fixed OHCI PRSC issue,      */
58 /*                                            resulting in version 6.1.12 */
59 /*  10-31-2023     Chaoqiong Xiao           Modified comment(s),          */
60 /*                                            refined memory management,  */
61 /*                                            added new function to check */
62 /*                                            parsed size of descriptor,  */
63 /*                                            resulting in version 6.3.0  */
64 /*                                                                        */
65 /**************************************************************************/
66 
67 #ifndef UX_UTILITY_H
68 #define UX_UTILITY_H
69 
70 
71 /* Define Utility component function prototypes.  */
72 
73 VOID             _ux_utility_descriptor_parse(UCHAR * raw_descriptor, UCHAR * descriptor_structure,
74                              UINT descriptor_entries, UCHAR * descriptor);
75 VOID             _ux_utility_descriptor_pack(UCHAR * descriptor, UCHAR * descriptor_structure,
76                              UINT descriptor_entries, UCHAR * raw_descriptor);
77 ULONG            _ux_utility_descriptor_parse_size(UCHAR * descriptor_structure, UINT descriptor_entries, UINT size_align_mask);
78 
79 ULONG            _ux_utility_long_get(UCHAR * address);
80 VOID             _ux_utility_long_put(UCHAR * address, ULONG value);
81 VOID             _ux_utility_long_put_big_endian(UCHAR * address, ULONG value);
82 ULONG            _ux_utility_long_get_big_endian(UCHAR * address);
83 VOID            *_ux_utility_memory_allocate(ULONG memory_alignment,ULONG memory_cache_flag, ULONG memory_size_requested);
84 UINT             _ux_utility_memory_compare(VOID *memory_source, VOID *memory_destination, ULONG length);
85 VOID             _ux_utility_memory_copy(VOID *memory_destination, VOID *memory_source, ULONG length);
86 VOID             _ux_utility_memory_free(VOID *memory);
87 ULONG            _ux_utility_string_length_get(UCHAR *string);
88 UINT             _ux_utility_string_length_check(UCHAR *input_string, UINT *string_length_ptr, UINT max_string_length);
89 UCHAR           *_ux_utility_memory_byte_pool_search(UX_MEMORY_BYTE_POOL *pool_ptr, ULONG memory_size);
90 UINT             _ux_utility_memory_byte_pool_create(UX_MEMORY_BYTE_POOL *pool_ptr, VOID *pool_start, ULONG pool_size);
91 VOID             _ux_utility_memory_set(VOID *destination, UCHAR value, ULONG length);
92 ULONG            _ux_utility_pci_class_scan(ULONG pci_class, ULONG bus_number, ULONG device_number,
93                             ULONG function_number, ULONG *current_bus_number,
94                             ULONG *current_device_number, ULONG *current_function_number);
95 ULONG            _ux_utility_pci_read(ULONG bus_number, ULONG device_number, ULONG function_number,
96                              ULONG offset, UINT read_size);
97 VOID             _ux_utility_pci_write(ULONG bus_number, ULONG device_number, ULONG function_number,
98                              ULONG offset, ULONG value, UINT write_size);
99 VOID            *_ux_utility_physical_address(VOID *virtual_address);
100 VOID             _ux_utility_set_interrupt_handler(UINT irq, VOID (*interrupt_handler)(VOID));
101 ULONG            _ux_utility_short_get(UCHAR * address);
102 ULONG            _ux_utility_short_get_big_endian(UCHAR * address);
103 VOID             _ux_utility_short_put(UCHAR * address, USHORT value);
104 VOID             _ux_utility_short_put_big_endian(UCHAR * address, USHORT value);
105 VOID            *_ux_utility_virtual_address(VOID *physical_address);
106 VOID             _ux_utility_unicode_to_string(UCHAR *source, UCHAR *destination);
107 VOID             _ux_utility_string_to_unicode(UCHAR *source, UCHAR *destination);
108 VOID             _ux_utility_debug_callback_register(VOID (*debug_callback)(UCHAR *, ULONG));
109 VOID             _ux_utility_delay_ms(ULONG ms_wait);
110 
111 #if !defined(UX_STANDALONE)
112 UINT             _ux_utility_mutex_create(UX_MUTEX *mutex, CHAR *mutex_name);
113 UINT             _ux_utility_mutex_delete(UX_MUTEX *mutex);
114 VOID             _ux_utility_mutex_off(UX_MUTEX *mutex);
115 VOID             _ux_utility_mutex_on(UX_MUTEX *mutex);
116 UINT             _ux_utility_semaphore_create(UX_SEMAPHORE *semaphore, CHAR *semaphore_name, UINT initial_count);
117 UINT             _ux_utility_semaphore_delete(UX_SEMAPHORE *semaphore);
118 UINT             _ux_utility_semaphore_get(UX_SEMAPHORE *semaphore, ULONG semaphore_signal);
119 UINT             _ux_utility_semaphore_put(UX_SEMAPHORE *semaphore);
120 UINT             _ux_utility_thread_create(UX_THREAD *thread_ptr, CHAR *name,
121                              VOID (*entry_function)(ULONG), ULONG entry_input,
122                              VOID *stack_start, ULONG stack_size,
123                              UINT priority, UINT preempt_threshold,
124                              ULONG time_slice, UINT auto_start);
125 UINT             _ux_utility_thread_delete(UX_THREAD *thread_ptr);
126 VOID             _ux_utility_thread_relinquish(VOID);
127 UINT             _ux_utility_thread_schedule_other(UINT caller_priority);
128 UINT             _ux_utility_thread_resume(UX_THREAD *thread_ptr);
129 UINT             _ux_utility_thread_sleep(ULONG ticks);
130 UINT             _ux_utility_thread_suspend(UX_THREAD *thread_ptr);
131 UX_THREAD       *_ux_utility_thread_identify(VOID);
132 UINT             _ux_utility_timer_create(UX_TIMER *timer, CHAR *timer_name, VOID (*expiration_function) (ULONG),
133                              ULONG expiration_input, ULONG initial_ticks, ULONG reschedule_ticks,
134                              UINT activation_flag);
135 UINT             _ux_utility_timer_delete(UX_TIMER *timer);
136 UINT             _ux_utility_event_flags_create(UX_EVENT_FLAGS_GROUP*group_ptr, CHAR *name);
137 UINT             _ux_utility_event_flags_delete(UX_EVENT_FLAGS_GROUP*group_ptr);
138 UINT             _ux_utility_event_flags_get(UX_EVENT_FLAGS_GROUP*group_ptr, ULONG requested_flags,
139                                                  UINT get_option, ULONG *actual_flags_ptr, ULONG wait_option);
140 UINT             _ux_utility_event_flags_set(UX_EVENT_FLAGS_GROUP*group_ptr, ULONG flags_to_set,
141                                                  UINT set_option);
142 #endif
143 
144 #ifndef             _ux_utility_interrupt_disable
145 #ifdef TX_API_H
146 #define             _ux_utility_interrupt_disable()             _tx_thread_interrupt_disable()
147 #else
148 extern ALIGN_TYPE   _ux_utility_interrupt_disable(VOID);
149 #endif
150 #else
151 extern ALIGN_TYPE   _ux_utility_interrupt_disable(VOID);
152 #endif
153 
154 #ifndef             _ux_utility_interrupt_restore
155 #ifdef TX_API_H
156 #define             _ux_utility_interrupt_restore(flags)        _tx_thread_interrupt_restore(flags)
157 #else
158 extern VOID         _ux_utility_interrupt_restore(ALIGN_TYPE);
159 #endif
160 #else
161 extern VOID         _ux_utility_interrupt_restore(ALIGN_TYPE);
162 #endif
163 
164 #ifndef             _ux_utility_time_get
165 #ifdef TX_API_H
166 #define             _ux_utility_time_get()                      tx_time_get()
167 #else
168 extern  ULONG       _ux_utility_time_get(VOID);
169 #endif
170 #else
171 extern  ULONG       _ux_utility_time_get(VOID);
172 #endif
173 
174 #ifndef             _ux_utility_time_elapsed
175 #define             _ux_utility_time_elapsed(a,b)          (((b)>=(a)) ? ((b)-(a)) : (0xFFFFFFFFul-(b)+(a)+1))
176 #else
177 extern  ALIGN_TYPE  _ux_utility_time_elapsed(ALIGN_TYPE, ALIGN_TYPE);
178 #endif
179 
180 #if !defined(UX_STANDALONE)
181 #define _ux_system_semaphore_create                             _ux_utility_semaphore_create
182 #define _ux_system_semaphore_create_norc                        _ux_utility_semaphore_create
183 #define _ux_system_semaphore_created(sem)                       ((sem)->tx_semaphore_id != UX_EMPTY)
184 #define _ux_system_semaphore_get                                _ux_utility_semaphore_get
185 #define _ux_system_semaphore_get_norc                           _ux_utility_semaphore_get
186 #define _ux_system_semaphore_waiting(sem)                       ((sem)->tx_semaphore_count != 0)
187 #define _ux_system_semaphore_delete                             _ux_utility_semaphore_delete
188 #define _ux_system_semaphore_put                                _ux_utility_semaphore_put
189 #define _ux_system_thread_create                                _ux_utility_thread_create
190 #define _ux_system_thread_create_norc                           _ux_utility_thread_create
191 #define _ux_system_thread_created(t)                            ((t)->tx_thread_id != UX_EMPTY)
192 #define _ux_system_thread_delete                                _ux_utility_thread_delete
193 #define _ux_system_mutex_create                                 _ux_utility_mutex_create
194 #define _ux_system_mutex_delete                                 _ux_utility_mutex_delete
195 #define _ux_system_mutex_off                                    _ux_utility_mutex_off
196 #define _ux_system_mutex_on                                     _ux_utility_mutex_on
197 #define _ux_system_event_flags_create                           _ux_utility_event_flags_create
198 #define _ux_system_event_flags_created(e)                       ((e)->tx_event_flags_group_id != UX_EMPTY)
199 #define _ux_system_event_flags_delete                           _ux_utility_event_flags_delete
200 #define _ux_system_event_flags_get                              _ux_utility_event_flags_get
201 #define _ux_system_event_flags_set                              _ux_utility_event_flags_set
202 #define _ux_system_event_flags_set_rc                           _ux_utility_event_flags_set
203 #else
204 #define _ux_system_semaphore_create(sem,name,cnt)               (UX_SUCCESS)
205 #define _ux_system_semaphore_create_norc(sem,name,cnt)          do{}while(0)
206 #define _ux_system_semaphore_created(sem)                       (UX_FALSE)
207 #define _ux_system_semaphore_get(sem,opt)                       (UX_SUCCESS)
208 #define _ux_system_semaphore_get_norc(sem,opt)                  do{}while(0)
209 #define _ux_system_semaphore_waiting(sem)                       (UX_FALSE)
210 #define _ux_system_semaphore_delete(sem)                        do{}while(0)
211 #define _ux_system_semaphore_put(sem)                           do{}while(0)
212 #define _ux_system_thread_create(t,name,entry,entry_param,stack,stack_size,priority,preempt_threshold,time_slice,auto_start) (UX_SUCCESS)
213 #define _ux_system_thread_create_norc(t,name,entry,entry_param,stack,stack_size,priority,preempt_threshold,time_slice,auto_start) do{}while(0)
214 #define _ux_system_thread_created(t)                            (UX_FALSE)
215 #define _ux_system_thread_delete(t)                             do{}while(0)
216 #define _ux_system_mutex_create(mutex,name)                     do{}while(0)
217 #define _ux_system_mutex_delete(mutex)                          do{}while(0)
218 #define _ux_system_mutex_off(mutex)                             do{}while(0)
219 #define _ux_system_mutex_on(mutex)                              do{}while(0)
220 #define _ux_system_event_flags_create(g,name)                   (UX_SUCCESS)
221 #define _ux_system_event_flags_created(e)                       (UX_FALSE)
222 #define _ux_system_event_flags_delete(g)                        do{}while(0)
223 #define _ux_system_event_flags_get(g,req,gopt,actual,wopt)      (*actual = 0)
224 #define _ux_system_event_flags_set(g,flags,option)              do{(void)flags;}while(0)
225 #define _ux_system_event_flags_set_rc(g,flags,option)           (UX_SUCCESS)
226 #endif
227 
228 #if !defined(UX_DEVICE_STANDALONE)
229 #define _ux_device_thread_create                                _ux_utility_thread_create
230 #define _ux_device_thread_delete                                _ux_utility_thread_delete
231 #define _ux_device_thread_entry(t)                              ((t)->tx_thread_entry)
232 #define _ux_device_thread_suspend                               _ux_utility_thread_suspend
233 #define _ux_device_thread_resume                                _ux_utility_thread_resume
234 #define _ux_device_thread_relinquish                            _ux_utility_thread_relinquish
235 #define _ux_device_semaphore_create                             _ux_utility_semaphore_create
236 #define _ux_device_semaphore_created(sem)                       ((sem)->tx_semaphore_id != 0)
237 #define _ux_device_semaphore_waiting(sem)                       ((sem)->tx_semaphore_count != 0)
238 #define _ux_device_semaphore_delete                             _ux_utility_semaphore_delete
239 #define _ux_device_semaphore_get                                _ux_utility_semaphore_get
240 #define _ux_device_semaphore_put                                _ux_utility_semaphore_put
241 #define _ux_device_mutex_create                                 _ux_utility_mutex_create
242 #define _ux_device_mutex_delete                                 _ux_utility_mutex_delete
243 #define _ux_device_mutex_off                                    _ux_utility_mutex_off
244 #define _ux_device_mutex_on                                     _ux_utility_mutex_on
245 #define _ux_device_event_flags_create                           _ux_utility_event_flags_create
246 #define _ux_device_event_flags_delete                           _ux_utility_event_flags_delete
247 #define _ux_device_event_flags_get                              _ux_utility_event_flags_get
248 #define _ux_device_event_flags_set                              _ux_utility_event_flags_set
249 #else
250 #define _ux_device_thread_create(t,name,entry,entry_param,stack,stack_size,priority,preempt_threshold,time_slice,auto_start) (UX_SUCCESS)
251 #define _ux_device_thread_delete(t)                             do{}while(0)
252 #define _ux_device_thread_entry(t)                              ((UX_THREAD_ENTRY)t)
253 #define _ux_device_thread_suspend(t)                            do{}while(0)
254 #define _ux_device_thread_resume(t)                             do{}while(0)
255 #define _ux_device_thread_relinquish(t)                         do{}while(0)
256 #define _ux_device_semaphore_create(sem,name,cnt)               (UX_SUCCESS)
257 #define _ux_device_semaphore_created(sem)                       (UX_FALSE)
258 #define _ux_device_semaphore_waiting(sem)                       (UX_FALSE)
259 #define _ux_device_semaphore_delete(sem)                        do{}while(0)
260 #define _ux_device_semaphore_get(sem,t)                         (UX_SUCCESS)
261 #define _ux_device_semaphore_put(sem)                           do{}while(0)
262 #define _ux_device_mutex_create(mutex,name)                     do{}while(0)
263 #define _ux_device_mutex_delete(mutex)                          do{}while(0)
264 #define _ux_device_mutex_off(mutex)                             do{}while(0)
265 #define _ux_device_mutex_on(mutex)                              do{}while(0)
266 #define _ux_device_event_flags_create(g,name)                   do{}while(0)
267 #define _ux_device_event_flags_delete(g)                        do{}while(0)
268 #define _ux_device_event_flags_get(g,req,gopt,actual,wopt)      do{}while(0)
269 #define _ux_device_event_flags_set(g,flags,option)              do{}while(0)
270 #endif
271 
272 
273 #if !defined(UX_HOST_STANDALONE)
274 #define _ux_host_thread_create                                  _ux_utility_thread_create
275 #define _ux_host_thread_created(thr)                            ((thr)->tx_thread_id != 0)
276 #define _ux_host_thread_delete                                  _ux_utility_thread_delete
277 #define _ux_host_thread_entry(thr)                              ((thr)->tx_thread_entry)
278 #define _ux_host_thread_resume                                  _ux_utility_thread_resume
279 #define _ux_host_thread_sleep                                   _ux_utility_thread_sleep
280 #define _ux_host_thread_schedule_other                          _ux_utility_thread_schedule_other
281 #define _ux_host_semaphore_create                               _ux_utility_semaphore_create
282 #define _ux_host_semaphore_created(sem)                         ((sem)->tx_semaphore_id != 0)
283 #define _ux_host_semaphore_waiting(sem)                         ((sem)->tx_semaphore_count != 0)
284 #define _ux_host_semaphore_delete                               _ux_utility_semaphore_delete
285 #define _ux_host_semaphore_get                                  _ux_utility_semaphore_get
286 #define _ux_host_semaphore_get_norc                             _ux_utility_semaphore_get
287 #define _ux_host_semaphore_put                                  _ux_utility_semaphore_put
288 #define _ux_host_semaphore_put_rc                               _ux_utility_semaphore_put
289 #define _ux_host_mutex_create                                   _ux_utility_mutex_create
290 #define _ux_host_mutex_delete                                   _ux_utility_mutex_delete
291 #define _ux_host_mutex_off                                      _ux_utility_mutex_off
292 #define _ux_host_mutex_on                                       _ux_utility_mutex_on
293 #define _ux_host_event_flags_create                             _ux_utility_event_flags_create
294 #define _ux_host_event_flags_delete                             _ux_utility_event_flags_delete
295 #define _ux_host_event_flags_get                                _ux_utility_event_flags_get
296 #define _ux_host_event_flags_set                                _ux_utility_event_flags_set
297 #define _ux_host_timer_create                                   _ux_utility_timer_create
298 #define _ux_host_timer_delete                                   _ux_utility_timer_delete
299 #else
300 #define _ux_host_thread_create(t,name,entry,entry_param,stack,stack_size,priority,preempt_threshold,time_slice,auto_start) (UX_SUCCESS)
301 #define _ux_host_thread_created(t)                              (UX_FALSE)
302 #define _ux_host_thread_delete(t)                               do{}while(0)
303 #define _ux_host_thread_entry(thr)                              (UX_NULL)
304 #define _ux_host_thread_resume(t)                               do{}while(0)
305 #define _ux_host_thread_sleep(t)                                do{}while(0)
306 #define _ux_host_thread_schedule_other(t)                       do{}while(0)
307 #define _ux_host_semaphore_create(sem,name,cnt)                 (UX_SUCCESS)
308 #define _ux_host_semaphore_created(sem)                         (UX_FALSE)
309 #define _ux_host_semaphore_waiting(sem)                         (UX_FALSE)
310 #define _ux_host_semaphore_delete(sem)                          do{}while(0)
311 #define _ux_host_semaphore_get(sem,t)                           (UX_SUCCESS)
312 #define _ux_host_semaphore_get_norc(sem,t)                      do{}while(0)
313 #define _ux_host_semaphore_put(sem)                             do{}while(0)
314 #define _ux_host_semaphore_put_rc(sem)                          (UX_SUCCESS)
315 #define _ux_host_mutex_create(mutex,name)                       (UX_SUCCESS)
316 #define _ux_host_mutex_delete(mutex)                            do{}while(0)
317 #define _ux_host_mutex_off(mutex)                               do{}while(0)
318 #define _ux_host_mutex_on(mutex)                                do{}while(0)
319 #define _ux_host_event_flags_create(g,name)                     (UX_SUCCESS)
320 #define _ux_host_event_flags_delete(g)                          (UX_SUCCESS)
321 #define _ux_host_event_flags_get(g,req,gopt,actual,wopt)        (UX_SUCCESS)
322 #define _ux_host_event_flags_set(g,flags,option)                do{}while(0)
323 #define _ux_host_timer_create(t,name,func,arg,tick0,tick1,flag) (UX_SUCCESS)
324 #define _ux_host_timer_delete(t)                                do{}while(0)
325 #endif
326 
327 
328 #ifdef UX_DISABLE_ERROR_HANDLER
329 #define          _ux_system_error_handler(system_level, system_context, error_code) do {} while(0)
330 #define          _ux_utility_error_callback_register(error_callback)                do {} while(0)
331 #else
332 VOID             _ux_system_error_handler(UINT system_level, UINT system_context, UINT error_code);
333 VOID             _ux_utility_error_callback_register(VOID (*error_callback)(UINT system_level, UINT system_context, UINT error_code));
334 #endif
335 
336 #define          UX_UTILITY_ADD_SAFE(add_a, add_b, result, status) do {     \
337         if (UX_OVERFLOW_CHECK_ADD_ULONG(add_a, add_b))                      \
338             status = UX_ERROR;                                              \
339         else                                                                \
340             result = (add_a) + (add_b);                                     \
341     } while(0)
342 
343 #define          UX_UTILITY_MULC_SAFE(mul_v, mul_c, result, status) do {    \
344         if (UX_OVERFLOW_CHECK_MULC_ULONG(mul_v, mul_c))                     \
345             status = UX_ERROR;                                              \
346         else                                                                \
347             result = (mul_v) * (mul_c);                                     \
348     } while(0)
349 
350 #define          UX_UTILITY_MULV_SAFE(mul_v0, mul_v1, result, status) do {  \
351         if (UX_OVERFLOW_CHECK_MULC_ULONG(mul_v0, mul_v1))                   \
352             status = UX_ERROR;                                              \
353         else                                                                \
354             result = (mul_v0) * (mul_v1);                                   \
355     } while(0)
356 
357 #define          UX_UTILITY_MEMORY_ALLOCATE_MULC_SAFE(align,cache,size_mul_v,size_mul_c)       \
358     (UX_OVERFLOW_CHECK_MULC_ULONG(size_mul_v, size_mul_c) ? UX_NULL : _ux_utility_memory_allocate((align), (cache), (size_mul_v)*(size_mul_c)))
359 #define          UX_UTILITY_MEMORY_ALLOCATE_MULV_SAFE(align,cache,size_mul_v0,size_mul_v1)     \
360     (UX_OVERFLOW_CHECK_MULV_ULONG(size_mul_v0, size_mul_v1) ? UX_NULL : _ux_utility_memory_allocate((align), (cache), (size_mul_v0)*(size_mul_v1)))
361 #define          UX_UTILITY_MEMORY_ALLOCATE_ADD_SAFE(align,cache,size_add_a,size_add_b)        \
362     (UX_OVERFLOW_CHECK_ADD_ULONG(size_add_a, size_add_b) ? UX_NULL : _ux_utility_memory_allocate((align), (cache), (size_add_a)+(size_add_b)))
363 
364 #ifdef UX_DISABLE_ARITHMETIC_CHECK
365 
366 /* No arithmetic check, calculate directly.  */
367 
368 #define          _ux_utility_memory_allocate_mulc_safe(align,cache,size_mul_v,size_mul_c)       _ux_utility_memory_allocate((align), (cache), (size_mul_v)*(size_mul_c))
369 #define          _ux_utility_memory_allocate_mulv_safe(align,cache,size_mul_v0,size_mul_v1)     _ux_utility_memory_allocate((align), (cache), (size_mul_v0)*(size_mul_v1))
370 #define          _ux_utility_memory_allocate_add_safe(align,cache,size_add_a,size_add_b)        _ux_utility_memory_allocate((align), (cache), (size_add_a)+(size_add_b))
371 
372 #else /* UX_DISABLE_ARITHMETIC_CHECK */
373 
374 #ifdef UX_ENABLE_MEMORY_ARITHMETIC_OPTIMIZE
375 
376 /* Uses macro to enable code optimization on compiling.  */
377 
378 #define          _ux_utility_memory_allocate_mulc_safe(align,cache,size_mul_v,size_mul_c)       UX_UTILITY_MEMORY_ALLOCATE_MULC_SAFE(align,cache,size_mul_v,size_mul_c)
379 #define          _ux_utility_memory_allocate_mulv_safe(align,cache,size_mul_v0,size_mul_v1)     UX_UTILITY_MEMORY_ALLOCATE_MULV_SAFE(align,cache,size_mul_v0,size_mul_v1)
380 #define          _ux_utility_memory_allocate_add_safe(align,cache,size_add_a,size_add_b)        UX_UTILITY_MEMORY_ALLOCATE_ADD_SAFE(align,cache,size_add_a,size_add_b)
381 
382 #else /* UX_ENABLE_MEMORY_ARITHMETIC_OPTIMIZE */
383 
384 /* Uses functions to be most flexible.  */
385 
386 VOID*            _ux_utility_memory_allocate_mulc_safe(ULONG align,ULONG cache,ULONG size_mul_v,ULONG size_mul_c);
387 VOID*            _ux_utility_memory_allocate_mulv_safe(ULONG align,ULONG cache,ULONG size_mul_v0,ULONG size_mul_v1);
388 VOID*            _ux_utility_memory_allocate_add_safe(ULONG align,ULONG cache,ULONG size_add_a,ULONG size_add_b);
389 
390 #endif /* UX_ENABLE_MEMORY_ARITHMETIC_OPTIMIZE */
391 
392 #endif /* UX_DISABLE_ARITHMETIC_CHECK */
393 
394 
395 #if defined(UX_NAME_REFERENCED_BY_POINTER)
396 #define ux_utility_name_match(n0,n1,l) ((n0) == (n1))
397 #else
398 #define ux_utility_name_match(n0,n1,l) (_ux_utility_memory_compare(n0,n1,l) == UX_SUCCESS)
399 #endif
400 
401 
402 /* Define the system API mappings.
403    Note: this section is only applicable to
404    application source code, hence the conditional that turns off this
405    stuff when the include file is processed by the ThreadX source. */
406 
407 #ifndef  UX_SOURCE_CODE
408 
409 
410 #define ux_utility_descriptor_parse                    _ux_utility_descriptor_parse
411 #define ux_utility_descriptor_pack                     _ux_utility_descriptor_pack
412 #define ux_utility_long_get                            _ux_utility_long_get
413 #define ux_utility_long_put                            _ux_utility_long_put
414 #define ux_utility_long_put_big_endian                 _ux_utility_long_put_big_endian
415 #define ux_utility_long_get_big_endian                 _ux_utility_long_get_big_endian
416 #define ux_utility_memory_allocate                     _ux_utility_memory_allocate
417 #define ux_utility_memory_compare                      _ux_utility_memory_compare
418 #define ux_utility_memory_copy                         _ux_utility_memory_copy
419 #define ux_utility_memory_free                         _ux_utility_memory_free
420 #define ux_utility_string_length_get                   _ux_utility_string_length_get
421 #define ux_utility_string_length_check                 _ux_utility_string_length_check
422 #define ux_utility_memory_set                          _ux_utility_memory_set
423 #define ux_utility_mutex_create                        _ux_utility_mutex_create
424 #define ux_utility_mutex_delete                        _ux_utility_mutex_delete
425 #define ux_utility_mutex_off                           _ux_utility_mutex_off
426 #define ux_utility_mutex_on                            _ux_utility_mutex_on
427 #define ux_utility_pci_class_scan                      _ux_utility_pci_class_scan
428 #define ux_utility_pci_read                            _ux_utility_pci_read
429 #define ux_utility_pci_write                           _ux_utility_pci_write
430 #define ux_utility_physical_address                    _ux_utility_physical_address
431 #define ux_utility_semaphore_create                    _ux_utility_semaphore_create
432 #define ux_utility_semaphore_delete                    _ux_utility_semaphore_delete
433 #define ux_utility_semaphore_get                       _ux_utility_semaphore_get
434 #define ux_utility_semaphore_put                       _ux_utility_semaphore_put
435 #define ux_utility_set_interrupt_handler               _ux_utility_set_interrupt_handler
436 #define ux_utility_short_get                           _ux_utility_short_get
437 #define ux_utility_short_get_big_endian                _ux_utility_short_get_big_endian
438 #define ux_utility_short_put                           _ux_utility_short_put
439 #define ux_utility_short_put_big_endian                _ux_utility_short_put_big_endian
440 #define ux_utility_thread_create                       _ux_utility_thread_create
441 #define ux_utility_thread_delete                       _ux_utility_thread_delete
442 #define ux_utility_thread_relinquish                   _ux_utility_thread_relinquish
443 #define ux_utility_thread_resume                       _ux_utility_thread_resume
444 #define ux_utility_thread_sleep                        _ux_utility_thread_sleep
445 #define ux_utility_thread_suspend                      _ux_utility_thread_suspend
446 #define ux_utility_thread_identify                     _ux_utility_thread_identify
447 #define ux_utility_timer_create                        _ux_utility_timer_create
448 #define ux_utility_event_flags_create                  _ux_utility_event_flags_create
449 #define ux_utility_event_flags_delete                  _ux_utility_event_flags_delete
450 #define ux_utility_event_flags_get                     _ux_utility_event_flags_get
451 #define ux_utility_event_flags_set                     _ux_utility_event_flags_set
452 #define ux_utility_unicode_to_string                   _ux_utility_unicode_to_string
453 #define ux_utility_string_to_unicode                   _ux_utility_string_to_unicode
454 #define ux_utility_delay_ms                            _ux_utility_delay_ms
455 #define ux_utility_error_callback_register             _ux_utility_error_callback_register
456 #define ux_system_error_handler                        _ux_system_error_handler
457 
458 #define ux_utility_time_get                            _ux_utility_time_get
459 #define ux_utility_time_elapsed                        _ux_utility_time_elapsed
460 #endif
461 
462 #endif
463