Solved

Allocating memory in a device driver

Posted on 1998-06-03
6
722 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
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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…

770 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