public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Andrew Fish <afish@apple.com>
To: GN Keshava <keshava.gn@gmail.com>
Cc: "edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Subject: Re: LocateHandle for gEfiShellProtocolGuid is failing in my application
Date: Wed, 21 Dec 2016 11:13:14 -0800	[thread overview]
Message-ID: <81635FDE-FDD2-4913-B142-A26340D319D6@apple.com> (raw)
In-Reply-To: <CABKwMdswKfz6xi9dw2zZ6yiX9DEQ0rmJf2qzAYrRumu6xpLiig@mail.gmail.com>


> On Dec 20, 2016, at 11:32 PM, GN Keshava <keshava.gn@gmail.com> wrote:
> 
> Hi,
> 
> I'm developing a shell application. A call to LocateHandle for
> gEfiShellProtocolGuid is failing with Status 0x0E.
> 
> Below is my code. Please let me know what I'm doing wrong.
> 

Assuming this is your entire code fragment you are passing 2 uninitialized values 

If you want to probe the size you need to:
BufferSize = 0;

> Status = gBS->LocateHandle(ByProtocol, &gEfiShellProtocolGuid, NULL,
> &BufferSize, Buffer); // Get BufferSize
> if (EFI_ERROR(Status))

Per the spec you would expect to get Status = EFI_BUFFER_TOO_SMALL if you need to grow the size. You should only allocate the buffer and retry if you get EFI_BUFFER_TOO_SMALL. 

You don't handle the case of  EFI_NOT_FOUND.

FYI the error codes are defined in the UEFI Spec and exist here in the code:
https://github.com/tianocore/edk2/blob/master/MdePkg/Include/Base.h <https://github.com/tianocore/edk2/blob/master/MdePkg/Include/Base.h>



///
/// The buffer was not large enough to hold the requested data.
/// The required buffer size is returned in the appropriate
/// parameter when this error occurs.
///
#define RETURN_BUFFER_TOO_SMALL      ENCODE_ERROR (5)


...

///
/// The item was not found.
///
#define RETURN_NOT_FOUND             ENCODE_ERROR (14)


#define ENCODE_ERROR(StatusCode)     ((RETURN_STATUS)(MAX_BIT | (StatusCode)))


MAX_BIT is going to be defined as BIT63 or BIT31 depending on the CPU architecture you are using. 


> Print(L"LocateHandle Status 0x%x\n",Status);
> 
> Status = gBS->AllocatePool(EfiBootServicesData, BufferSize,
> (void**)&Buffer);
> if (EFI_ERROR(Status))
> Print(L"AllocatePool Status 0x%x\n",Status);
> 

I mentioned in the other mail that you can use %r to get a string for the error.

Thanks,

Andrew Fish


> Status = gBS->LocateHandle(ByProtocol, &gEfiShellProtocolGuid, NULL,
> &BufferSize, Buffer);
> if (EFI_ERROR(Status))
> Print(L"LocateHandle Status 0x%x\n",Status);
> 
> All calls failing with Status being 0x0E. Please help me to solve this. Is
> there any special requirement for using this protocol?
> 
> Thanks.
> Regards,
> Keshava
> ___________________________________



  parent reply	other threads:[~2016-12-21 19:13 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-21  7:32 LocateHandle for gEfiShellProtocolGuid is failing in my application GN Keshava
2016-12-21 18:36 ` Carsey, Jaben
2016-12-22  9:35   ` GN Keshava
2016-12-22 10:07     ` GN Keshava
2016-12-22 16:56       ` Carsey, Jaben
2016-12-23  4:06         ` GN Keshava
2016-12-27 23:28           ` Carsey, Jaben
2016-12-28  4:16             ` GN Keshava
2016-12-28 14:56               ` Carsey, Jaben
2016-12-21 18:59 ` Andrew Fish
2016-12-21 19:13 ` Andrew Fish [this message]
2016-12-22  2:00   ` GN Keshava

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=81635FDE-FDD2-4913-B142-A26340D319D6@apple.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox