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 /** Block Pool */ 19 /** */ 20 /**************************************************************************/ 21 /**************************************************************************/ 22 23 #define TX_SOURCE_CODE 24 25 26 /* Include necessary system files. */ 27 28 #include "tx_api.h" 29 #include "tx_block_pool.h" 30 31 32 /**************************************************************************/ 33 /* */ 34 /* FUNCTION RELEASE */ 35 /* */ 36 /* _txe_block_release PORTABLE C */ 37 /* 6.1 */ 38 /* AUTHOR */ 39 /* */ 40 /* William E. Lamie, Microsoft Corporation */ 41 /* */ 42 /* DESCRIPTION */ 43 /* */ 44 /* This function checks for errors in the block release function call. */ 45 /* */ 46 /* INPUT */ 47 /* */ 48 /* block_ptr Pointer to memory block */ 49 /* */ 50 /* OUTPUT */ 51 /* */ 52 /* TX_PTR_ERROR Invalid memory block pointer */ 53 /* status Actual completion status */ 54 /* */ 55 /* CALLS */ 56 /* */ 57 /* _tx_block_release Actual block release function */ 58 /* */ 59 /* CALLED BY */ 60 /* */ 61 /* Application Code */ 62 /* */ 63 /* RELEASE HISTORY */ 64 /* */ 65 /* DATE NAME DESCRIPTION */ 66 /* */ 67 /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 68 /* 09-30-2020 Yuxin Zhou Modified comment(s), */ 69 /* resulting in version 6.1 */ 70 /* */ 71 /**************************************************************************/ _txe_block_release(VOID * block_ptr)72UINT _txe_block_release(VOID *block_ptr) 73 { 74 75 UINT status; 76 TX_BLOCK_POOL *pool_ptr; 77 UCHAR **indirect_ptr; 78 UCHAR *work_ptr; 79 80 81 /* First check the supplied pointer. */ 82 if (block_ptr == TX_NULL) 83 { 84 85 /* The block pointer is invalid, return appropriate status. */ 86 status = TX_PTR_ERROR; 87 } 88 else 89 { 90 91 /* Pickup the pool pointer which is just previous to the starting 92 address of block that the caller sees. */ 93 work_ptr = TX_VOID_TO_UCHAR_POINTER_CONVERT(block_ptr); 94 work_ptr = TX_UCHAR_POINTER_SUB(work_ptr, (sizeof(UCHAR *))); 95 indirect_ptr = TX_UCHAR_TO_INDIRECT_UCHAR_POINTER_CONVERT(work_ptr); 96 work_ptr = *indirect_ptr; 97 pool_ptr = TX_UCHAR_TO_BLOCK_POOL_POINTER_CONVERT(work_ptr); 98 99 /* Check for an invalid pool pointer. */ 100 if (pool_ptr == TX_NULL) 101 { 102 103 /* Pool pointer is invalid, return appropriate error code. */ 104 status = TX_PTR_ERROR; 105 } 106 107 /* Now check for invalid pool ID. */ 108 else if (pool_ptr -> tx_block_pool_id != TX_BLOCK_POOL_ID) 109 { 110 111 /* Pool pointer is invalid, return appropriate error code. */ 112 status = TX_PTR_ERROR; 113 } 114 else 115 { 116 117 /* Call actual block release function. */ 118 status = _tx_block_release(block_ptr); 119 } 120 } 121 122 /* Return completion status. */ 123 return(status); 124 } 125 126