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