On Sep 23, 2013, at 4:55 AM, [email protected] wrote:
> Dell - Internal Use - Confidential
>
>
> Hi All,
>
> Below is my code when I run this on my machine it crashes.
>
>
> //
> // Connect All Handles Example
> // The following example recusively connects all controllers in a platform.
> //
> EFI_STATUS Status;
> EFI_BOOT_SERVICES *gBS;
In C a local variable is uninitialized space on the stack. So this statement
makes gBS point to random data on the stack
> UINTN HandleCount;
> EFI_HANDLE *HandleBuffer;
> UINTN HandleIndex;
> gST->ConOut->OutputString (gST->ConOut, L"Code started\n");
Here you try to dereference a bogus pointer and you crash.
> //
> // Retrieve the list of all handles from the handle database
> //
> Status = gBS->LocateHandleBuffer(AllHandles,
> NULL,
> NULL, &HandleCount, &HandleBuffer);
> gST->ConOut->OutputString (gST->ConOut, L"After locate handler\n");
> if (!EFI_ERROR(Status)) {
> gST->ConOut->OutputString (gST->ConOut, L"Got error\n");
> for (HandleIndex = 0; HandleIndex < HandleCount;
> HandleIndex++) {
> Status =
> gBS->ConnectController(HandleBuffer[HandleIndex],
> NULL, NULL, TRUE);
> }
> gBS->FreePool(HandleBuffer);
> }
>
>
> Any Idea why it crashed ??
>
In the edk2 coding style if a variable starts with a lower case g, it is a
global. That means it is defined outside the scope of a function.
In this case gBS is provided by a library. So you code should include the
library via, #include <Library/UefiBootServicesTableLib.h> it has the
definitions required to make you code compile,
https://svn.code.sf.net/p/edk2/code/trunk/edk2/MdePkg/Include/Library/UefiBootServicesTableLib.h.
This will make your code compile, but not link. So you need to add
UefiBootServicesTableLib to the LibraryClassess section of the INF file to link
in the library. The libraries constructors are called prior to the entry point
so that means gBS will be a valid pointer when you use it in your code.
Thanks,
Andrew Fish
>
> Best Regards,
> Parmeshwr Prasad
> Tel : +91-9743262018
> <image001.png>
>
> ------------------------------------------------------------------------------
> LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
> 1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
> 2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
> Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13.
> http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk_______________________________________________
> edk2-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/edk2-devel
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel