Solved

Allocating memory in a device driver

Posted on 1998-06-03
6
728 Views
Last Modified: 2013-12-03
I need to allocate memory in a device driver (atapi).
Somebody tell me ExAllocatePool is wrong in a DD isn't it?
So I am trying to use MmAllocateNonCachedMemory.
The problem is that the compiler says it can't found the
function... and if I include "ntddk.h" it founds a lot
of re-declarations... so I can't obtain the memory
and the driver is sttoped.

Can someone help me?
0
Comment
Question by:ern31
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 2

Expert Comment

by:kinkajou
ID: 1406728
Are you including the correct library/.LIB file for MmAllocateNonCachedMemory?
0
 

Author Comment

by:ern31
ID: 1406729
MmAllocateNonCachedMemory is in ntddk.h as far as I know.
If I include it it doesn't link (repeated simbols)... if
I do it links (assuming extern declaration returning int) but
the drives hungs.
Thanks.
0
 
LVL 4

Expert Comment

by:tflai
ID: 1406730
I would suggest you to use ExAllocatePool().  It should be fine.  You can even use NdisAllocateMemory() to allocate non-paged memory.  The problem with redeclaration is probably caused by the order of the include files.  Try have "ntddk.h" as the first header file.
-----from DDK-----
Each call to MmAllocateNonCachedMemory ties up at least a full page of nonpaged system-space memory, whatever the size of the requested allocation. For requests less than a page, any remainder bytes on the page are wasted: inaccessible by the driver that called MmAllocateNonCachedMemory and unusable by other kernel-mode code.

0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

Expert Comment

by:Madorsky
ID: 1406731
How do you compile the driver? Hope you know you should use BUILD utility.
What kind of driver is it (custom, network, printer, ...)?
0
 

Author Comment

by:ern31
ID: 1406732
I have decide it is not posible to allocate dinamic memory in
a device driver (atapi). I compile the driver without any error,
with BUILD of course, but if I use ExAllocate the system crash
(IRQ_LEVEL_NOT_EQUAL...): this is ok (reading DDK it says ExAllocate don't go on device drivers) but if I use MmAllocate
the system crash too (¿?) KERNEL_MODE_EXCEPTION_NOT_HANDLE.
Well there are *NOT* other system calls to allocate memory so
I have decided IT'S NOT POSIBLE IN A D.DRIVER.
Anyway thaks for your help.
0
 

Accepted Solution

by:
Madorsky earned 200 total points
ID: 1406733
Of course it IS possible, I made it a lot of times. Here are the examples:

1.
in DriverEntry:
    LARGE_INTEGER PA;
    PA.QuadPart = 0x00000FFFFFFFFF;
    E->ClearBuf = MmAllocateContiguousMemory
    (
      BLOCKSIZE,
      PA
    );

in DriverUnload:
    MmFreeContiguousMemory (E->ClearBuf);

2.
in DriverEntry:
E->TestBlock = ExAllocatePool( NonPagedPool, 0x2000);

in DriverUnload:
ExFreePool(E->TestBlock);

Try to write the simple driver (for the start), which does nothing but
allocates the memory in DriverEntry and frees it in DriverUnload.
Your problem is probably in the action of the driver, not in the allocation
of the memory.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question