?
Solved

Allocating memory in a device driver

Posted on 1998-06-03
6
Medium Priority
?
733 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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 400 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

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 …
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

764 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