| 158 | |
| 159 | #ifdef DEBUG_XDR_MEMORY |
| 160 | void xdr_debug_memory(RemoteXdr* xdrs, |
| 161 | enum xdr_op xop, |
| 162 | const void* xdrvar, const void* address, ULONG length) |
| 163 | { |
| 164 | /************************************** |
| 165 | * |
| 166 | * x d r _ d e b u g _ m e m o r y |
| 167 | * |
| 168 | ************************************** |
| 169 | * |
| 170 | * Functional description |
| 171 | * Track memory allocation patterns of RemoteXdr aggregate |
| 172 | * types (i.e. xdr_cstring, xdr_string, etc.) to |
| 173 | * validate that memory is not leaked by overwriting |
| 174 | * RemoteXdr aggregate pointers and that freeing a packet |
| 175 | * with REMOTE_free_packet() does not miss anything. |
| 176 | * |
| 177 | * All memory allocations due to marshalling RemoteXdr |
| 178 | * variables are recorded in a debug memory alloca- |
| 179 | * tion table stored at the front of a packet. |
| 180 | * |
| 181 | * Once a packet is being tracked it is an assertion |
| 182 | * error if a memory allocation can not be recorded |
| 183 | * due to space limitations or if a previous memory |
| 184 | * allocation being freed cannot be found. At most |
| 185 | * P_MALLOC_SIZE entries can be stored in the memory |
| 186 | * allocation table. A rough estimate of the number |
| 187 | * of RemoteXdr aggregates that can hang off a packet can |
| 188 | * be obtained by examining the subpackets defined |
| 189 | * in <remote/protocol.h>: A guestimate of 36 at this |
| 190 | * time includes 10 strings used to decode an xdr |
| 191 | * status vector. |
| 192 | * |
| 193 | **************************************/ |
| 194 | rem_port* port = xdrs->x_public; |
| 195 | fb_assert(port != 0); |
| 196 | fb_assert(port->port_header.blk_type == type_port); |
| 197 | |
| 198 | // Compare the RemoteXdr variable address with the lower and upper bounds |
| 199 | // of each packet to determine which packet contains it. Record or |
| 200 | // delete an entry in that packet's memory allocation table. |
| 201 | |
| 202 | rem_vec* vector = port->port_packet_vector; |
| 203 | if (!vector) // Not tracking port's protocol |
| 204 | return; |
| 205 | |
| 206 | ULONG i; |
| 207 | for (i = 0; i < vector->vec_count; i++) |
| 208 | { |
| 209 | PACKET* packet = (PACKET*) vector->vec_object[i]; |
| 210 | if (packet) |
| 211 | { |
| 212 | fb_assert(packet->p_operation > op_void && packet->p_operation < op_max); |
| 213 | |
| 214 | if ((SCHAR*) xdrvar >= (SCHAR*) packet && |
| 215 | (SCHAR*) xdrvar < (SCHAR*) packet + sizeof(PACKET)) |
| 216 | { |
| 217 | ULONG j; |
no outgoing calls
no test coverage detected