static void *mcl_def_list_iter_next(mcl_iter *iter, mcl_list *list) { mcl_list_head *entries = NULL; mcl_list_head *ent = NULL; POINTER_RET_NULL(iter); POINTER_RET_NULL(list); common_iter_op(iter); entries = &list->_entries; if (!IS_LIST_EMPTY(entries)) { ent = (mcl_list_head *)iter->_data; if (!ent || ent->_next == entries) { // last elem alrdy iter->_ptr = NULL; iter->_data = NULL; return NULL; } else { iter->_ptr = (void *)MCL_LIST_ENTRY(ent->_next); iter->_data = (void *)ent->_next; return iter->_ptr; } } else { iter->_ptr = NULL; iter->_data = NULL; return NULL; } }
//-------------------------------------------------------------------------- // Name FindLocalIdent // // Find the most nested ident with this name. // // Note: The most nested ident is always on the top. //-------------------------------------------------------------------------- TLocalIdent * _FindLocalIdent ( TListRoot * pTab ) { if (IS_LIST_EMPTY( pTab )) return NULL; else return (TLocalIdent *)pTab->Flink; };
static void *mcl_def_list_iter_tail(mcl_iter *iter, mcl_list *list) { mcl_list_head *entries = NULL; POINTER_RET_NULL(iter); POINTER_RET_NULL(list); common_iter_op(iter); entries = &list->_entries; if (!IS_LIST_EMPTY(entries)) { iter->_ptr = (void *)MCL_LIST_ENTRY(entries->_prev); iter->_data = (void *)entries->_prev; } else { iter->_ptr = NULL; iter->_data = NULL; } return iter->_ptr; }
void mcl_list_destroy(mcl_list *list_ptr, mcl_free_fn_t free_fn) { mcl_list_head *ent = NULL; mcl_list_node *node = NULL; mcl_list_head *entries = &list_ptr->_entries; if (!IS_LIST_EMPTY(entries)) { for (ent = entries->_next; ent != entries;) { node = (mcl_list_node *)MCL_LIST_ENTRY(ent); if (node->_data && free_fn) { free_fn(node->_data); } ent = ent->_next; free(node); } } else { fprintf(stderr, "warning: destroy empty list\n"); } free(list_ptr); }
static inline int list_del(void *data, mcl_list *list_ptr, int free_flag, mcl_list_cmp_func cmp_func, mcl_free_fn_t free_fn) { mcl_list_head *ent = NULL; mcl_list_node *node = NULL; mcl_list_head *entries = &(list_ptr->_entries); if (!IS_LIST_EMPTY(entries)) { //printf("entries: %p, prev: %p, next: %p\n", entries, entries->_prev, entries->_next); for (ent = entries->_next; ent != entries; ent = ent->_next) { node = (mcl_list_node *)MCL_LIST_ENTRY(ent); //printf("node: %p, node_data: %p, data: %p, prev: %p, next: %p\n", node, node->_data, data, ent->_prev, ent->_next); if (cmp_func && cmp_func(data, node->_data)) { HANDLE_ELEM(ent, list_ptr, free_flag, free_fn); return 1; } else if (node->_data == data) { HANDLE_ELEM(ent, list_ptr, free_flag, free_fn); return 1; } } } return 0; }
VOID DumpAfdConnection( PAFD_CONNECTION Connection, DWORD ActualAddress ) /*++ Routine Description: Dumps the specified AFD_CONNECTION structures. Arguments: Connection - Points to the AFD_CONNECTION structure to dump. ActualAddress - The actual address where the structure resides on the debugee. Return Value: None. --*/ { UCHAR address[MAX_TRANSPORT_ADDR]; ULONG result; dprintf( "AFD_CONNECTION @ %08lx:\n", ActualAddress ); dprintf( " Type = %04X (%s)\n", Connection->Type, StructureTypeToString( Connection->Type ) ); dprintf( " ReferenceCount = %d\n", Connection->ReferenceCount ); dprintf( " State = %08X (%s)\n", Connection->State, ConnectionStateToString( Connection->State ) ); dprintf( " Handle = %08lx\n", Connection->Handle ); dprintf( " FileObject = %08lx\n", Connection->FileObject ); dprintf( " ConnectTime = %s\n", SystemTimeToString( Connection->ConnectTime ) ); if( Connection->TdiBufferring ) { dprintf( " ReceiveBytesIndicated = %s\n", LongLongToString( Connection->Common.Bufferring.ReceiveBytesIndicated.QuadPart ) ); dprintf( " ReceiveBytesTaken = %s\n", LongLongToString( Connection->Common.Bufferring.ReceiveBytesTaken.QuadPart ) ); dprintf( " ReceiveBytesOutstanding = %s\n", LongLongToString( Connection->Common.Bufferring.ReceiveBytesOutstanding.QuadPart ) ); dprintf( " ReceiveExpeditedBytesIndicated = %s\n", LongLongToString( Connection->Common.Bufferring.ReceiveExpeditedBytesIndicated.QuadPart ) ); dprintf( " ReceiveExpeditedBytesTaken = %s\n", LongLongToString( Connection->Common.Bufferring.ReceiveExpeditedBytesTaken.QuadPart ) ); dprintf( " ReceiveExpeditedBytesOutstanding = %s\n", LongLongToString( Connection->Common.Bufferring.ReceiveExpeditedBytesOutstanding.QuadPart ) ); dprintf( " NonBlockingSendPossible = %s\n", BooleanToString( Connection->Common.Bufferring.NonBlockingSendPossible ) ); dprintf( " ZeroByteReceiveIndicated = %s\n", BooleanToString( Connection->Common.Bufferring.ZeroByteReceiveIndicated ) ); } else { if( IS_LIST_EMPTY( ActualAddress, Connection, Common.NonBufferring.ReceiveIrpListHead ) ) { dprintf( " ReceiveIrpListHead = EMPTY\n" ); } else { dprintf( " ReceiveIrpListHead @ %08lx\n", ACTUAL_ADDRESS( ActualAddress, Connection, Common.NonBufferring.ReceiveIrpListHead ) ); } if( IS_LIST_EMPTY( ActualAddress, Connection, Common.NonBufferring.ReceiveBufferListHead ) ) { dprintf( " ReceiveBufferListHead = EMPTY\n" ); } else { dprintf( " ReceiveBufferListHead @ %08lx\n", ACTUAL_ADDRESS( ActualAddress, Connection, Common.NonBufferring.ReceiveBufferListHead ) ); } if( IS_LIST_EMPTY( ActualAddress, Connection, Common.NonBufferring.SendIrpListHead ) ) { dprintf( " SendIrpListHead = EMPTY\n" ); } else { dprintf( " SendIrpListHead @ %08lx\n", ACTUAL_ADDRESS( ActualAddress, Connection, Common.NonBufferring.SendIrpListHead ) ); } dprintf( " BufferredReceiveBytes = %lu\n", Connection->Common.NonBufferring.BufferredReceiveBytes ); dprintf( " BufferredExpeditedBytes = %lu\n", Connection->Common.NonBufferring.BufferredExpeditedBytes ); dprintf( " BufferredReceiveCount = %u\n", Connection->Common.NonBufferring.BufferredReceiveCount ); dprintf( " BufferredExpeditedCount = %u\n", Connection->Common.NonBufferring.BufferredExpeditedCount ); dprintf( " ReceiveBytesInTransport = %lu\n", Connection->Common.NonBufferring.ReceiveBytesInTransport ); dprintf( " BufferredSendBytes = %lu\n", Connection->Common.NonBufferring.BufferredSendBytes ); dprintf( " ReceiveCountInTransport = %u\n", Connection->Common.NonBufferring.ReceiveCountInTransport ); dprintf( " BufferredSendCount = %u\n", Connection->Common.NonBufferring.BufferredSendCount ); dprintf( " DisconnectIrp = %08lx\n", Connection->Common.NonBufferring.DisconnectIrp ); } dprintf( " Endpoint = %08lx\n", Connection->Endpoint ); dprintf( " MaxBufferredReceiveBytes = %lu\n", Connection->MaxBufferredReceiveBytes ); dprintf( " MaxBufferredSendBytes = %lu\n", Connection->MaxBufferredSendBytes ); dprintf( " MaxBufferredReceiveCount = %u\n", Connection->MaxBufferredReceiveCount ); dprintf( " MaxBufferredSendCount = %u\n", Connection->MaxBufferredSendCount ); dprintf( " ConnectDataBuffers = %08lx\n", Connection->ConnectDataBuffers ); dprintf( " OwningProcess = %08lx\n", Connection->OwningProcess ); dprintf( " DeviceObject = %08lx\n", Connection->DeviceObject ); dprintf( " RemoteAddress = %08lx\n", Connection->RemoteAddress ); dprintf( " RemoteAddressLength = %lu\n", Connection->RemoteAddressLength ); if( Connection->RemoteAddressLength <= sizeof(address) && Connection->RemoteAddress != NULL ) { if( ReadMemory( (DWORD)Connection->RemoteAddress, address, sizeof(address), &result ) ) { DumpTransportAddress( " ", (PTRANSPORT_ADDRESS)address, (DWORD)Connection->RemoteAddress ); } } dprintf( " DisconnectIndicated = %s\n", BooleanToString( Connection->DisconnectIndicated ) ); dprintf( " AbortIndicated = %s\n", BooleanToString( Connection->AbortIndicated ) ); dprintf( " TdiBufferring = %s\n", BooleanToString( Connection->TdiBufferring ) ); dprintf( " ConnectedReferenceAdded = %s\n", BooleanToString( Connection->ConnectedReferenceAdded ) ); dprintf( " SpecialCondition = %s\n", BooleanToString( Connection->SpecialCondition ) ); dprintf( " CleanupBegun = %s\n", BooleanToString( Connection->CleanupBegun ) ); dprintf( " ClosePendedTransmit = %s\n", BooleanToString( Connection->ClosePendedTransmit ) ); if( IsCheckedAfd ) { dprintf( " CurrentReferenceSlot = %lu\n", Connection->CurrentReferenceSlot % MAX_REFERENCE ); dprintf( " ReferenceDebug = %08lx\n", ACTUAL_ADDRESS( ActualAddress, Connection, ReferenceDebug ) ); } dprintf( "\n" ); } // DumpAfdConnection
VOID DumpAfdEndpoint( PAFD_ENDPOINT Endpoint, DWORD ActualAddress ) /*++ Routine Description: Dumps the specified AFD_ENDPOINT structure. Arguments: Endpoint - Points to the AFD_ENDPOINT to dump. ActualAddress - The actual address where the structure resides on the debugee. Return Value: None. --*/ { AFD_TRANSPORT_INFO transportInfo; UNICODE_STRING unicodeString; WCHAR buffer[MAX_PATH]; UCHAR address[MAX_TRANSPORT_ADDR]; ULONG result; dprintf( "AFD_ENDPOINT @ %08lx:\n", ActualAddress ); dprintf( " Type = %04X (%s)\n", Endpoint->Type, StructureTypeToString( Endpoint->Type ) ); dprintf( " ReferenceCount = %d\n", Endpoint->ReferenceCount ); dprintf( " State = %02X (%s)\n", Endpoint->State, EndpointStateToString( Endpoint->State ) ); dprintf( " NonBlocking = %s\n", BooleanToString( Endpoint->NonBlocking ) ); dprintf( " InLine = %s\n", BooleanToString( Endpoint->InLine ) ); dprintf( " TdiBufferring = %s\n", BooleanToString( Endpoint->TdiBufferring ) ); dprintf( " TransportInfo = %08lx\n", Endpoint->TransportInfo ); if( ReadMemory( (DWORD)Endpoint->TransportInfo, &transportInfo, sizeof(transportInfo), &result ) && ReadMemory( (DWORD)transportInfo.TransportDeviceName.Buffer, buffer, sizeof(buffer), &result ) ) { unicodeString = transportInfo.TransportDeviceName; unicodeString.Buffer = buffer; dprintf( " TransportDeviceName = %wZ\n", &unicodeString ); } dprintf( " EndpointType = %08lx (%s)\n", Endpoint->EndpointType, EndpointTypeToString( Endpoint->EndpointType ) ); dprintf( " AddressHandle = %08lx\n", Endpoint->AddressHandle ); dprintf( " AddressFileObject = %08lx\n", Endpoint->AddressFileObject ); switch( Endpoint->Type ) { case AfdBlockTypeVcConnecting : dprintf( " Connection = %08lx\n", Endpoint->Common.VcConnecting.Connection ); dprintf( " ConnectStatus = %08lx\n", Endpoint->Common.VcConnecting.ConnectStatus ); dprintf( " ListenEndpoint = %08lx\n", Endpoint->Common.VcConnecting.ListenEndpoint ); break; case AfdBlockTypeVcListening : if( IS_LIST_EMPTY( ActualAddress, Endpoint, Common.VcListening.FreeConnectionListHead ) ) { dprintf( " FreeConnectionListHead = EMPTY\n" ); } else { dprintf( " FreeConnectionListHead @ %08lx\n", ACTUAL_ADDRESS( ActualAddress, Endpoint, Common.VcListening.FreeConnectionListHead ) ); } if( IS_LIST_EMPTY( ActualAddress, Endpoint, Common.VcListening.UnacceptedConnectionListHead ) ) { dprintf( " UnacceptedConnectionListHead = EMPTY\n" ); } else { dprintf( " UnacceptedConnectionListHead @ %08lx\n", ACTUAL_ADDRESS( ActualAddress, Endpoint, Common.VcListening.UnacceptedConnectionListHead ) ); } if( IS_LIST_EMPTY( ActualAddress, Endpoint, Common.VcListening.ReturnedConnectionListHead ) ) { dprintf( " ReturnedConnectionListHead = EMPTY\n" ); } else { dprintf( " ReturnedConnectionListHead @ %08lx\n", ACTUAL_ADDRESS( ActualAddress, Endpoint, Common.VcListening.ReturnedConnectionListHead ) ); } if( IS_LIST_EMPTY( ActualAddress, Endpoint, Common.VcListening.ListeningIrpListHead ) ) { dprintf( " ListeningIrpListHead = EMPTY\n" ); } else { dprintf( " ListeningIrpListHead @ %08lx\n", ACTUAL_ADDRESS( ActualAddress, Endpoint, Common.VcListening.ListeningIrpListHead ) ); } dprintf( " FailedConnectionAdds = %08lx\n", Endpoint->Common.VcListening.FailedConnectionAdds ); break; case AfdBlockTypeDatagram : dprintf( " RemoteAddress = %08lx\n", Endpoint->Common.Datagram.RemoteAddress ); dprintf( " RemoteAddressLength = %08lx\n", Endpoint->Common.Datagram.RemoteAddressLength ); if( IS_LIST_EMPTY( ActualAddress, Endpoint, Common.Datagram.ReceiveIrpListHead ) ) { dprintf( " ReceiveIrpListHead = EMPTY\n" ); } else { dprintf( " ReceiveIrpListHead @ %08lx\n", ACTUAL_ADDRESS( ActualAddress, Endpoint, Common.Datagram.ReceiveIrpListHead ) ); } if( IS_LIST_EMPTY( ActualAddress, Endpoint, Common.Datagram.PeekIrpListHead ) ) { dprintf( " PeekIrpListHead = EMPTY\n" ); } else { dprintf( " PeekIrpListHead @ %08lx\n", ACTUAL_ADDRESS( ActualAddress, Endpoint, Common.Datagram.PeekIrpListHead ) ); } if( IS_LIST_EMPTY( ActualAddress, Endpoint, Common.Datagram.ReceiveBufferListHead ) ) { dprintf( " ReceiveBufferListHead = EMPTY\n" ); } else { dprintf( " ReceiveBufferListHead @ %08lx\n", ACTUAL_ADDRESS( ActualAddress, Endpoint, Common.Datagram.ReceiveBufferListHead ) ); } dprintf( " BufferredDatagramBytes = %08lx\n", Endpoint->BufferredDatagramBytes ); dprintf( " BufferredDatagramCount = %04X\n", Endpoint->BufferredDatagramCount ); dprintf( " MaxBufferredReceiveBytes = %08lx\n", Endpoint->Common.Datagram.MaxBufferredReceiveBytes ); dprintf( " MaxBufferredSendBytes = %08lx\n", Endpoint->Common.Datagram.MaxBufferredSendBytes ); dprintf( " MaxBufferredReceiveCount = %04X\n", Endpoint->Common.Datagram.MaxBufferredReceiveCount ); dprintf( " MaxBufferredSendCount = %04X\n", Endpoint->Common.Datagram.MaxBufferredSendCount ); dprintf( " CircularQueueing = %s\n", BooleanToString( Endpoint->Common.Datagram.CircularQueueing ) ); break; } dprintf( " DisconnectMode = %08lx\n", Endpoint->DisconnectMode ); dprintf( " OutstandingIrpCount = %08lx\n", Endpoint->OutstandingIrpCount ); dprintf( " LocalAddress = %08lx\n", Endpoint->LocalAddress ); dprintf( " LocalAddressLength = %08lx\n", Endpoint->LocalAddressLength ); if( Endpoint->LocalAddressLength <= sizeof(address) && Endpoint->LocalAddress != NULL ) { if( ReadMemory( (DWORD)Endpoint->LocalAddress, address, sizeof(address), &result ) ) { DumpTransportAddress( " ", (PTRANSPORT_ADDRESS)address, (DWORD)Endpoint->LocalAddress ); } } dprintf( " Context = %08lx\n", Endpoint->Context ); dprintf( " ContextLength = %08lx\n", Endpoint->ContextLength ); dprintf( " OwningProcess = %08lx\n", Endpoint->OwningProcess ); dprintf( " ConnectDataBuffers = %08lx\n", Endpoint->ConnectDataBuffers ); dprintf( " TransmitIrp = %08lx\n", Endpoint->TransmitIrp ); dprintf( " TransmitInfo = %08lx\n", Endpoint->TransmitInfo ); dprintf( " AddressDeviceObject = %08lx\n", Endpoint->AddressDeviceObject ); dprintf( " ConnectOutstanding = %s\n", BooleanToString( Endpoint->ConnectOutstanding ) ); dprintf( " SendDisconnected = %s\n", BooleanToString( Endpoint->SendDisconnected ) ); dprintf( " EndpointCleanedUp = %s\n", BooleanToString( Endpoint->EndpointCleanedUp ) ); dprintf( " TdiMessageMode = %s\n", BooleanToString( Endpoint->TdiMessageMode ) ); #if !defined(NT351) dprintf( " EventObject = %08lx\n", Endpoint->EventObject ); dprintf( " EventsEnabled = %08lx\n", Endpoint->EventsEnabled ); dprintf( " EventsDisabled = %08lx\n", Endpoint->EventsDisabled ); dprintf( " EventsActive = %08lx\n", Endpoint->EventsActive ); dprintf( " EventStatus = %08lx\n", ACTUAL_ADDRESS( ActualAddress, Endpoint, EventStatus[0] ) ); dprintf( " GroupID = %08lx\n", Endpoint->GroupID ); dprintf( " GroupType = %s\n", GroupTypeToString( Endpoint->GroupType ) ); #endif if( IsCheckedAfd ) { dprintf( " ReferenceDebug = %08lx\n", Endpoint->ReferenceDebug ); dprintf( " CurrentReferenceSlot = %lu\n", Endpoint->CurrentReferenceSlot % MAX_REFERENCE ); } dprintf( "\n" ); } // DumpAfdEndpoint