From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-oln040092066106.outbound.protection.outlook.com [40.92.66.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 341B620945037 for ; Mon, 24 Jul 2017 09:50:36 -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=4op9impGg4mmqMwqMTesdVJgzenX2sjXTG4M5OBp2xA=; b=laXSzH+PF0HZJ9+AL0PJ5J2DkTXc8t9EuUyx/5LUpZdovZ8rnbGYAEbZehQDRDAaZpblJiT1S0t7wNt0EMFLwKRF1qVNiQuP5sgJLytghlf9gm4b1VrSMy+iy8lOae4JKqjEJqFN3yaee4+QzhMnqP6fX35JV6b0UBTpahAwkB+DafyXCZt03jv36VUkelYlRDq7HnWcNGpfvXN3FJgqWe9uhK4whc0fGUlfvwLFKelMldVi10DDjedGphx+IYTILPPOHysWJFahS0laLEFQ/SupxbtvA+ZdjyqYpahhLCi6hplh5Pbrfs+nSnIXeVwF2HJtkm2UxlzXhndVQU0O1Q== Received: from VE1EUR01FT007.eop-EUR01.prod.protection.outlook.com (10.152.2.58) by VE1EUR01HT163.eop-EUR01.prod.protection.outlook.com (10.152.3.232) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.1240.9; Mon, 24 Jul 2017 16:52:35 +0000 Received: from AM4PR06MB1491.eurprd06.prod.outlook.com (10.152.2.55) by VE1EUR01FT007.mail.protection.outlook.com (10.152.2.88) 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; Mon, 24 Jul 2017 16:52:34 +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; Mon, 24 Jul 2017 16:52:34 +0000 From: =?iso-8859-1?Q?Marvin_H=E4user?= To: "edk2-devel@lists.01.org" CC: "Kinney, Michael D" Thread-Topic: [PATCH 1/2] MdePkg/BaseLib: Add IsNodeInList() function. Thread-Index: AQHTA5vus1udQdORhEegPjUTqWKZfaJjLSJAgAADdaA= Date: Mon, 24 Jul 2017 16:52:34 +0000 Message-ID: References: In-Reply-To: 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:6E1A261B30CF1262403AC6511412388B103859662AFAAF742A91F21B2CAABE2D; UpperCasedChecksum:2DFEF46B64B0AC63AEFF6D5702D76DDC2D49275A465893B0DAE5CACBE6C8C9F7; SizeAsReceived:7454; Count:45 x-tmn: [C32VbDeJmxHrRrwftdIRv02HKiIkLpNDwYR1wUYHb/x0kh3hBbYWhqwTo9vflS2c] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; VE1EUR01HT163; 7:TBgO8ansRS0SX7le0ETzIAQ5UdumwTcSXyFuLQYpkSBE4YYnoOJ0htbVqL6fxd4Us5uUdo17vDxpZdp4GOe6Czqts7lWYEAi2VJsDIJy+t058ib+a/ERnSxgGMSEvYJz6NyHQpkufMg4qSa5UYKOsp7Au7zM4ktU90WhUWD68U4OlOviInEvmUwDhpQpuCBEo6oRUorQhNBtnbBipHm0sT3lFP+brADHbB2f5GtqLGNRBnTRhCoD8qviGpEK/U/XNX9p0SL0si2oUP2QifnT3ybhrmPHQPS1i0VoJpDtUATV0Er+HsrsMj8NNmixrAGrfgNYXD5v+pTZ+/tH9JdJowHVYKKWwYN7Tu8a039UKK9Z/upzLkrTf6fA+qElyNC/Z3AnILlQzrJl73AJklSoYL2e6Mo/A285Nis6a3GgVsO23c3cyCy7NgQvjelZHfsoWrnt5VndmRKal3i3qdtsjj2KIG0/sWdRncXT57adQLw4jyaQD98tzikBv8sT1OBXk8z5qXODBSg9+XaNNG2Hx2SgvOGUxTYTznyWtHzs+BJ3mxB2zONNRfVrYyIyxyVp7/noEh8mxOdI8jbp6NHqLiKmD/fxm7qNJ8f6U50Hwb0PrfY16Wj4A+WriX0ppdKduGvJqsaZTd+PfLshvIQ7+EAUhL36AnebUbT4UhZi7XsfL/GCeBqegjy7uMT+lZpbR1vaTyztTvZW3RKLR6REM9y2JZ3owAGG2HDA8mdWQz9Yj7+uYmF//ufU0wxTIX07AFn9WoOL8ri5X1my2QOYYw== x-incomingheadercount: 45 x-eopattributedmessage: 0 x-forefront-antispam-report: EFV:NLI; SFV:NSPM; SFS:(7070007)(98901004); DIR:OUT; SFP:1901; SCL:1; SRVR:VE1EUR01HT163; H:AM4PR06MB1491.eurprd06.prod.outlook.com; FPR:; SPF:None; LANG:en; x-ms-office365-filtering-correlation-id: bad22bc4-3b2d-4617-e462-08d4d2b461f8 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:VE1EUR01HT163; x-ms-traffictypediagnostic: VE1EUR01HT163: x-exchange-antispam-report-test: UriScan:(189930954265078)(162533806227266)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(444000031); SRVR:VE1EUR01HT163; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:VE1EUR01HT163; x-forefront-prvs: 0378F1E47A spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jul 2017 16:52:34.2927 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1EUR01HT163 Subject: Re: [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: Mon, 24 Jul 2017 16:50:36 -0000 Content-Language: de-DE Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hey Mike, In contrast to setting 'BackLink' and 'ForwardLink' to dummy values such as= EFI_BAD_POINTER, verifying that a node is part of a known list is a safe w= ay to determine whether a link is still valid without needing to keep the m= emory allocated. If the Node, which had its links set to dummys, is freed, = the dummy values may be overwriten and the check would pass despite the nod= e being invalid. This can, for example, be used in OpenKabylake's PchSmiDis= patcher, which does the described check against EFI_BAD_POINTER (though if = I remember correctly, the value is actually never explicitely set). The iss= ue is that some function may pass a handle that was unregistered to the fun= ction. IsNodeInList() can be used to determine whether it was previously re= moved. Thanks for your response! Regards, Marvin. > -----Original Message----- > From: Kinney, Michael D [mailto:michael.d.kinney@intel.com] > Sent: Monday, July 24, 2017 6:31 PM > To: Marvin H=E4user ; edk2- > devel@lists.01.org; Kinney, Michael D > Cc: Gao, Liming > Subject: RE: [PATCH 1/2] MdePkg/BaseLib: Add IsNodeInList() function. >=20 > Hi Marvin, >=20 > Can you provide a few more details on why you would like to see tis inter= nal > function promoted to a library class API? >=20 > Thanks, >=20 > Mike >=20 > > -----Original Message----- > > From: Marvin H=E4user [mailto:Marvin.Haeuser@outlook.com] > > Sent: Sunday, July 23, 2017 3:11 AM > > To: edk2-devel@lists.01.org > > Cc: Kinney, Michael D ; Gao, Liming > > > > Subject: [PATCH 1/2] MdePkg/BaseLib: Add IsNodeInList() function. > > > > 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/LinkedList.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. > > > > - 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 BSD License > > which accompanies this distribution. The full text of the license > > may be found at @@ -113,6 +113,74 @@ InternalBaseLibIsNodeInList ( } > > > > /** > > + 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); > > + > > + // > > + // 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. > > + // Exit early if the number of nodes in List >=3D > > PcdMaximumLinkedListLength > > + // > > + 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 > > pointer to > > the head node of the doubly-linked list. > > > > diff --git a/MdePkg/Include/Library/BaseLib.h > > b/MdePkg/Include/Library/BaseLib.h > > index 791849b80406..4f3f4fd51f3f 100644 > > --- a/MdePkg/Include/Library/BaseLib.h > > +++ b/MdePkg/Include/Library/BaseLib.h > > @@ -2869,6 +2869,31 @@ PathCleanUpDirectories( > > > > > > /** > > + 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 > > pointer to > > the head node of the doubly linked list. > > > > diff --git a/MdePkg/Library/BaseLib/BaseLibInternals.h > > b/MdePkg/Library/BaseLib/BaseLibInternals.h > > index ea387ce37d27..9dca97a0dcc9 100644 > > --- a/MdePkg/Library/BaseLib/BaseLibInternals.h > > +++ b/MdePkg/Library/BaseLib/BaseLibInternals.h > > @@ -340,34 +340,6 @@ InternalSwitchStack ( > > > > > > /** > > - Worker function that locates the Node in the List. > > - > > - By searching the List, finds the location of the Node in List. > > At the same 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 number > > - 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. > > > > Returns the bitfield specified by the StartBit and the EndBit from > > Operand. > > -- > > 2.12.2.windows.2