Hi All


I have use DeviceIoControl to send user mode data to the kernel,
but it wiil crash down when I copy data to Kernal dma buffer,
Does anyone can help this ?? any comment or sample code is wellcome
Thanks a lot

Ps:

I define my CTL_CODE like this

#define IOCTL_SEND_DATA CTL_CODE(MY_TYPE, 0x900, METHOD_IN_DIRECT,
FILE_ANY_ACCES)

and send data like this

DeviceIoControl(hdevice, IOCTL_SEND_DATA, MyParam, MY_LEN, NULL, NULL,
&dwRet, NULL);

Myparam is allocate by (MY_PARAM*) malloc(MY_LEN);

typedef struct _MY_PARAM {
ULONG Channel;
ULONG DataLen;
ULONG Message[1];
} MY_PARAM

#define MY_LEN (sizeof(MY_PARAM)+1024*sizeof(unsigned char))

My Driver code is write as this

KeAcquireSpinLock(&pLDI->DmaSpinLock, &oldIrql);

pMPG = (MY_PARAM*) pIrp->AssociatedIrp.SystemBuffer;

RtlCopyMemory((PULONG)
pLDI->DMABuffers[(pMPG->DmaChannel)].Virtual,pMPG->Message,pMPG->DataLen);---->crash
down here!!!!

KeReleaseSpinLock(&pLDI->DmaSpinLock, oldIrql);

Thanks for you read this letter,Sorry for my poor english^^"""

Re: How to use DeviceIoControl to deliver the user mode data to give the kernel?? by Arkady

Arkady
Thu Mar 17 02:37:14 CST 2005

If you use METHOD_IN_DIRECT you have to receive address of the buffer with
MmGetMdlVirtualAddress ( in PIO MmGetSystemAddressForMdlSafe )
Arkady

<hatepaul@gmail.com> wrote in message
news:1111039808.909893.114960@g14g2000cwa.googlegroups.com...
> Hi All
>
>
> I have use DeviceIoControl to send user mode data to the kernel,
> but it wiil crash down when I copy data to Kernal dma buffer,
> Does anyone can help this ?? any comment or sample code is wellcome
> Thanks a lot
>
> Ps:
>
> I define my CTL_CODE like this
>
> #define IOCTL_SEND_DATA CTL_CODE(MY_TYPE, 0x900, METHOD_IN_DIRECT,
> FILE_ANY_ACCES)
>
> and send data like this
>
> DeviceIoControl(hdevice, IOCTL_SEND_DATA, MyParam, MY_LEN, NULL, NULL,
> &dwRet, NULL);
>
> Myparam is allocate by (MY_PARAM*) malloc(MY_LEN);
>
> typedef struct _MY_PARAM {
> ULONG Channel;
> ULONG DataLen;
> ULONG Message[1];
> } MY_PARAM
>
> #define MY_LEN (sizeof(MY_PARAM)+1024*sizeof(unsigned char))
>
> My Driver code is write as this
>
> KeAcquireSpinLock(&pLDI->DmaSpinLock, &oldIrql);
>
> pMPG = (MY_PARAM*) pIrp->AssociatedIrp.SystemBuffer;
>
> RtlCopyMemory((PULONG)
> pLDI->DMABuffers[(pMPG->DmaChannel)].Virtual,pMPG->Message,pMPG->DataLen);---->crash
> down here!!!!
>
> KeReleaseSpinLock(&pLDI->DmaSpinLock, oldIrql);
>
> Thanks for you read this letter,Sorry for my poor english^^"""
>



Re: How to use DeviceIoControl to deliver the user mode data to give the kernel?? by hatepaul

hatepaul
Thu Mar 17 03:16:51 CST 2005

hi

I see the sample code "IOTCL" , It only use
MmGetSystemAddressForMdlSafe when it access oufbuffer
Does in_buffer also need ?? I have try to change method to
METHOD_BUFFER,it work well in consle mode program but fail in the MFC
program

case IOCTL_SIOCTL_METHOD_IN_DIRECT:

//
// In this type of transfer, the I/O manager allocates a
system buffer
// large enough to accommodatethe User input buffer, sets the
buffer address
// in Irp->AssociatedIrp.SystemBuffer and copies the content of
user input buffer
// into the SystemBuffer. For the user output buffer, the I/O
manager
// probes to see whether the virtual address is readable in the
callers
// access mode, locks the pages in memory and passes the
pointer to
// MDL describing the buffer in Irp->MdlAddress.
//

SIOCTL_KDPRINT(("Called IOCTL_SIOCTL_METHOD_IN_DIRECT\n"));

PrintIrpInfo(Irp);

inBuf = Irp->AssociatedIrp.SystemBuffer;

SIOCTL_KDPRINT(("\tData from User in InputBuffer: "));
PrintChars(inBuf, inBufLength);

//
// To access the output buffer, just get the system address
// for the buffer. For this method, this buffer is intended for
transfering data
// from the application to the driver.
//

buffer = MmGetSystemAddressForMdlSafe(Irp->MdlAddress,
NormalPagePriority);

if(!buffer) {
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
break;
}

SIOCTL_KDPRINT(("\tData from User in OutputBuffer: "));
PrintChars(buffer, outBufLength);

//
// Return total bytes read from the output buffer.
// Note OutBufLength = MmGetMdlByteCount(Irp->MdlAddress)
//

Irp->IoStatus.Information = MmGetMdlByteCount(Irp->MdlAddress);

//
// NOTE: Changes made to the SystemBuffer are not copied
// to the user input buffer by the I/O manager
//

break;


Re: How to use DeviceIoControl to deliver the user mode data to give the kernel?? by Arkady

Arkady
Thu Mar 17 03:55:28 CST 2005

Sure buffered method is safe and prefered for short buffers ( 4K and less )
, try to debug your MFC app , if that work for console that have to work for
MFC app too
Arkady

<hatepaul@gmail.com> wrote in message
news:1111051011.889011.15980@z14g2000cwz.googlegroups.com...
> hi
>
> I see the sample code "IOTCL" , It only use
> MmGetSystemAddressForMdlSafe when it access oufbuffer
> Does in_buffer also need ?? I have try to change method to
> METHOD_BUFFER,it work well in consle mode program but fail in the MFC
> program
>
> case IOCTL_SIOCTL_METHOD_IN_DIRECT:
>
> //
> // In this type of transfer, the I/O manager allocates a
> system buffer
> // large enough to accommodatethe User input buffer, sets the
> buffer address
> // in Irp->AssociatedIrp.SystemBuffer and copies the content of
> user input buffer
> // into the SystemBuffer. For the user output buffer, the I/O
> manager
> // probes to see whether the virtual address is readable in the
> callers
> // access mode, locks the pages in memory and passes the
> pointer to
> // MDL describing the buffer in Irp->MdlAddress.
> //
>
> SIOCTL_KDPRINT(("Called IOCTL_SIOCTL_METHOD_IN_DIRECT\n"));
>
> PrintIrpInfo(Irp);
>
> inBuf = Irp->AssociatedIrp.SystemBuffer;
>
> SIOCTL_KDPRINT(("\tData from User in InputBuffer: "));
> PrintChars(inBuf, inBufLength);
>
> //
> // To access the output buffer, just get the system address
> // for the buffer. For this method, this buffer is intended for
> transfering data
> // from the application to the driver.
> //
>
> buffer = MmGetSystemAddressForMdlSafe(Irp->MdlAddress,
> NormalPagePriority);
>
> if(!buffer) {
> ntStatus = STATUS_INSUFFICIENT_RESOURCES;
> break;
> }
>
> SIOCTL_KDPRINT(("\tData from User in OutputBuffer: "));
> PrintChars(buffer, outBufLength);
>
> //
> // Return total bytes read from the output buffer.
> // Note OutBufLength = MmGetMdlByteCount(Irp->MdlAddress)
> //
>
> Irp->IoStatus.Information = MmGetMdlByteCount(Irp->MdlAddress);
>
> //
> // NOTE: Changes made to the SystemBuffer are not copied
> // to the user input buffer by the I/O manager
> //
>
> break;
>



Re: How to use DeviceIoControl to deliver the user mode data to give the kernel?? by Calvin

Calvin
Thu Mar 17 09:05:51 CST 2005

For METHOD_XXX_DIRECT, inupt buffer is copied to system non-paged pool
(Irp->AssociatedIrp.SystemBuffer), output buffer is double-mapped and
described by Irp->MdlAddress. You use MmGetMdlVirtualAddress to get the
virtual address for DMA API, such as MapTransfer. If you want to
dereference/access the output buffer, use MmGetSystemAddressForMdlSafe.

The OP doesn't have an output buffer so the MDL will be NULL, no point to
use any MmXxxx.

--
Calvin Guan Software Engineer/Radeon NT Drivers
ATI Technologies Inc. Markham ON, Canada www.ati.com


"Arkady Frenkel" <arkadyf@hotmailxdotx.com> wrote in message
news:%23zjC4wsKFHA.3992@TK2MSFTNGP15.phx.gbl...
> If you use METHOD_IN_DIRECT you have to receive address of the buffer with
> MmGetMdlVirtualAddress ( in PIO MmGetSystemAddressForMdlSafe )
> Arkady
>
> <hatepaul@gmail.com> wrote in message
> news:1111039808.909893.114960@g14g2000cwa.googlegroups.com...
> > Hi All
> >
> >
> > I have use DeviceIoControl to send user mode data to the kernel,
> > but it wiil crash down when I copy data to Kernal dma buffer,
> > Does anyone can help this ?? any comment or sample code is wellcome
> > Thanks a lot
> >
> > Ps:
> >
> > I define my CTL_CODE like this
> >
> > #define IOCTL_SEND_DATA CTL_CODE(MY_TYPE, 0x900, METHOD_IN_DIRECT,
> > FILE_ANY_ACCES)
> >
> > and send data like this
> >
> > DeviceIoControl(hdevice, IOCTL_SEND_DATA, MyParam, MY_LEN, NULL, NULL,
> > &dwRet, NULL);
> >
> > Myparam is allocate by (MY_PARAM*) malloc(MY_LEN);
> >
> > typedef struct _MY_PARAM {
> > ULONG Channel;
> > ULONG DataLen;
> > ULONG Message[1];
> > } MY_PARAM
> >
> > #define MY_LEN (sizeof(MY_PARAM)+1024*sizeof(unsigned char))
> >
> > My Driver code is write as this
> >
> > KeAcquireSpinLock(&pLDI->DmaSpinLock, &oldIrql);
> >
> > pMPG = (MY_PARAM*) pIrp->AssociatedIrp.SystemBuffer;
> >
> > RtlCopyMemory((PULONG)
> >
pLDI->DMABuffers[(pMPG->DmaChannel)].Virtual,pMPG->Message,pMPG->DataLen);--
-->crash
> > down here!!!!
> >
> > KeReleaseSpinLock(&pLDI->DmaSpinLock, oldIrql);
> >
> > Thanks for you read this letter,Sorry for my poor english^^"""
> >
>
>



Re: How to use DeviceIoControl to deliver the user mode data to give the kernel?? by Calvin

Calvin
Thu Mar 17 09:14:47 CST 2005

> RtlCopyMemory((PULONG)
>
pLDI->DMABuffers[(pMPG->DmaChannel)].Virtual,pMPG->Message,pMPG->DataLen);--
-->crash
> down here!!!!

What was the pMPG->DataLen? Note that pMPG->DataLen should be SMALLER than
MY_LEN. Also, make sure the DMA buffer size is greater than or equal to
pMPG->DataLen.

--
Calvin Guan Software Engineer/Radeon NT Drivers
ATI Technologies Inc. Markham ON, Canada www.ati.com


<hatepaul@gmail.com> wrote in message
news:1111039808.909893.114960@g14g2000cwa.googlegroups.com...
> Hi All
>
>
> I have use DeviceIoControl to send user mode data to the kernel,
> but it wiil crash down when I copy data to Kernal dma buffer,
> Does anyone can help this ?? any comment or sample code is wellcome
> Thanks a lot
>
> Ps:
>
> I define my CTL_CODE like this
>
> #define IOCTL_SEND_DATA CTL_CODE(MY_TYPE, 0x900, METHOD_IN_DIRECT,
> FILE_ANY_ACCES)
>
> and send data like this
>
> DeviceIoControl(hdevice, IOCTL_SEND_DATA, MyParam, MY_LEN, NULL, NULL,
> &dwRet, NULL);
>
> Myparam is allocate by (MY_PARAM*) malloc(MY_LEN);
>
> typedef struct _MY_PARAM {
> ULONG Channel;
> ULONG DataLen;
> ULONG Message[1];
> } MY_PARAM
>
> #define MY_LEN (sizeof(MY_PARAM)+1024*sizeof(unsigned char))
>
> My Driver code is write as this
>
> KeAcquireSpinLock(&pLDI->DmaSpinLock, &oldIrql);
>
> pMPG = (MY_PARAM*) pIrp->AssociatedIrp.SystemBuffer;
>
> RtlCopyMemory((PULONG)
>
pLDI->DMABuffers[(pMPG->DmaChannel)].Virtual,pMPG->Message,pMPG->DataLen);--
-->crash
> down here!!!!
>
> KeReleaseSpinLock(&pLDI->DmaSpinLock, oldIrql);
>
> Thanks for you read this letter,Sorry for my poor english^^"""
>