I gave this a new topic because it’s pretty OT and I don’t want to
clutter up the original thread with it.
Quotes are from the “ZwReadFile Speed Problem.” thread.
Hope you guy’s don’t mind.
For non-involved readers: I suggested a recursive sort (quicksort)
and Steve replied recursive sorts should be avoided in the kernel.
Hi Steve,
> Hi Don!
That was me (Steve), actually; don’t blame Don for my rants.
well, er, I’m sorry for that mistake - hope it doesn’t happen again!
(Messed up 2 messages I was answering to)
> (…)
It’s still better to flatten your sort out into a for loop or
something. You leave yourself open to security problems if someone
feeds you a big buffer to sort - it’s a DoS at least.
I ment for really known sizes like when the driver is queuing stuff
in a self-allocated list/array (that has a known & fixed size).
For unknown sizes one can always check the size and decide what
sort-function to use.
> (…)
Depends on where you are in the call stack and how much stack you
allocate in each frame. Remember, the kernel has a fixed 12KB stack. I
guess you could do something goofy with IoGetRemainingStackSize(), but
it’d be better to just use a flat sort IMO.
Actually I thought it was 8K (2 pages), but if you say 12K that leaves me
plenty of room for nasty stuff ![]()
> (…)
Funny you should ask.see above, and also look at
IoGetStackLimits().
Yeah, right, hit me ![]()
Unfortunately the functions you mentioned only work for
IRQL < DISPATCH_LEVEL… (at least DDK says so).
What does one do if one’s executing a DPC or ISR? I mean counting by
hand is really really cumbersome when there are a lot of callbacks
involved… Also I don’t really 100% trust the compiler (c++) to free
stack-space e.g. for nested local scopes in a function right where
the scope ends - especially not for “plain-old-data” variables…
Or is the only possible way saving the value of ESP when entering the
ISR and comparing it to the actual value in every called function?
I mean I’d like to write “flat” code (concerning call-depth), but the
usual “the day before yesterday” deadline really doesn’t help writing
“perfect” code… and most of the time it’s faster to just write some
piece of code and put a lot of ASSERT()s in than to “do the numbers”
on every possibility…
At least I don’t allocate buffers of unknown/non-const size on the
stack ![]()
Regards,
Paul Groke