MmAllocateContiguousMemorySpecifyCache() failed on Windows 10

Hello,
I wrote a driver on windows 10 build 10586 x64, however MmAllocateContiguousMemorySpecifyCache() always fails.

ULONG size = 0x1000;
PHYSICAL_ADDRESS l1, l2, l3;
l1.QuadPart = 0;
l2.QuadPart = -1;
l3.QuadPart = 0x200000;

Address = MmAllocateContiguousMemorySpecifyCache(size, l1, l2, l3, MmCached);

Sometimes the OS crashes here, but most time the function returns NULL.

Then I made a test:

Address = MmAllocateContiguousMemorySpecifyCache(size, l1, l2, l3, MmCached);
if (Address == NULL)
{
Address = MmAllocateContiguousMemory(size, l2);
if(Address == NULL)
{
Address = MmAllocateNonCachedMemory(size);
if (Address == NULL)
return NULL;
}
}

It makes me sad that both of MmAllocateContiguousMemorySpecifyCache() and MmAllocateContiguousMemory() return NULL and MmAllocateNonCachedMemory() succeeds for several times. But sometime MmAllocateNonCachedMemory() crashes, too.

p.s. The same code runs successfully on Windows 8.1/7 x64.

How can I fix this bug in my code?

Do you seriously have variables named like interfere constants?

I had no idea that was possible in C. Regardless, it’s a terrible idea.

Peter
OSR
@OSRDrivers

Emm… It’s better to rename them

After debugging in WinDbg, I noticed where the problem happens.
Since I need to run the code separately on each processor core, I use KeIpiGenericCall() to run a worker on each core.

KeIpiGenericCall(IpiWorker, NULL);

Before IpiWorker() runs, I can allocate any size of memory I want. However since IpiWorker() runs, whatever size of memory I want to allocate easily fails and even causes a system crash.

You did notice the IRQL that the IpiWorker is called at I hope? It is
IPI_LEVEL which is far above the level that you can safely allocate memory.
Running Code Analysis should have caught this.

If you want to do something like this, you are going to need to create your
own thread pool, one for each processor, or loop through changing processor
affinity to do the work in a thread.

Don Burn
Windows Driver Consulting
Website: http://www.windrvr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Thursday, December 31, 2015 10:57 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] MmAllocateContiguousMemorySpecifyCache() failed on
Windows 10

After debugging in WinDbg, I noticed where the problem happens.
Since I need to run the code separately on each processor core, I use
KeIpiGenericCall() to run a worker on each core.

KeIpiGenericCall(IpiWorker, NULL);

Before IpiWorker() runs, I can allocate any size of memory I want. However
since IpiWorker() runs, whatever size of memory I want to allocate easily
fails and even causes a system crash.


NTDEV is sponsored by OSR

Visit the list online at:
http:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software
drivers!
Details at http:

To unsubscribe, visit the List Server section of OSR Online at
http:</http:></http:></http:>

xxxxx@gmail.com wrote:

Hello,
I wrote a driver on windows 10 build 10586 x64, however MmAllocateContiguousMemorySpecifyCache() always fails.

ULONG size = 0x1000;
PHYSICAL_ADDRESS l1, l2, l3;
l1.QuadPart = 0;
l2.QuadPart = -1;
l3.QuadPart = 0x200000;

Address = MmAllocateContiguousMemorySpecifyCache(size, l1, l2, l3, MmCached);

Is that just an experiment, or is this really your requirement? If all
you need is one page of memory, just use ExAllocatePool. A single page
will ALWAYS be contiguous, by definition. Contiguous is only an issue
if you need multiple pages.

And where did the 2-megabyte alignment figure come from?


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

On Thu, Dec 31, 2015 at 9:39 AM, wrote:

> interfere constants

I give up, what phone keyboard mangling produced “interfere constants”, and
what did you actually mean?

Mark Roddy

xxxxx@osr.com wrote:

Do you seriously have variables named like interfere constants?

I’m guessing your phone helpfully corrected “integer constants”. The
variables are L1 L2 and L3, lower case. Not 11, 12, 13. Still a
terrible idea, for the very reason you’ve demonstrated here.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Ah thanks. And yes lower case L is hard on the eyes. And happy new year!

Mark Roddy

On Thu, Dec 31, 2015 at 1:39 PM, Tim Roberts wrote:

> xxxxx@osr.com wrote:
> > Do you seriously have variables named like interfere constants?
>
> I’m guessing your phone helpfully corrected “integer constants”. The
> variables are L1 L2 and L3, lower case. Not 11, 12, 13. Still a
> terrible idea, for the very reason you’ve demonstrated here.
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at: <
> http://www.osronline.com/showlists.cfm?list=ntdev&gt;
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and
> software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at <
> http://www.osronline.com/page.cfm?name=ListServer&gt;
></http:>

You know… I really MUST be MUCH more careful when I post from my iPad while lying on the couch.

Sorry about the miserable garble of those last couple of messages.

Damn you, auto-correct! http:</http:>

Peter
OSR
@OSRDrivers

It is high time to have Gadget(s) that would market as - No random ads, and no auto correct… Or the marketing line should be “ Sorry for not including random ads and auto correct feature!. But give it a try, you might like it”

Happy new year to all!
Pro

On Jan 1, 2016, at 2:12 PM, xxxxx@osr.com wrote:

You know… I really MUST be MUCH more careful when I post from my iPad while lying on the couch.

Sorry about the miserable garble of those last couple of messages.

Damn you, auto-correct! http:</http:>

Peter
OSR
@OSRDrivers


NTDEV is sponsored by OSR

Visit the list online at: http:
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:>

On 1/1/16 3:52 PM, Prokash Sinha wrote:

It is high time to have Gadget(s) that would market as - No random ads, and no auto correct… Or the marketing line should be “ Sorry for not including random ads and auto correct feature!. But give it a try, you might like it”

Or, people who don’t like auto-correct could simply click a few buttons
and make it go away :slight_smile:

(For iOS that’s Settings -> General -> Keyboard -> Auto-Correction)


Bruce

Yeah Bruce!

In the past the paradigm was Garbage In is Garbage out. Now Good things in, Garbage out !. The default settings should be to not Auto Correct, and perhaps a friendly notification to enable it, and disable it right from edit control if it does not do the job. I’ve hard so many complains ( including mine). Particularly in SMS ( with lots of abbreviations etc.) what if some one has a spell mistake, does it matters?. But if I type without paying attention, the Auto Correct can be quite rubbish …
-Pro

On Jan 1, 2016, at 4:58 PM, Bruce Cran wrote:
>
> On 1/1/16 3:52 PM, Prokash Sinha wrote:
>> It is high time to have Gadget(s) that would market as - No random ads, and no auto correct… Or the marketing line should be “ Sorry for not including random ads and auto correct feature!. But give it a try, you might like it”
>
> Or, people who don’t like auto-correct could simply click a few buttons and make it go away :slight_smile:
>
> (For iOS that’s Settings -> General -> Keyboard -> Auto-Correction)
>
> –
> Bruce
>
>
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at: http:
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:>

OT but at least autocorrect could freaking LEARN from manual de-corrections.

Mark Roddy

On Fri, Jan 1, 2016 at 8:58 PM, Prokash Sinha wrote:

> Yeah Bruce!
>
> In the past the paradigm was Garbage In is Garbage out. Now Good things
> in, Garbage out !. The default settings should be to not Auto Correct, and
> perhaps a friendly notification to enable it, and disable it right from
> edit control if it does not do the job. I’ve hard so many complains (
> including mine). Particularly in SMS ( with lots of abbreviations etc.)
> what if some one has a spell mistake, does it matters?. But if I type
> without paying attention, the Auto Correct can be quite rubbish …
> -Pro
>
> > On Jan 1, 2016, at 4:58 PM, Bruce Cran wrote:
> >
> > On 1/1/16 3:52 PM, Prokash Sinha wrote:
> >> It is high time to have Gadget(s) that would market as - No random ads,
> and no auto correct… Or the marketing line should be “ Sorry for not
> including random ads and auto correct feature!. But give it a try, you
> might like it”
> >
> > Or, people who don’t like auto-correct could simply click a few buttons
> and make it go away :slight_smile:
> >
> > (For iOS that’s Settings -> General -> Keyboard -> Auto-Correction)
> >
> > –
> > Bruce
> >
> >
> >
> >
> > —
> > NTDEV is sponsored by OSR
> >
> > Visit the list online at: <
> http://www.osronline.com/showlists.cfm?list=ntdev&gt;
> >
> > MONTHLY seminars on crash dump analysis, WDF, Windows internals and
> software drivers!
> > Details at http:
> >
> > To unsubscribe, visit the List Server section of OSR Online at <
> http://www.osronline.com/page.cfm?name=ListServer&gt;
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at: <
> http://www.osronline.com/showlists.cfm?list=ntdev&gt;
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and
> software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at <
> http://www.osronline.com/page.cfm?name=ListServer&gt;
></http:></http:>

Still OT, but I think SwiftKey (https://swiftkey.com/en) does.


Bruce
Sent from my iPad

On Jan 2, 2016, at 09:12, Mark Roddy wrote:
>
> OT but at least autocorrect could freaking LEARN from manual de-corrections.
>
> Mark Roddy
>
>> On Fri, Jan 1, 2016 at 8:58 PM, Prokash Sinha wrote:
>> Yeah Bruce!
>>
>> In the past the paradigm was Garbage In is Garbage out. Now Good things in, Garbage out !. The default settings should be to not Auto Correct, and perhaps a friendly notification to enable it, and disable it right from edit control if it does not do the job. I’ve hard so many complains ( including mine). Particularly in SMS ( with lots of abbreviations etc.) what if some one has a spell mistake, does it matters?. But if I type without paying attention, the Auto Correct can be quite rubbish …
>> -Pro
>>
>> > On Jan 1, 2016, at 4:58 PM, Bruce Cran wrote:
>> >
>> > On 1/1/16 3:52 PM, Prokash Sinha wrote:
>> >> It is high time to have Gadget(s) that would market as - No random ads, and no auto correct… Or the marketing line should be “ Sorry for not including random ads and auto correct feature!. But give it a try, you might like it”
>> >
>> > Or, people who don’t like auto-correct could simply click a few buttons and make it go away :slight_smile:
>> >
>> > (For iOS that’s Settings -> General -> Keyboard -> Auto-Correction)
>> >
>> > –
>> > Bruce
>> >
>> >
>> >
>> >
>> > —
>> > NTDEV is sponsored by OSR
>> >
>> > Visit the list online at: http:
>> >
>> > MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
>> > Details at http:
>> >
>> > To unsubscribe, visit the List Server section of OSR Online at http:
>>
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> Visit the list online at: http:
>>
>> MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
>> Details at http:
>>
>> To unsubscribe, visit the List Server section of OSR Online at http:
>
> — NTDEV is sponsored by OSR Visit the list online at: MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers! Details at To unsubscribe, visit the List Server section of OSR Online at</http:></http:></http:></http:></http:></http:>