Solved

Allocating memory in a device driver

Posted on 1998-06-03
6
718 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
Comment Utility
Are you including the correct library/.LIB file for MmAllocateNonCachedMemory?
0
 

Author Comment

by:ern31
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Expert Comment

by:Madorsky
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
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 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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now