From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-oln040092068106.outbound.protection.outlook.com [40.92.68.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 40FC421E1DAFA for ; Thu, 3 Aug 2017 12:50:03 -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=08rClQ9tQ44aT6ifLMEkYSgtEHvWw7xgFXdpF1+igxI=; b=jFPhJWqoWOk8uiVssVgYEQqNX65NbXYSavh1sVQ94lft0kjKmh4DVkmukqpx82fb3bQeIU+KWnVa3zHqpBgJciQuyckWY1gWzt3bYW1CsgufYrhlTIUe/yB9S0pHJ1KuafxXjJtOlcB2JheR3hDPT5rIswzkbZTYBqLAs/taUJmsDe6FSFxmMljLoGeHq44ZMfte6ugECxtLXjVLsd8SCrdhdLhNTyH2kDFTFvrpDAGc9XwGIjSxIFQjYA4sGmPZ1s/Axs1KUR2+5BZERfzkpGGscADsb9ZNFrqC7xepAwKpHSJC4t1mUDdw1rbMiJio13veIGnkjjDSKGQT7nRvqg== Received: from AM5EUR02FT039.eop-EUR02.prod.protection.outlook.com (10.152.8.60) by AM5EUR02HT199.eop-EUR02.prod.protection.outlook.com (10.152.9.178) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.1304.16; Thu, 3 Aug 2017 19:52:08 +0000 Received: from AM4PR06MB1491.eurprd06.prod.outlook.com (10.152.8.59) by AM5EUR02FT039.mail.protection.outlook.com (10.152.9.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1304.16 via Frontend Transport; Thu, 3 Aug 2017 19:52:08 +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.1304.025; Thu, 3 Aug 2017 19:52:08 +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 v3 1/2] MdePkg/BaseLib: Add IsNodeInList() function. Thread-Index: AQHTDJH9gmDNebNGHE+Aj45jSciTKg== Date: Thu, 3 Aug 2017 19:52:08 +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:E99D727AF0D09966E7C3923A6F5A40140AAED7B61CDA16997D53BC4E3BC60AC4; UpperCasedChecksum:6B7C30B89B484664C11303B5E1F22D45C0F9CA3A5ABC82CE81CF5ACF6DF4BE3E; SizeAsReceived:7252; Count:44 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [w2RQNtxl1BMeLao3TalOiXD3jHj/gP/3] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM5EUR02HT199; 7:FrapG2Oyumre9gKHYDIcqLK/odQ4IRb1a3I4Dkn59fchvv3Rg/qUbNIdOkKUx0PtUK1BxefNzeh0BRvlT3JXlp7gQ4y61yjpNbKFe/j14WuVi6jQWoYj+zqq5YFYjUi4oVxwDuutp9KbKDRlKwz8dfOz6Ga0/WHi+pCRzVm7e+ESyI2CmZEyGivUCKEzf2eU6zo6z8P7Q06uniqa4Ydi3cdZnfnRE6ftlHAxTnue0yrrICt8OfJSnGxFaFAM3uHGlvZd4OFxXlbDC13eVVEYLiRej5zaOewknITcGR0UBtifYTuyO+UPGPwjhgXZJ/B/Eb+FRpJ5Asm34mRZ/44FVMMx6YTgNsz55UGxUvde/qb9549tEO9T6laH/E0tySepRetVU8NfWg8uacxGWMymUv7n7Phz4sTHkXfTLFXp7gnNpkgDEaaCE5+vZQgezPPqQoRR0RllMyk9rlgsiTCFS5XjOw596WsZkWQVbX82ctCBzC3BYP643E9KVsSBIrTw1ir0eZBCtu09MXQZeUDLyrGliHkAGl/IRl+kdVw/F0q645vsmaEcF5Yzo070bc1D5PSAtzBDisElATZxzJ/RJOqvlsu6pWZ4pGPktTz/ujeoF3iUSXFlVLiyC02U5Dnb1mEl87Dc35aNLKBw1rUlsAQ5o6CabDHKdCMJfHGSA7VLXzVDFld+tLocNWImIfUa5s4pwYvxFY09Gldz86Sh7zIHuZPxm/6no9utVbg01+RdOXlSPf7wxRPkP/p4+v8DOrvPfPkVIsPjr1K6D+bHgw== x-incomingheadercount: 44 x-eopattributedmessage: 0 x-forefront-antispam-report: EFV:NLI; SFV:NSPM; SFS:(7070007)(98901004); DIR:OUT; SFP:1901; SCL:1; SRVR:AM5EUR02HT199; H:AM4PR06MB1491.eurprd06.prod.outlook.com; FPR:; SPF:None; LANG:en; x-ms-office365-filtering-correlation-id: 6d033a23-1848-49d6-e509-08d4daa91f1f 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)(2017031322377)(1603101448)(1601125374)(1701031045)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:AM5EUR02HT199; x-ms-traffictypediagnostic: AM5EUR02HT199: 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:AM5EUR02HT199; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:AM5EUR02HT199; x-forefront-prvs: 03883BD916 spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Aug 2017 19:52:08.4001 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5EUR02HT199 Subject: [PATCH v3 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: Thu, 03 Aug 2017 19:50:04 -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. V2: - Rename "List" to "FirstEntry" and "Node" to "SecondEntry" to clarify th= at "FirstEntry" does not need to be the doubly-linked list's head node. V3: - Remove ASSERTs from IsNodeInList() which are present in InternalBaseLibIsListValid(). Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Marvin Haeuser --- MdePkg/Library/BaseLib/LinkedList.c | 66 +++++++++++++++++++- MdePkg/Include/Library/BaseLib.h | 27 ++++++++ MdePkg/Library/BaseLib/BaseLibInternals.h | 28 --------- 3 files changed, 92 insertions(+), 29 deletions(-) diff --git a/MdePkg/Library/BaseLib/LinkedList.c b/MdePkg/Library/BaseLib/L= inkedList.c index ba373f4b7be3..af27b0dd9a5c 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,70 @@ InternalBaseLibIsNodeInList ( } =20 /** + Checks whether FirstEntry and SecondEntry are part of the same doubly-li= nked + list. + + If FirstEntry is NULL, then ASSERT(). + If FirstEntry->ForwardLink is NULL, then ASSERT(). + If FirstEntry->BackLink is NULL, then ASSERT(). + If SecondEntry is NULL, then ASSERT(); + If PcdMaximumLinkedListLength is not zero, and List contains more than + PcdMaximumLinkedListLength nodes, then ASSERT(). + + @param FirstEntry A pointer to a node in a linked list. + @param SecondEntry A pointer to the node to locate. + + @retval TRUE SecondEntry is in the same doubly-linked list as FirstEnt= ry. + @retval FALSE SecondEntry isn't in the same doubly-linked list as First= Entry, + or FirstEntry is invalid. + +**/ +BOOLEAN +EFIAPI +IsNodeInList ( + IN CONST LIST_ENTRY *FirstEntry, + IN CONST LIST_ENTRY *SecondEntry + ) +{ + UINTN Count; + CONST LIST_ENTRY *Ptr; + + // + // ASSERT List not too long + // + ASSERT (InternalBaseLibIsListValid (FirstEntry)); + + ASSERT (SecondEntry !=3D NULL); + + Count =3D 0; + Ptr =3D FirstEntry; + + // + // Check to see if SecondEntry is a member of FirstEntry. =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 SecondEntry); + } + } + + if (Ptr =3D=3D SecondEntry) { + return TRUE; + } + } while (Ptr !=3D FirstEntry); + + 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..40b96b761a85 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -2869,6 +2869,33 @@ PathCleanUpDirectories( =20 =20 /** + Checks whether FirstEntry and SecondEntry are part of the same doubly-li= nked + list. + + If FirstEntry is NULL, then ASSERT(). + If FirstEntry->ForwardLink is NULL, then ASSERT(). + If FirstEntry->BackLink is NULL, then ASSERT(). + If SecondEntry is NULL, then ASSERT(); + If PcdMaximumLinkedListLength is not zero, and List contains more than + PcdMaximumLinkedListLength nodes, then ASSERT(). + + @param FirstEntry A pointer to a node in a linked list. + @param SecondEntry A pointer to the node to locate. + + @retval TRUE SecondEntry is in the same doubly-linked list as FirstEnt= ry. + @retval FALSE SecondEntry isn't in the same doubly-linked list as First= Entry, + or FirstEntry is invalid. + +**/ +BOOLEAN +EFIAPI +IsNodeInList ( + IN CONST LIST_ENTRY *FirstEntry, + IN CONST LIST_ENTRY *SecondEntry + ); + + +/** 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