From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by mx.groups.io with SMTP id smtpd.web10.9369.1583480328282690605 for ; Thu, 05 Mar 2020 23:38:48 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=h7eQ9qxm; spf=pass (domain: linaro.org, ip: 209.85.221.65, mailfrom: ard.biesheuvel@linaro.org) Received: by mail-wr1-f65.google.com with SMTP id n15so1074625wrw.13 for ; Thu, 05 Mar 2020 23:38:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=sbG04D3nLi65qxf6WI6HMv2LL5J2XBHQUBbq21Z/G0s=; b=h7eQ9qxmUbi1yYu2YxfZ/avgxcfE6UNxe18iuohgZRxh0ddu7oWgdAL+50SMy51yRV Eohz2KSK43scrzMr1kEG4JAmjUKWIFm0PHi67xqfcpeC1R7wS/72O2BN7EXQaaGv2Nmt CEmS+LXVNs8FOzgfb0D8X9Gj+DJ3rglGFlJ5+H4SzystVgN5oLcY3E93k4xY6RNqL8BZ DXqO9gURJnqnVYoMxh7mrw6KjisYa69pMDHN4E9X+bi+P5V4Sf6yIJh3lKeJUseI6FoN Dfm/k8zOWY6FMVOON2oEZP7oY2zJ7qnOFVqM3ITUK1MGoB8AHwu18tbIM7Z+Lxme8fU7 +yWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=sbG04D3nLi65qxf6WI6HMv2LL5J2XBHQUBbq21Z/G0s=; b=bQa21Cvd7z/pr1/YdnGDKxoP3Sm7tpKcsO5LFPy7giukzupQmr9kd+u5TKnnQe6n0X lCnrAG5wmiyUCclcsCiZSNacrhjb6vvH6SAnT4op1GXhQu72Jzs83jdCAae5jzQ/tD5v wywcRvy29hmP2JvSDDXZiHzpMdUSvU2S8KlJpA06PTXCwidPz7XBfappuTNNkWxYfRid UEV3ujUUQjeCgYfSk1a7G0nSJ16FoxcNNC1soo+KaBhFe741+coiB6rZkMgvUQFR4Ip7 ichnCro+gBFadhRVI04tRlL8jqr+swUPHO6SXG/WsAj6rcekI8hr34sUaYVli/EWhXjW YJRg== X-Gm-Message-State: ANhLgQ1H8tOvoDuXyS8/1vhB8Ryo1Saexi0Gv3VPOoP5ROzs3zZWR9tI 26q96tb8PAWEun4zXiXHHzb9JD80yAh0Qw== X-Google-Smtp-Source: ADFU+vseU9JCnNPIcrCEedSjnpgpn+4MQhVW2rFXF9hvkwIg3x+wHDrj4Ih21VfY1P1nYN2XyW6b+g== X-Received: by 2002:adf:ee02:: with SMTP id y2mr2444166wrn.23.1583480326493; Thu, 05 Mar 2020 23:38:46 -0800 (PST) Return-Path: Received: from e123331-lin.home ([2a01:cb1d:112:6f00:816e:ff0d:fb69:f613]) by smtp.gmail.com with ESMTPSA id o5sm13182149wmb.8.2020.03.05.23.38.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2020 23:38:45 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: lersek@redhat.com, Ard Biesheuvel , "Feng, Bob C" Subject: [PATCH] OvmfPkg/QemuKernelLoaderFsDxe: drop tentative const object definition Date: Fri, 6 Mar 2020 08:38:41 +0100 Message-Id: <20200306073841.13528-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 Bob reports that VS2017 chokes on a tentative definition of the const object 'mEfiFileProtocolTemplate', with the following error: OvmfPkg\QemuKernelLoaderFsDxe\QemuKernelLoaderFsDxe.c(130): error C2220: warning treated as error - no 'object' file generated OvmfPkg\QemuKernelLoaderFsDxe\QemuKernelLoaderFsDxe.c(130): warning C4132: 'mEfiFileProtocolTemplate': const object should be initialized Let's turn the only function that relies on this tentative definition into a forward declaration itself, and move its definition after the normal definition of the object. That allows us to drop the tentative definition of the const object, and hopefully make VS2017 happy. Cc: "Feng, Bob C" Signed-off-by: Ard Biesheuvel --- OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c | 134 ++++++++++---------- 1 file changed, 70 insertions(+), 64 deletions(-) diff --git a/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c b/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c index 869549f164f0..fbcdf019bf56 100644 --- a/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c +++ b/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c @@ -123,13 +123,6 @@ typedef struct { #define STUB_FILE_FROM_FILE(FilePointer) \ CR (FilePointer, STUB_FILE, File, STUB_FILE_SIG) -// -// Tentative definition of the file protocol template. The initializer -// (external definition) will be provided later. -// -STATIC CONST EFI_FILE_PROTOCOL mEfiFileProtocolTemplate; - - // // Protocol member functions for File. // @@ -181,65 +174,10 @@ StubFileOpen ( IN CHAR16 *FileName, IN UINT64 OpenMode, IN UINT64 Attributes - ) -{ - CONST STUB_FILE *StubFile; - UINTN BlobType; - STUB_FILE *NewStubFile; - + ); // - // We're read-only. + // Forward declaration. // - switch (OpenMode) { - case EFI_FILE_MODE_READ: - break; - - case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE: - case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE: - return EFI_WRITE_PROTECTED; - - default: - return EFI_INVALID_PARAMETER; - } - - // - // Only the root directory supports opening files in it. - // - StubFile = STUB_FILE_FROM_FILE (This); - if (StubFile->BlobType != KernelBlobTypeMax) { - return EFI_UNSUPPORTED; - } - - // - // Locate the file. - // - for (BlobType = 0; BlobType < KernelBlobTypeMax; ++BlobType) { - if (StrCmp (FileName, mKernelBlob[BlobType].Name) == 0) { - break; - } - } - if (BlobType == KernelBlobTypeMax) { - return EFI_NOT_FOUND; - } - - // - // Found it. - // - NewStubFile = AllocatePool (sizeof *NewStubFile); - if (NewStubFile == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - NewStubFile->Signature = STUB_FILE_SIG; - NewStubFile->BlobType = (KERNEL_BLOB_TYPE)BlobType; - NewStubFile->Position = 0; - CopyMem (&NewStubFile->File, &mEfiFileProtocolTemplate, - sizeof mEfiFileProtocolTemplate); - *NewHandle = &NewStubFile->File; - - return EFI_SUCCESS; -} - /** Closes a specified file handle. @@ -797,6 +735,74 @@ STATIC CONST EFI_FILE_PROTOCOL mEfiFileProtocolTemplate = { NULL // FlushEx, revision 2 }; +STATIC +EFI_STATUS +EFIAPI +StubFileOpen ( + IN EFI_FILE_PROTOCOL *This, + OUT EFI_FILE_PROTOCOL **NewHandle, + IN CHAR16 *FileName, + IN UINT64 OpenMode, + IN UINT64 Attributes + ) +{ + CONST STUB_FILE *StubFile; + UINTN BlobType; + STUB_FILE *NewStubFile; + + // + // We're read-only. + // + switch (OpenMode) { + case EFI_FILE_MODE_READ: + break; + + case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE: + case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE: + return EFI_WRITE_PROTECTED; + + default: + return EFI_INVALID_PARAMETER; + } + + // + // Only the root directory supports opening files in it. + // + StubFile = STUB_FILE_FROM_FILE (This); + if (StubFile->BlobType != KernelBlobTypeMax) { + return EFI_UNSUPPORTED; + } + + // + // Locate the file. + // + for (BlobType = 0; BlobType < KernelBlobTypeMax; ++BlobType) { + if (StrCmp (FileName, mKernelBlob[BlobType].Name) == 0) { + break; + } + } + if (BlobType == KernelBlobTypeMax) { + return EFI_NOT_FOUND; + } + + // + // Found it. + // + NewStubFile = AllocatePool (sizeof *NewStubFile); + if (NewStubFile == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + NewStubFile->Signature = STUB_FILE_SIG; + NewStubFile->BlobType = (KERNEL_BLOB_TYPE)BlobType; + NewStubFile->Position = 0; + CopyMem (&NewStubFile->File, &mEfiFileProtocolTemplate, + sizeof mEfiFileProtocolTemplate); + *NewHandle = &NewStubFile->File; + + return EFI_SUCCESS; +} + // // Protocol member functions for SimpleFileSystem. -- 2.17.1