questions regarding MDL

Hi

I have few doubts regarding MDLs

I am sharing memory between driver and user mode application with
IoAllocateMDL,MmProbeAndLockPages,MmMapLockedPagesSpecifyCache this
sequence ofAPIS. Is it necessary to lock the physical pages contained in
MDL before mapping to user space? What can happen if I map it without
locking ?

Can we unlock the pages described by MDL before un-mapping it ?

If answer to previous question is yes - If we can unlock without un-mapping
those and later lock the MDL again, Will MDL have different set of pages
than it had earlier ?

If answer to previous question is yes - If the MDL have different set of
pages, will mapped user memory point to same physical pages that are
described by the MDL currently not earlier ?

Thanking in advance

Regards,
James

> I am sharing memory between driver and user mode application

with IoAllocateMDL,MmProbeAndLockPages,MmMapLockedPagesSpecifyCache

Do you mean that you allocate memory in kernel and then map it into the user address space?
Please note that this design is incredibly poor due to the security holes that it opens. If you really need to share memory between app and driver, you should allocate it in the UM.

Is it necessary to lock the physical pages contained in MDL before mapping to user space?

Well, pages, apparently, have to be locked even if you never access them at elevated IRQL- otherwise, you may just get a discrepancy if they get swapped to the disk (after all, the system does not know that you share pages - you don’t use them as a section, do you). The only thing I am not 100% sure about is whether you have to do it explicitly - after all, documentation makes it clear that, first, a call to MmMapLockedPagesSpecifyCache() with UserMode as an ‘Access’ parameter has to be enclosed in try/except block because it may throw exceptions, and, second, that it cannot be made at elevated IRQL (which is understandable, taking into consideration the above). Judging from the above mentioned description, it looks like MmMapLockedPagesSpecifyCache() just calls MmProbeAndLockPages() behind the scenes if UserMode is specified. Disassemble the OS and check how it all works…

What can happen if I map it without locking ?

I think the system will just lock them anyway…

Can we unlock the pages described by MDL before un-mapping it ?

I think that you can just get a discrepancy if pages that you want to share this way get swapped to the disk…

Anton Bassov

An MDL describes the physical pages that a buffer takes up. There’s not really any such thing as an unlocked MDL.

An MDL that hasn’t been locked is just a buffer pointer and length. You can’t map it and you can’t share it.

If you need to share paged memory between multiple processes then you need a mapped section object. These setup the necessary prototype PTEs so that everyone mapping a particular physical page can stay in sync when that page is swapped out to disk and then swapped back into a different physical page. Without the prototype PTE there’s no way for process A and process B to ensure that they’re both pointing at the same page without keeping that page locked.

-p

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of James Thompson
Sent: Friday, March 07, 2008 12:53 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] questions regarding MDL

Hi

I have few doubts regarding MDLs

I am sharing memory between driver and user mode application with IoAllocateMDL,MmProbeAndLockPages,MmMapLockedPagesSpecifyCache this sequence ofAPIS. Is it necessary to lock the physical pages contained in MDL before mapping to user space? What can happen if I map it without locking ?

Can we unlock the pages described by MDL before un-mapping it ?

If answer to previous question is yes - If we can unlock without un-mapping those and later lock the MDL again, Will MDL have different set of pages than it had earlier ?

If answer to previous question is yes - If the MDL have different set of pages, will mapped user memory point to same physical pages that are described by the MDL currently not earlier ?

Thanking in advance

Regards,
James

— 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

This is really off topic, but I’m always interested in linguistic
things…

Up to this point, I thought that the words “doubt” and “question” were
only synonyms in Indian English dialects. Is this moving beyond
India?

Thanks,
Jake


“James Thompson” wrote in message
news:xxxxx@ntdev…
Hi

I have few doubts regarding MDLs

(non-lingustically interesting content deleted)

> sequence ofAPIS. Is it necessary to lock the physical pages contained in

MDL before mapping to user space?

Yes.

Can we unlock the pages described by MDL before un-mapping it ?

No.


Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

>> s it necessary to lock the physical pages contained in

> MDL before mapping to user space?

Yes.

Why does MmMapLockedPagesSpecifyCache() throw an exception then??? I think it just
locks pages behind the scenes when UserMode is specified, so that its behavior becomes
identical to that of MmProbeAndLockPages()…

> Can we unlock the pages described by MDL before un-mapping it ?

No

Well, you can - the only question is what “result” you are going to achieve…

Anton Bassov

Jake Oshins wrote:

Up to this point, I thought that the words “doubt” and “question” were
only synonyms in Indian English dialects. Is this moving beyond India?

No, of course not. “James” is really an Indian guy. In fact, by his own previous admission, he’s posting with an alias that his outsourcing company itself provided him, ostensibly to hide the fact that they don’t know jack squat about drivers.

For example, see this thread where he was waiting on an event at DISPATCH_LEVEL and I called him out about his “alias”:

http://groups.google.com/group/microsoft.public.development.device.drivers/browse_thread/thread/437f23e909a9e91b

I’m more interested in knowing how the heck one can use “doubt” instead of
“question” in any dialects of english. I admit that I’m not good either in
this spectrum, but the english in India should be the British english…

Here I think, this has something to do with OP being scared to admit that
“(s)he does not know something and ask a straight question” … But I could
be very wrong here …

A while ago, I was reading a book by Knuth, where he mentioned the word
“cool”. And he went on to explain his reaction when he heard first few times
and then realized that “neat” should be more of his style … BUT, “doubt”
for a “question” will make lot of people throwup …

-pro

----- Original Message -----
From:
To: “Windows System Software Devs Interest List”
Sent: Saturday, March 08, 2008 8:14 AM
Subject: RE:[ntdev] questions regarding MDL

> Jake Oshins wrote:
>
>> Up to this point, I thought that the words “doubt” and “question” were
>> only synonyms in Indian English dialects. Is this moving beyond India?
>
> No, of course not. “James” is really an Indian guy. In fact, by his own
> previous admission, he’s posting with an alias that his outsourcing
> company itself provided him, ostensibly to hide the fact that they don’t
> know jack squat about drivers.
>
> For example, see this thread where he was waiting on an event at
> DISPATCH_LEVEL and I called him out about his “alias”:
>
> http://groups.google.com/group/microsoft.public.development.device.drivers/browse_thread/thread/437f23e909a9e91b
>
> —
> 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

> I’m more interested in knowing how the heck one can use “doubt” instead of

“question” in any dialects of english.

My English is even worse then the Indians speak, but for me, this is rather
clear.

“Doubt” means - “I’m uncertain”.
“Question” means nearly the same - “I’m uncertain and what to clarify”.

So, in the context of the forum’s request for clarification, both words can be
used.


Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

No. No native speaker of U.S. English would express a question with the
word ‘doubt’ being used to replace the question sentence format. You might
‘doubt’ that something someone said to you is correct, complete, or not
pertinent. You would express that you have doubts and then ask a follow up
question.

You ask a question about how to handle IRPs when your cancel routine is
called. If you get an answer that might be too simplistic or incomplete you
might have doubts about the answer but that leads to more questions. If you
are uneducated about the subject under discussion you might not have a
question but then might express your doubts about the completeness,
correctness, or applicability to the subject at hand. You would then leave
it there or just ask a general question such as: “I don’t get this at all,
can you explain it in simpler terms or with simple examples?”.

Look at: http://www.selfknowledge.com/28644.htm where doubt is associated
with belief, in many cases it has to do with religion, but not exclusively.

If someone says ‘bonnet’ in the U.S. most people think of Easter Sunday. In
England they think of cars.

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
>> I’m more interested in knowing how the heck one can use “doubt” instead
>> of
>> “question” in any dialects of english.
>
> My English is even worse then the Indians speak, but for me, this is
> rather
> clear.
>
> “Doubt” means - “I’m uncertain”.
> “Question” means nearly the same - “I’m uncertain and what to clarify”.
>
> So, in the context of the forum’s request for clarification, both words
> can be
> used.
>
> –
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>

> No native speaker of U.S. English would express a question with the word ‘doubt’

being used to replace the question sentence format.

It sounds like really exciting technical discussion that is directly related to Windows kernel programming - (question==doubt)?TRUE:FALSE;

Anton Bassov

Linguistics is actually a very interesting subject, and agree it’s not
directly related to doing Windows kernel development.

On the other hand, sometimes having meta discussions about the communication
process that happens on this list could improve the quality and satisfaction
of communication on this list. What we actually do on this list is
“communicate about kernel development”, the actual “kernel development”
occurs (probably inside our head) while we look at source code or the
debugger.

Jan

> No native speaker of U.S. English would express a question
with the word ‘doubt’
> being used to replace the question sentence format.

It sounds like really exciting technical discussion that is
directly related to Windows kernel programming -
(question==doubt)?TRUE:FALSE;

It’s certainly no worse than the thread that degenerated in to a
discussion about the role of divinity in the design of x86 assembler
syntax, my personal favorite. I’m serious; as long as they are
conducted in the proper spirit, I enjoy things like this. Discussions
about INF syntax are only so interesting, for example. That being said,
considering the discussions that we have had about and reactions to
‘thread hijacking’ in the past two months or so, I can understand
Anton’s sentiment here.

mm

Jan Bottorff wrote:

Linguistics is actually a very interesting subject, and agree it’s not
directly related to doing Windows kernel development.

On the other hand, sometimes having meta discussions about the communication
process that happens on this list could improve the quality and satisfaction
of communication on this list. What we actually do on this list is
“communicate about kernel development”, the actual “kernel development”
occurs (probably inside our head) while we look at source code or the
debugger.

Jan

>> No native speaker of U.S. English would express a question
> with the word ‘doubt’
>> being used to replace the question sentence format.
> It sounds like really exciting technical discussion that is
> directly related to Windows kernel programming -
> (question==doubt)?TRUE:FALSE;

> “communicate about kernel development”, the actual “kernel development”

occurs (probably inside our head) while we look at source code or the
debugger.

No, when we look at things like !analyze -v or !devobj or “dd” in the debugger
:slight_smile:


Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

>> No native speaker of U.S. English would express a question with the

> word ‘doubt’
> being used to replace the question sentence format.

I disagree with this on the grounds that it assumes that Indians are
never native English speakers. There are a whole lot of Indians who
are, and an entire dialect has arisen that is native to India. It’s
no less a native dialect than the various American English dialects
are, and it may have as many native speakers as those American
dialects do (given that there are more than a billion* Indians.) In
that dialect, spoken between native speakers, “question” and “doubt”
are often synonyms.

  • Jake

* Note that I’m using “billion” in the sense that my American English
dialect deems correct. The proper usage in England would be (to my
understanding) “a thousand million.” In England, a “billion” is what
we in America would think of a “million million.”

Jake,

You really got me lost here! You probably have reason to belive that way,
and perhaps you studied more on this sphare than what I know and what I’ve
seen so far …

I would go something along this line though …

First what is the literacy rate in India ( and if we want to have a
statewide breakdown then for each state ). Here I mean to say those who can
read ( and perhaps write ) in their own language(s), and this is not
english…

Then I would go about ‘out of all those literate people’ how many have
english as first language ( what I mean by this that how many of them
regulary speak/read/write in english as their main means of communication ).
And finally I would go about ‘how many of those native english speaker(s) go
on to technical areas as engineering and science’…

If you factor all of these, you would be surprised how little would be the
percentage figure …

I would be surprised if the overall literacy rate is more than 10 %. So in a
roughly 1,200,000,000 population we get about 120,000,000. Out of these, not
even 1% have their ( great grand parents, grand parents, parents are native
english speaker :-), so I would knock off another two digits, that gets us
to 1,200,000. Most of these people are from Missionary or other schools
where medium of instruction/communications etc. are indeed in english…

How many of those go for computer science? Very small percentage, since
these people are very high in demand to go for Business schools, public
relations ( administrative / foreign / and other services ), media and
entertainment related jobs where compensation and perhaps the life style
believed to be better …

So I would be surprised, if someone from those background ( who could say
that english is their first language ) and the dialects permits to
interchange ‘doubt’ with ‘question’…

-pro

And finally guess how many are in Windows driver/kernel programming???
----- Original Message -----
From: “Jake Oshins”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Sunday, March 09, 2008 5:00 PM
Subject: Re:[ntdev] questions regarding MDL

>>> No native speaker of U.S. English would express a question with the word
>>> ‘doubt’
>>> being used to replace the question sentence format.
>>
>
> I disagree with this on the grounds that it assumes that Indians are never
> native English speakers. There are a whole lot of Indians who are, and an
> entire dialect has arisen that is native to India. It’s no less a native
> dialect than the various American English dialects are, and it may have as
> many native speakers as those American dialects do (given that there are
> more than a billion* Indians.) In that dialect, spoken between native
> speakers, “question” and “doubt” are often synonyms.
>
> - Jake
>
> * Note that I’m using “billion” in the sense that my American English
> dialect deems correct. The proper usage in England would be (to my
> understanding) “a thousand million.” In England, a “billion” is what we
> in America would think of a “million million.”
>
>
>
>
> —
> 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

I get your point, and thanks for educating me. The answer, for me, by
the way, is that I’ve worked with at least two Indians in NT
kernel-mode development who spoke English as their native language at
birth. Incidentally, both of them grew up in Dubai and had parents
from different regions of India who’s regional languages were
different, which is why their families used English as the common
point.

I’m not sure whether either of them used “question” and “doubt”
interchangeably.

  • Jake

“Prokash Sinha” wrote in message
news:xxxxx@ntdev…
> Jake,
>
> You really got me lost here! You probably have reason to belive that
> way, and perhaps you studied more on this sphare than what I know
> and what I’ve seen so far …
>
> I would go something along this line though …
>
> First what is the literacy rate in India ( and if we want to have a
> statewide breakdown then for each state ). Here I mean to say those
> who can read ( and perhaps write ) in their own language(s), and
> this is not english…
>
> Then I would go about ‘out of all those literate people’ how many
> have english as first language ( what I mean by this that how many
> of them regulary speak/read/write in english as their main means of
> communication ). And finally I would go about ‘how many of those
> native english speaker(s) go on to technical areas as engineering
> and science’…
>
> If you factor all of these, you would be surprised how little would
> be the percentage figure …
>
> I would be surprised if the overall literacy rate is more than 10 %.
> So in a roughly 1,200,000,000 population we get about 120,000,000.
> Out of these, not even 1% have their ( great grand parents, grand
> parents, parents are native english speaker :-), so I would knock
> off another two digits, that gets us to 1,200,000. Most of these
> people are from Missionary or other schools where medium of
> instruction/communications etc. are indeed in english…
>
> How many of those go for computer science? Very small percentage,
> since these people are very high in demand to go for Business
> schools, public relations ( administrative / foreign / and other
> services ), media and entertainment related jobs where compensation
> and perhaps the life style believed to be better …
>
> So I would be surprised, if someone from those background ( who
> could say that english is their first language ) and the dialects
> permits to interchange ‘doubt’ with ‘question’…
>
> -pro
>
> And finally guess how many are in Windows driver/kernel
> programming???
> ----- Original Message -----
> From: “Jake Oshins”
> Newsgroups: ntdev
> To: “Windows System Software Devs Interest List”
>
> Sent: Sunday, March 09, 2008 5:00 PM
> Subject: Re:[ntdev] questions regarding MDL
>
>
>>>> No native speaker of U.S. English would express a question with
>>>> the word ‘doubt’
>>>> being used to replace the question sentence format.
>>>
>>
>> I disagree with this on the grounds that it assumes that Indians
>> are never native English speakers. There are a whole lot of
>> Indians who are, and an entire dialect has arisen that is native to
>> India. It’s no less a native dialect than the various American
>> English dialects are, and it may have as many native speakers as
>> those American dialects do (given that there are more than a
>> billion* Indians.) In that dialect, spoken between native
>> speakers, “question” and “doubt” are often synonyms.
>>
>> - Jake
>>
>> * Note that I’m using “billion” in the sense that my American
>> English dialect deems correct. The proper usage in England would
>> be (to my understanding) “a thousand million.” In England, a
>> “billion” is what we in America would think of a “million million.”
>>
>>
>>
>>
>> —
>> 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

xxxxx@gmail.com wrote

>No, of course not. “James” is really an Indian guy. In fact, by his own
previous admission, he’s posting with an alias that his >>outsourcing
company itself provided him, ostensibly to hide the fact that they don’t
know jack squat about drivers.

> For example, see this thread where he was waiting on an event at
DISPATCH_LEVEL and I called him out about his “alias”:

>
http://groups.google.com/group/microsoft.public.development.device.drivers/browse_thread/thread/437f23e909a9e91bhttp:

I never said I am not an Indian in any of my posts. I even registered with
country as India. But, the above link mentioned by Chris tells that the
person is James Smith. But, I am James Thompson.
If you think using ‘doubt’ word is a mistake, I am sorry for using it.

Regards,
James

On Mon, Mar 10, 2008 at 6:15 AM, Prokash Sinha wrote:

> Jake,
>
> You really got me lost here! You probably have reason to belive that way,
> and perhaps you studied more on this sphare than what I know and what I’ve
> seen so far …
>
> I would go something along this line though …
>
> First what is the literacy rate in India ( and if we want to have a
> statewide breakdown then for each state ). Here I mean to say those who
> can
> read ( and perhaps write ) in their own language(s), and this is not
> english…
>
> Then I would go about ‘out of all those literate people’ how many have
> english as first language ( what I mean by this that how many of them
> regulary speak/read/write in english as their main means of communication
> ).
> And finally I would go about ‘how many of those native english speaker(s)
> go
> on to technical areas as engineering and science’…
>
> If you factor all of these, you would be surprised how little would be the
> percentage figure …
>
> I would be surprised if the overall literacy rate is more than 10 %. So in
> a
> roughly 1,200,000,000 population we get about 120,000,000. Out of these,
> not
> even 1% have their ( great grand parents, grand parents, parents are
> native
> english speaker :-), so I would knock off another two digits, that gets us
> to 1,200,000. Most of these people are from Missionary or other schools
> where medium of instruction/communications etc. are indeed in english…
>
> How many of those go for computer science? Very small percentage, since
> these people are very high in demand to go for Business schools, public
> relations ( administrative / foreign / and other services ), media and
> entertainment related jobs where compensation and perhaps the life style
> believed to be better …
>
> So I would be surprised, if someone from those background ( who could say
> that english is their first language ) and the dialects permits to
> interchange ‘doubt’ with ‘question’…
>
> -pro
>
> And finally guess how many are in Windows driver/kernel programming???
> ----- Original Message -----
> From: “Jake Oshins”
> Newsgroups: ntdev
> To: “Windows System Software Devs Interest List”
> Sent: Sunday, March 09, 2008 5:00 PM
> Subject: Re:[ntdev] questions regarding MDL
>
>
> >>> No native speaker of U.S. English would express a question with the
> word
> >>> ‘doubt’
> >>> being used to replace the question sentence format.
> >>
> >
> > I disagree with this on the grounds that it assumes that Indians are
> never
> > native English speakers. There are a whole lot of Indians who are, and
> an
> > entire dialect has arisen that is native to India. It’s no less a
> native
> > dialect than the various American English dialects are, and it may have
> as
> > many native speakers as those American dialects do (given that there are
> > more than a billion* Indians.) In that dialect, spoken between native
> > speakers, “question” and “doubt” are often synonyms.
> >
> > - Jake
> >
> > * Note that I’m using “billion” in the sense that my American English
> > dialect deems correct. The proper usage in England would be (to my
> > understanding) “a thousand million.” In England, a “billion” is what we
> > in America would think of a “million million.”
> >
> >
> >
> >
> > —
> > 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
>
>
> —
> 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
></http:>

> Note that I’m using “billion” in the sense that my American English dialect deems correct.

The proper usage in England would be (to my understanding) “a thousand million.”
In England, a “billion” is what we in America would think of a “million million.”

In order to realize that you are wrong, all you have to do is to open any English newspaper, so that you will see a term “billion” referring to population, money and everything else that is known to exist in quantities well below “million million” …

Anton Bassov

>>> Is it necessary to lock the physical pages contained in

>> MDL before mapping to user space?

>Yes.

Why does MmMapLockedPagesSpecifyCache() throw an exception then??? I think
it just
locks pages behind the scenes when UserMode is specified, so that its
behavior becomes
identical to that of MmProbeAndLockPages()…

As suggested by Anton, I looked at disassembly and found that
MmMapLockedPagesSpecifyCache is not calling MmProbeAndLockPages and anything
that is locking the pages

> >Can we unlock the pages described by MDL before un-mapping it ?

> No

Well, you can - the only question is what “result” you are going to
achieve…

I tried this and worked fine for me. But, not sure same will happen
consistently.

Regards
James