#include "BaseLibInternals.h"\r
\r
/**\r
- Worker function that locates the Node in the List.\r
+ If PcdVerifyNodeInList is TRUE, ASSERTs when SecondEntry is or is not part of\r
+ the same doubly-linked list as FirstEntry depending on the value of InList.\r
+ Independent of PcdVerifyNodeInList, ASSERTs when FirstEntry is not part of a\r
+ valid list.\r
\r
- By searching the List, finds the location of the Node in List. At the same time,\r
- verifies the validity of this list.\r
+ If FirstEntry is NULL, then ASSERT().\r
+ If FirstEntry->ForwardLink is NULL, then ASSERT().\r
+ If FirstEntry->BackLink is NULL, then ASSERT().\r
+ If PcdMaximumLinkedListLength is not zero, and List contains more than\r
+ PcdMaximumLinkedListLength nodes, then ASSERT().\r
+ If PcdVerifyNodeInList is TRUE and SecondEntry is NULL, then ASSERT().\r
+\r
+ @param FirstEntry A pointer to a node in a linked list.\r
+ @param SecondEntry A pointer to the node to locate.\r
+ @param InList Defines whether to check if SecondEntry is or is not part\r
+ of the same doubly-linked list as FirstEntry.\r
+\r
+**/\r
+#if !defined (MDEPKG_NDEBUG)\r
+ #define ASSERT_VERIFY_NODE_IN_VALID_LIST(FirstEntry, SecondEntry, InList) \\r
+ do { \\r
+ if (FeaturePcdGet (PcdVerifyNodeInList)) { \\r
+ ASSERT (InList == IsNodeInList ((FirstEntry), (SecondEntry))); \\r
+ } else { \\r
+ ASSERT (InternalBaseLibIsListValid (FirstEntry)); \\r
+ } \\r
+ } while (FALSE)\r
+#else\r
+ #define ASSERT_VERIFY_NODE_IN_VALID_LIST(FirstEntry, SecondEntry, InList)\r
+#endif\r
+\r
+/**\r
+ Worker function that verifies the validity of this list.\r
\r
If List is NULL, then ASSERT().\r
If List->ForwardLink is NULL, then ASSERT().\r
- If List->backLink is NULL, then ASSERT().\r
- If Node is NULL, then ASSERT().\r
- If PcdVerifyNodeInList is TRUE and DoMembershipCheck is TRUE and Node \r
- is in not a member of List, then return FALSE\r
+ If List->BackLink is NULL, then ASSERT().\r
If PcdMaximumLinkedListLength is not zero, and List contains more than\r
PcdMaximumLinkedListLength nodes, then ASSERT().\r
\r
@param List A pointer to a node in a linked list.\r
- @param Node A pointer to a node in a linked list.\r
- @param VerifyNodeInList TRUE if a check should be made to see if Node is a \r
- member of List. FALSE if no membership test should \r
- be performed.\r
\r
@retval TRUE if PcdVerifyNodeInList is FALSE\r
@retval TRUE if DoMembershipCheck is FALSE\r
**/\r
BOOLEAN\r
EFIAPI\r
-InternalBaseLibIsNodeInList (\r
- IN CONST LIST_ENTRY *List,\r
- IN CONST LIST_ENTRY *Node,\r
- IN BOOLEAN VerifyNodeInList\r
+InternalBaseLibIsListValid (\r
+ IN CONST LIST_ENTRY *List\r
)\r
{\r
UINTN Count;\r
ASSERT (List != NULL);\r
ASSERT (List->ForwardLink != NULL);\r
ASSERT (List->BackLink != NULL);\r
- ASSERT (Node != NULL);\r
-\r
- Count = 0;\r
- Ptr = List;\r
-\r
- if (FeaturePcdGet (PcdVerifyNodeInList) && VerifyNodeInList) {\r
- //\r
- // Check to see if Node is a member of List. \r
- // Exit early if the number of nodes in List >= PcdMaximumLinkedListLength\r
- //\r
- do {\r
- Ptr = Ptr->ForwardLink;\r
- if (PcdGet32 (PcdMaximumLinkedListLength) > 0) {\r
- Count++;\r
- //\r
- // ASSERT() if the linked list is too long\r
- //\r
- ASSERT (Count < PcdGet32 (PcdMaximumLinkedListLength));\r
-\r
- //\r
- // Return if the linked list is too long\r
- //\r
- if (Count >= PcdGet32 (PcdMaximumLinkedListLength)) {\r
- return (BOOLEAN)(Ptr == Node);\r
- }\r
- }\r
- } while ((Ptr != List) && (Ptr != Node)); \r
-\r
- if (Ptr != Node) {\r
- return FALSE;\r
- }\r
- }\r
\r
if (PcdGet32 (PcdMaximumLinkedListLength) > 0) {\r
+ Count = 0;\r
+ Ptr = List;\r
+\r
//\r
// Count the total number of nodes in List.\r
// Exit early if the number of nodes in List >= PcdMaximumLinkedListLength\r
} while ((Ptr != List) && (Count < PcdGet32 (PcdMaximumLinkedListLength)));\r
\r
//\r
- // ASSERT() if the linked list is too long\r
+ // return whether linked list is too long\r
//\r
- ASSERT (Count < PcdGet32 (PcdMaximumLinkedListLength));\r
+ return (BOOLEAN)(Count < PcdGet32 (PcdMaximumLinkedListLength));\r
}\r
\r
return TRUE;\r
//\r
// ASSERT List not too long and Entry is not one of the nodes of List\r
//\r
- ASSERT (InternalBaseLibIsNodeInList (ListHead, Entry, FALSE));\r
+ ASSERT_VERIFY_NODE_IN_VALID_LIST (ListHead, Entry, FALSE);\r
\r
Entry->ForwardLink = ListHead->ForwardLink;\r
Entry->BackLink = ListHead;\r
//\r
// ASSERT List not too long and Entry is not one of the nodes of List\r
//\r
- ASSERT (InternalBaseLibIsNodeInList (ListHead, Entry, FALSE));\r
+ ASSERT_VERIFY_NODE_IN_VALID_LIST (ListHead, Entry, FALSE);\r
\r
Entry->ForwardLink = ListHead;\r
Entry->BackLink = ListHead->BackLink;\r
//\r
// ASSERT List not too long\r
//\r
- ASSERT (InternalBaseLibIsNodeInList (List, List, FALSE));\r
+ ASSERT (InternalBaseLibIsListValid (List));\r
\r
return List->ForwardLink;\r
}\r
//\r
// ASSERT List not too long and Node is one of the nodes of List\r
//\r
- ASSERT (InternalBaseLibIsNodeInList (List, Node, TRUE));\r
+ ASSERT_VERIFY_NODE_IN_VALID_LIST (List, Node, TRUE);\r
\r
return Node->ForwardLink;\r
}\r
//\r
// ASSERT List not too long and Node is one of the nodes of List\r
//\r
- ASSERT (InternalBaseLibIsNodeInList (List, Node, TRUE));\r
+ ASSERT_VERIFY_NODE_IN_VALID_LIST (List, Node, TRUE);\r
\r
return Node->BackLink;\r
}\r
//\r
// ASSERT List not too long\r
//\r
- ASSERT (InternalBaseLibIsNodeInList (ListHead, ListHead, FALSE));\r
+ ASSERT (InternalBaseLibIsListValid (ListHead));\r
\r
return (BOOLEAN)(ListHead->ForwardLink == ListHead);\r
}\r
//\r
// ASSERT List not too long and Node is one of the nodes of List\r
//\r
- ASSERT (InternalBaseLibIsNodeInList (List, Node, TRUE));\r
+ ASSERT_VERIFY_NODE_IN_VALID_LIST (List, Node, TRUE);\r
\r
return (BOOLEAN)(Node == List);\r
}\r
//\r
// ASSERT List not too long and Node is one of the nodes of List\r
//\r
- ASSERT (InternalBaseLibIsNodeInList (List, Node, TRUE));\r
+ ASSERT_VERIFY_NODE_IN_VALID_LIST (List, Node, TRUE);\r
\r
return (BOOLEAN)(!IsNull (List, Node) && List->BackLink == Node);\r
}\r
//\r
// ASSERT Entry1 and Entry2 are in the same linked list\r
//\r
- ASSERT (InternalBaseLibIsNodeInList (FirstEntry, SecondEntry, TRUE));\r
+ ASSERT_VERIFY_NODE_IN_VALID_LIST (FirstEntry, SecondEntry, TRUE);\r
\r
//\r
// Ptr is the node pointed to by FirstEntry->ForwardLink\r