[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Allocating memory in a device driver

Posted on 1998-06-03
6
Medium Priority
?
736 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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

656 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