BSOD in ExSetFirmwareEnvironmentVariable - Windows 8

Hi All,

I am calling a ExSetFirmwareEnvironmentVariable from my driver to set value of a exsisting variable. This varible is created by an application with attributes (EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_SERVICE).

But call to ExSetFirmwareEnvironmentVariable is producing a BSOD with bugcheck PFN_LIST_CORRUPT (4e).

Arguments:
Arg1: 00000007, A driver has unlocked a page more times than it locked it
Arg2: 0004ac33, page frame number
Arg3: 00000001, current share count
Arg4: 00000000, 0

8eee1924 81400a85 0000004e 00000007 0004ac33 nt!KeBugCheckEx
8eee19a8 8128e8c1 8be00000 8eee1a1c 8eee19f4 nt! ?? ::FNODOBFM::string'+0x1ee4b 8eee19b8 816ed2af 8be00000 31cc09e5 00000000 nt!ExUnlockUserBuffer+0xe 8eee19f4 816580a0 8be00000 8eee1a84 00000000 nt! ?? ::NNGAKEGL::string’+0x6176d
8eee1a20 8165829b 8a517da8 9cebcd00 8a855338 nt!ExpSetFirmwareEnvironmentVariable+0x26
8eee1a48 9cebc6a6 8eee1a78 9cebcd00 8a855338 nt!ExSetFirmwareEnvironmentVariable+0x4b
8eee1a8c 9cebc729 8a855338 00000000 896c4190 testdrv!SetParams+0xce

But if I set the same variable from another usermode application using SetFirmwareEnvironmentVariableEx it works fine.

Can anyone tell me…

  1. Why ExSetFirmwareEnvironmentVariable is producing BSOD while SetFirmwareEnvironmentVariableEx is working fine?

  2. Am I missing something?

I have called the function as follows…
ulAttributes = 0x00000001 | 0x00000002 | 0x00000004/*VARIABLE_ATTRIBUTE_NON_VOLATILE*/;
ulValueLength = sizeof(PARAMETER);
RtlInitUnicodeString(&VariableName, NVRAM_VARIABLE_NAME);
NtStatus = pfnExSetFirmwareEnvironmentVariable(
&VariableName,
&VariableGUID,
pParams,
&ulValueLength,
&ulAttributes
);

Thanks & Regards,
Amit.

A similar problem is disscussed at following thread…
http://www.osronline.com/showthread.cfm?link=229441

But I have’t find any solution over there. Do we have any solution?

I was testing it on 32 bit VM, But now I am testing it on laptop with 64 Windows 8 and result is BSOD.
But this time with bugcheck PAGE_FAULT_IN_NONPAGED_AREA.

Hello,

Pass ulValueLength directly not its address.
i.e do
,
NtStatus = pfnExSetFirmwareEnvironmentVariable(
&VariableName,
&VariableGUID,
pParams,
ulValueLength,
&ulAttributes
);

instead of
,
NtStatus = pfnExSetFirmwareEnvironmentVariable(
&VariableName,
&VariableGUID,
pParams,
&ulValueLength,
&ulAttributes
);

As the API expect the
ValueLength [in]
The size, in bytes, of the data value contained in the Value buffer.

Below is the function prototype from wdm.h.

NTKERNELAPI
NTSTATUS
ExSetFirmwareEnvironmentVariable (
In PUNICODE_STRING VariableName,
In LPGUID VendorGuid,
In_reads_bytes_opt(ValueLength) PVOID Value,
In ULONG ValueLength,
In ULONG Attributes
);

The prototype documented at the following link is incorrect.
http://msdn.microsoft.com/en-us/library/windows/hardware/jj151554(v=vs.85).aspx

Motto : when in doubt ,always refer to the src .
Thanks,
–Rajnish.

On Fri, Sep 28, 2012 at 7:43 AM, wrote:
> I was testing it on 32 bit VM, But now I am testing it on laptop with 64 Windows 8 and result is BSOD.
> But this time with bugcheck PAGE_FAULT_IN_NONPAGED_AREA.
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Hi Rajnish,

Yes you are correct. Now it is working fine.
Thanks for the greate help.

One thing I want to add for other readers is that Attributes is also in parameter so no need to pass address.

Thanks & Regards,
Amit.

I am glad it solved your issue.

Thanks,
–Rc

On Mon, Oct 1, 2012 at 6:45 AM, wrote:
> Hi Rajnish,
>
> Yes you are correct. Now it is working fine.
> Thanks for the greate help.
>
> One thing I want to add for other readers is that Attributes is also in parameter so no need to pass address.
>
> Thanks & Regards,
> Amit.
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

“Rudra ठाकुर” wrote in message news:xxxxx@ntdev…
> Motto : when in doubt ,always refer to the src .

Error: src not found

– pa