From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-oln040092065065.outbound.protection.outlook.com [40.92.65.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 431BE2095DB8D for ; Wed, 2 Aug 2017 06:09:43 -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=mVJB5N8Dme/VJxsR6vy7uhyJkYMlsIeDnKdj1gOQ+TM=; b=CaLT0919RByVg2V+ghPldHG6K6MPv/xH1gQi4SbYHpAtlKf9ULurGhZ53flZGeITalU0v0jaJbHdF+H/1lguOtyI5vom345xAaNw8zzfUTDsmo4hYsBkiDnxcfktjPiQdcmbR0LHygNdcW1FZ0ZdGdCL10f6WsjadM6MnL3pqa7v/8Wk5U8TpAlRu564mTyfxXaqu89cKZtTfo5+mqE/h/6uk3cyNGmlYNUGQ7vLxZuwmlDHgXKt3B5ZS7IATYaifdi+M6uhAHyrIvWqTKs4uJgMRuxQd0YBJSbRncW1FwhNsnkZbRsdfNOswCGmevl10yjtoRWPy7iCHdYB42iecA== Received: from VE1EUR01FT035.eop-EUR01.prod.protection.outlook.com (10.152.2.60) by VE1EUR01HT098.eop-EUR01.prod.protection.outlook.com (10.152.3.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.1240.9; Wed, 2 Aug 2017 13:11:51 +0000 Received: from AM4PR06MB1491.eurprd06.prod.outlook.com (10.152.2.58) by VE1EUR01FT035.mail.protection.outlook.com (10.152.2.236) 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; Wed, 2 Aug 2017 13:11:51 +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.023; Wed, 2 Aug 2017 13:11:51 +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 v2 1/2] MdePkg/BaseLib: Add IsNodeInList() function. Thread-Index: AQHTC5Dnj8Z0454Pw0iTEfn92fRUFQ== Date: Wed, 2 Aug 2017 13:11:51 +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:A51E64F568055A5FC9D4EA2083DC9E272B332F0752630862AE88845714023E4E; UpperCasedChecksum:E2005F60F13771BEC00ADA57CDB45617A6120035C4C0C6F8ADD0B9D61757FF0D; SizeAsReceived:7251; Count:44 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [p+gCPlVY8+Kst3Bm0xkHtQAqbSOnK3Zu] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; VE1EUR01HT098; 7:5M6VHSNybyXcPnTvUNpMeVdtjM4JKyWhqqLfuj2Bw3sv9F4y9YgBdpjSLPSnhXk87BpGT8wU3mqwESs1o8aiPa7TDprEKBwIF+Z7mWZ8E4b7Xn55rESV4aRojAQx93NJZouOBw+1RQfrgmIZ/LkObkRUni0TL+hvDY/1FWox5a+MqsomyGdhl9rKQYaeQEZ8Yk1YQXqze2oOnfF93CF0AmmmCDEkZp3s3tBq8c+vaQoor7jUrlBrJi2UNXMzwZWkfGmzaSojHpXCm/sht/eO/+YSo+DVPm8LNxComU+XcQnUEEC2ICBFbXo/0HHeoPV+Oh4qPj3c7sFOsQAl48cLWR94Ad83MKbj44Ne1GhuZNar+bf5UOxz5TzgaliDiKF6osV00raY6aFP6S+0lRGr4tzi8HHut/i5SgBNTqztbTvHUjILsRf//nSCuwHnonQDR+VsFTXj1nMYseG3yXBN74o38IAMcbxq9BKsE2iAJBA5xi3sh+V0TWrvMEg4kNhkcpQWlFfpkPNgQ8D9HuDyWdH9hFpXAk/h8GqTeYp57A453X91/mRufTOpREN9/R53Q/Kv60U1B0rRbJjc/fmHQdxrGqRH8XKLMskbEEK2UWEnCnoLr5jfbI8N/0g//X1OpejwE+loJu17sAu1qSuiJPwm0+1QLhL+v2O6zgRZOBp8HBzpS9BGfNmeCZRCepli8UT6E3yTFk9P2kuISIqZqHX3dbTXGudldNqJvLB+GKoT4ytDQ6priOT9rlSLCF6d2Hq4vl9sCRey2RVUyFcW+Q== x-incomingheadercount: 44 x-eopattributedmessage: 0 x-forefront-antispam-report: EFV:NLI; SFV:NSPM; SFS:(7070007)(98901004); DIR:OUT; SFP:1901; SCL:1; SRVR:VE1EUR01HT098; H:AM4PR06MB1491.eurprd06.prod.outlook.com; FPR:; SPF:None; LANG:en; x-ms-office365-filtering-correlation-id: b29b7415-2302-46a8-f215-08d4d9a809b4 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:VE1EUR01HT098; x-ms-traffictypediagnostic: VE1EUR01HT098: 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:VE1EUR01HT098; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:VE1EUR01HT098; x-forefront-prvs: 0387D64A71 spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Aug 2017 13:11:51.4481 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1EUR01HT098 Subject: [PATCH v2 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: Wed, 02 Aug 2017 13:09:44 -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. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Marvin Haeuser --- MdePkg/Library/BaseLib/LinkedList.c | 72 +++++++++++++++++++- MdePkg/Include/Library/BaseLib.h | 27 ++++++++ MdePkg/Library/BaseLib/BaseLibInternals.h | 28 -------- 3 files changed, 98 insertions(+), 29 deletions(-) diff --git a/MdePkg/Library/BaseLib/LinkedList.c b/MdePkg/Library/BaseLib/L= inkedList.c index ba373f4b7be3..484ee836b8c2 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,76 @@ 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; + + // + // Test the validity of FirstEntry and FirstEntry + // + ASSERT (FirstEntry !=3D NULL); + ASSERT (FirstEntry->ForwardLink !=3D NULL); + ASSERT (FirstEntry->BackLink !=3D NULL); + ASSERT (FirstEntry !=3D NULL); + =20 + // + // ASSERT List not too long + // + ASSERT (InternalBaseLibIsListValid (FirstEntry)); + + 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