From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-oln040092072034.outbound.protection.outlook.com [40.92.72.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 83CF721CB030B for ; Sun, 23 Jul 2017 03:08:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=tM8g7oWm9g6PtuKtwAotOmzmIUIqQH7amSwYczlS2mI=; b=NU54GMBjL+RXscjx8fzz+raxs2OHzT7NMyikO90NjcSFrTlfZfnRA2Z985esbFI4o96yog8YUIX/7Q+ZNS4Wnv7WRrKtjOgIQ32cEiBpbBdupzmOx1ocdJk+kTs3QdzZm4wysIN1t91qpzQJdPf4hlz/S8kvx1MbkMmQyVcsqr2jDhlLmxGy5BIUuTv92aK++T4emm7DeIuftlUre40zyIae6kLZSItNa/WPn8+1glmqwBmoYKZvyS4Zea4VNZ/1CS5+ojifXVJVEKHTBglpZJBLOmQFlR72GXlmkUvLfFSm+RjANqYvCwk2KMZBQ6XRWeXyfiJyP/CufMPfoV4kqg== Received: from AM5EUR03FT015.eop-EUR03.prod.protection.outlook.com (10.152.16.59) by AM5EUR03HT055.eop-EUR03.prod.protection.outlook.com (10.152.16.227) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.1240.9; Sun, 23 Jul 2017 10:10:38 +0000 Received: from AM4PR06MB1491.eurprd06.prod.outlook.com (10.152.16.56) by AM5EUR03FT015.mail.protection.outlook.com (10.152.16.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1240.9 via Frontend Transport; Sun, 23 Jul 2017 10:10:38 +0000 Received: from AM4PR06MB1491.eurprd06.prod.outlook.com ([fe80::dcd0:60e6:90e0:871b]) by AM4PR06MB1491.eurprd06.prod.outlook.com ([fe80::dcd0:60e6:90e0:871b%13]) with mapi id 15.01.1282.017; Sun, 23 Jul 2017 10:10:38 +0000 From: =?iso-8859-1?Q?Marvin_H=E4user?= To: "edk2-devel@lists.01.org" CC: "michael.d.kinney@intel.com" , "liming.gao@intel.com" Thread-Topic: [PATCH 1/2] MdePkg/BaseLib: Add IsNodeInList() function. Thread-Index: AQHTA5vus1udQdORhEegPjUTqWKZfQ== Date: Sun, 23 Jul 2017 10:10:38 +0000 Message-ID: Accept-Language: de-DE, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: lists.01.org; dkim=none (message not signed) header.d=none;lists.01.org; dmarc=none action=none header.from=outlook.com; x-incomingtopheadermarker: OriginalChecksum:8FA1DF897E8859CCAF1A0C84AF24750BCF524337EB81108443923E0DD2E6F13D; UpperCasedChecksum:8CFC48F16EB1F0853DD5208984C47823D8D5BCFAC829DF108C2C165C24443863; SizeAsReceived:7248; Count:44 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [+jqFAkcbfIhziDSciUOufOn6i0OGDfT9] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM5EUR03HT055; 7:Jr4hNyZj0U+yMSmFmv3qYyQEYxzcI6NimKM2xPlcIhpD2lvTFQgYSlDWGdCiZMkifiiHGosBGeb+uqLpgQLykg1gW9bJvnhT3cANeeeMBnwfpJ/IvnhCndwWDMH4CkQBPOzO8li1pXWnxe8zuDMbFD2jJyULWKj+Ndhw7RzZfpeAIbHBNNc7/6+gG7nNiiHdhAIkkyQ5au/OwOIiXIKN2H4eGenXLiav7Zu3+jtVDnYS1hV0yR15qBdKYhOGPIvf1d4s7D3w98kVl9qXkQTHeefmP7BRCc/iH9WVjEarXJBDUJ8c+ddr+nUbWPOAbAlHZirr4vId5RMHVNT7By3gYkWQ/AI2lz7ur0I8Yo51SbmOVx5fFAjMT6DUYzjNmmQHqnh8/GTOWXfyhGdOWzYHe262oNz2/p5TV0BPgah4aTtJzSmXaJ8KWZ2MMbxP+8p4kZn7h33EeAhMMfZWOXv1dnDI8v1J1Kem5hPZ4xUWjioao//Y8N3owgc/DQYame27vWsIcaMNY/PUH+bUHsrf0B8DOi4IsDcPOY7NIFf2hxGddMUiIB5/Xve1mTViOuZ5heIuDtQOppbEkR1z2rSbdlv3n6ocxK0fmmS70hu6RkJUz8V98G/ZTMZKH0UmB6Hm2MxXdnk9P1hFzmKOD9XHY405ZU2zVm8W+B917BFNS8YQ0om/XSOynW3F4dBI8T2Zxac+96lBpGBt9ycTpgo9uP3kJzV/vwLYjC9fclcbooX0Fahy9Qd0tMDap7gU9NhWH380AI7xOt6zSEoO7QxS3g== x-incomingheadercount: 44 x-eopattributedmessage: 0 x-forefront-antispam-report: EFV:NLI; SFV:NSPM; SFS:(7070007)(98901004); DIR:OUT; SFP:1901; SCL:1; SRVR:AM5EUR03HT055; H:AM4PR06MB1491.eurprd06.prod.outlook.com; FPR:; SPF:None; LANG:en; x-ms-office365-filtering-correlation-id: 529d2c9f-1fcd-48b2-96ca-08d4d1b31068 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(300000503095)(300135400095)(201702061074)(5061506573)(5061507331)(1603103135)(2017031320274)(2017031324274)(2017031323274)(2017031322350)(1603101448)(1601125374)(1701031045)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:AM5EUR03HT055; x-ms-traffictypediagnostic: AM5EUR03HT055: x-exchange-antispam-report-test: UriScan:(189930954265078); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(444000031); SRVR:AM5EUR03HT055; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:AM5EUR03HT055; x-forefront-prvs: 0377802854 spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Jul 2017 10:10:38.2286 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5EUR03HT055 Subject: [PATCH 1/2] MdePkg/BaseLib: Add IsNodeInList() function. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Jul 2017 10:08:46 -0000 Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable This patch adds IsNodeInList() to BaseLib, which verifies the given Node is part of the doubly-linked List provided. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Marvin Haeuser --- MdePkg/Library/BaseLib/LinkedList.c | 70 +++++++++++++++++++- MdePkg/Include/Library/BaseLib.h | 25 +++++++ MdePkg/Library/BaseLib/BaseLibInternals.h | 28 -------- 3 files changed, 94 insertions(+), 29 deletions(-) diff --git a/MdePkg/Library/BaseLib/LinkedList.c b/MdePkg/Library/BaseLib/L= inkedList.c index ba373f4b7be3..b364ae41c647 100644 --- a/MdePkg/Library/BaseLib/LinkedList.c +++ b/MdePkg/Library/BaseLib/LinkedList.c @@ -1,7 +1,7 @@ /** @file Linked List Library Functions. =20 - Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -113,6 +113,74 @@ InternalBaseLibIsNodeInList ( } =20 /** + Checks whether Node is part of a doubly-linked list. + + If List is NULL, then ASSERT(). + If List->ForwardLink is NULL, then ASSERT(). + If List->BackLink is NULL, then ASSERT(). + If Node is NULL, then ASSERT(); + If PcdMaximumLinkedListLength is not zero, and List contains more than + PcdMaximumLinkedListLength nodes, then ASSERT(). + + @param List A pointer to a node in a linked list. + @param Node A pointer to the node to locate. + + @retval TRUE Node is in List. + @retval FALSE Node isn't in List, or List is invalid. + +**/ +BOOLEAN +EFIAPI +IsNodeInList ( + IN CONST LIST_ENTRY *List, + IN CONST LIST_ENTRY *Node + ) +{ + UINTN Count; + CONST LIST_ENTRY *Ptr; + + // + // Test the validity of List and Node + // + ASSERT (List !=3D NULL); + ASSERT (List->ForwardLink !=3D NULL); + ASSERT (List->BackLink !=3D NULL); + ASSERT (Node !=3D NULL); + =20 + // + // ASSERT List not too long + // + ASSERT (InternalBaseLibIsNodeInList (ListHead, Entry, FALSE)); + + Count =3D 0; + Ptr =3D List; + + // + // Check to see if Node is a member of List. =20 + // Exit early if the number of nodes in List >=3D PcdMaximumLinkedListLe= ngth + // + do { + Ptr =3D Ptr->ForwardLink; + if (PcdGet32 (PcdMaximumLinkedListLength) > 0) { + Count++; + + // + // Return if the linked list is too long + // + if (Count =3D=3D PcdGet32 (PcdMaximumLinkedListLength)) { + return (BOOLEAN)(Ptr =3D=3D Node); + } + } + + if (Ptr =3D=3D Node) { + return TRUE; + } + } while (Ptr !=3D List); + + return FALSE; +} + +/** Initializes the head node of a doubly-linked list, and returns the point= er to the head node of the doubly-linked list. =20 diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/Base= Lib.h index 791849b80406..4f3f4fd51f3f 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -2869,6 +2869,31 @@ PathCleanUpDirectories( =20 =20 /** + Checks whether Node is part of a doubly-linked list. + + If List is NULL, then ASSERT(). + If List->ForwardLink is NULL, then ASSERT(). + If List->BackLink is NULL, then ASSERT(). + If Node is NULL, then ASSERT(); + If PcdMaximumLinkedListLength is not zero, and List contains more than + PcdMaximumLinkedListLength nodes, then ASSERT(). + + @param List A pointer to a node in a linked list. + @param Node A pointer to the node to locate. + + @retval TRUE Node is in List. + @retval FALSE Node isn't in List, or List is invalid. + +**/ +BOOLEAN +EFIAPI +IsNodeInList ( + IN CONST LIST_ENTRY *List, + IN CONST LIST_ENTRY *Node + ); + + +/** Initializes the head node of a doubly linked list, and returns the point= er to the head node of the doubly linked list. =20 diff --git a/MdePkg/Library/BaseLib/BaseLibInternals.h b/MdePkg/Library/Bas= eLib/BaseLibInternals.h index ea387ce37d27..9dca97a0dcc9 100644 --- a/MdePkg/Library/BaseLib/BaseLibInternals.h +++ b/MdePkg/Library/BaseLib/BaseLibInternals.h @@ -340,34 +340,6 @@ InternalSwitchStack ( =20 =20 /** - Worker function that locates the Node in the List. - - By searching the List, finds the location of the Node in List. At the sa= me time, - verifies the validity of this list. - - If List is NULL, then ASSERT(). - If List->ForwardLink is NULL, then ASSERT(). - If List->backLink is NULL, then ASSERT(). - If Node is NULL, then ASSERT(); - If PcdMaximumLinkedListLength is not zero, and prior to insertion the nu= mber - of nodes in ListHead, including the ListHead node, is greater than or - equal to PcdMaximumLinkedListLength, then ASSERT(). - - @param List A pointer to a node in a linked list. - @param Node A pointer to one nod. - - @retval TRUE Node is in List. - @retval FALSE Node isn't in List, or List is invalid. - -**/ -BOOLEAN -EFIAPI -IsNodeInList ( - IN CONST LIST_ENTRY *List, - IN CONST LIST_ENTRY *Node - ); - -/** Worker function that returns a bit field from Operand. =20 Returns the bitfield specified by the StartBit and the EndBit from Opera= nd. --=20 2.12.2.windows.2