What you assume is what you may get !
Assumption is really a key concept in daily life. Can we really eliminate assumption altogether? That's a question I fight with almost everyday, though not for daily chores outside my profession. In programming, it is extreemly important to know what is/are known and what are not. Hopes sometime lead us to assume ( or belief) about some situation, some context that bite us back later. A very good book to read on this is "How to solve it" by Polya. In almost all science and engineering we contradict hypothesis. And that is to test our hypothethis.
Here is an example of how bad assumptions could be in math -
We were taught that infinity divided by infinity is not one. Since infinity has a mathematical symbol ( often more than one symbol, but that is a different topics altogether) like any other number why it is not true that infinity by infinity equals one. So lets assume that it is one, then contradict it to see what we were taught is indeed true or not.
We know that sum of all natural numbers is infinity. Sum of all even numbers is infinity. Sum of all odd numbers is ... Sum of all numbers that are multiple of something is again infinity.
Now we can argue that sum of all odd numbers and sum of all even numbers must be equal to sum of all numbers, since a number could either be odd or even.
So take inifinity by infinity equals 1, and substitute accordingly you will see 1 is equal to 2, 3 equal to 7, or whatever you imagination drives to.
In windows kernel mode programming, there are lot of places you can not readily assume anything. For example, user context is one. Accessibility of your own allocated memory is another one. In another topic I touched upon process context.
Here, for example if you allocate memory from paged pool, you have to remember that particular memory will not be accessible all the time. It could be paged out by the systems, and if you happen to be in a high irql, and the system thinks your memory is invalid ( i.e. from the paging point of view), it would not be able to page in your memory, and you know what is next... So is the story for any code or data you define for your windows kernel mode programming. By default, all the data and code you write for drivers ( or other kernel module by a third party ) are from non-paged pool. But when you allocate memory from kernel heap, you have a choice to allocate from paged or non-paged pool. If you are not sure how the memory would be access, it is safe and perhaps little bad design, allocate your memory from non-paged pool. Also note that non-paged pool is a limited resources.
Since code sizes are not very dynamic, and it is not very large for kernel modules, it is perhaps okay to have them in non-paged area. Dyanmic memory allocation is different though, so use of judment is essential. Experts often uses several techniques to allocate memory from paged pool, and if there is a need for access at a higher IRQL when makes the request as an work item and queues to be processed at a lower IRQL when paging is allowed.
Reader Comments