chaining and unchaing buffers?? BAD_POOL_CALL?

Hi folks, I wonder if someone could help me?I want to unchain the
first buffer from the packet, chain my own buffer at front and then
chain the original buffer at front again. I would end up with my
buffer inserted between the first and second buffers in the original
packet.

I am using the following code to do this in MPSend( ). It is in the
w2k ddk’s passthru sample. Here 'originalPacket¡¯ is the packet to
be sent, 'firstBuffer¡¯ is first buffer in that packet and
‘myBuffer’ is the buffer I construct and want to insert in the packet.

NdisAllocateBufferPool(&myStatus,&myBufferPool,3);

if(myStatus==NDIS_STATUS_SUCCESS){

NdisAllocateMemoryWithTag(&myBaseAddress,60,‘toor’);
NdisAllocateBuffer(&myStatus,&myBuffer,myBufferPool,myBaseAddress,14);

if(myStatus==NDIS_STATUS_SUCCESS){
NdisQueryBuffer(myBuffer,&myVirtualAddress,&myLength);
if(myBuffer){
//I write my own buffer here
NdisUnchainBufferAtFront(originalPacket,&firstBuffer);
if(firstBuffer){
NdisChainBufferAtFront(originalPacket,myBuffer);
NdisChainBufferAtFront(originalPacket,firstBuffer);
}
}
}
}

However this gives a blue screen with the error 'BAD_POOL_CALL¡¯.
What am I doing wrong.Any help would be much appreciated. Thanks in
advance
Regards,
Yasser

P.S I get the same error when I try to chain a buffer at the back.


MSN 8 helps eliminate e-mail viruses. Get 3 months FREE*.
http://join.msn.com/?page=features/virus&xAPID=42&PS=47575&PI=7324&DI=7474&SU=
http://www.hotmail.msn.com/cgi-bin/getmsg&HL=1216hotmailtaglines_virusprotection_3mf

What exactly are you trying to do? There are several problems:

  • if you want to change packet contents some way (which way?), you must not
    depend on buffers size and number chained by above driver. The only thing
    you can use is packet contents. If you want to change contents, you have to
    use own buffers and copy necessary data. For example tcpip.sys may use the
    first buffer for MAC header and next one for IP header. This can be true for
    all NT like OSes but when another IM driver is installed, the assumption can
    be broken. For example I wrote a driver years ago which used one buffer for
    whole (encrypted) packet under some circumstances. Also, the assumption can
    be broken in the next SP.

  • you should take original packet descriptor as read only and never change
    it. Instead, you should allocate a new descriptor and chain buffers there.
    If you don’t for some reason, you should at least restore descriptor to
    original state (including buffers chain) before returning it to above
    driver. Be aware returning has another meaning when NdisSend returns pending
    status.

Please note what passthru does in MPSend is special case. Buffers chained to
original descriptor are chained again to a new one. This is good for
performance reason but works only if nothing is changed in packet. If a new
buffer is added in the middle of chain, bad things happen (well, as I
already stated, it shouldn’t be done).

I guess you return changed descriptor to above driver, it tries to do
something with buffer you have allocated because doesn’t expect it (for
example, frees it) and causes memory corruption. Buffer can be freed twice
this way.

Best regards,

Michal Vodicka
STMicroelectronics Design and Application s.r.o.
[michal.vodicka@st.com, http:://www.st.com]


From: xxxxx@hotmail.com[SMTP:xxxxx@hotmail.com]
Reply To: xxxxx@lists.osr.com
Sent: Tuesday, December 31, 2002 5:18 AM
To: xxxxx@lists.osr.com
Cc: xxxxx@lists.osr.com
Subject: [ntdev] chaining and unchaing buffers?? BAD_POOL_CALL?

Hi folks, I wonder if someone could help me?I want to unchain the
first buffer from the packet, chain my own buffer at front and then
chain the original buffer at front again. I would end up with my
buffer inserted between the first and second buffers in the original
packet.

I am using the following code to do this in MPSend( ). It is in the
w2k ddk’s passthru sample. Here 'originalPacket?? is the packet to
be sent, 'firstBuffer?? is first buffer in that packet and
‘myBuffer’ is the buffer I construct and want to insert in the packet.

NdisAllocateBufferPool(&myStatus,&myBufferPool,3);

if(myStatus==NDIS_STATUS_SUCCESS){

NdisAllocateMemoryWithTag(&myBaseAddress,60,‘toor’);
NdisAllocateBuffer(&myStatus,&myBuffer,myBufferPool,myBaseAddress,14);

if(myStatus==NDIS_STATUS_SUCCESS){
NdisQueryBuffer(myBuffer,&myVirtualAddress,&myLength);
if(myBuffer){
//I write my own buffer here
NdisUnchainBufferAtFront(originalPacket,&firstBuffer);
if(firstBuffer){
NdisChainBufferAtFront(originalPacket,myBuffer);
NdisChainBufferAtFront(originalPacket,firstBuffer);
}
}
}
}

However this gives a blue screen with the error 'BAD_POOL_CALL??.
What am I doing wrong.Any help would be much appreciated. Thanks in
advance
Regards,
Yasser

P.S I get the same error when I try to chain a buffer at the back.


MSN 8 helps eliminate e-mail viruses. Get 3 months FREE*.
http://join.msn.com/?page=features/virus&xAPID=42&PS=47575&PI=7324&DI=7474
&SU=
http://www.hotmail.msn.com/cgi-bin/getmsg&HL=1216hotmailtaglines_virusprot
ection_3mf


You are currently subscribed to ntdev as: michal.vodicka@st.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

As Michal said, the approach you are taking is dangerous.

The NDIS FAQ topic “Can I modify a NDIS packet that I didn’t allocate
myself?” at:

http://www.ndis.com/faq/ndisfaq.htm

Good luck,

Thomas F. Divine

“Yasser Toor” wrote in message news:xxxxx@ntdev…
>
>
>
> Hi folks, I wonder if someone could help me?I want to unchain the
> first buffer from the packet, chain my own buffer at front and then
> chain the original buffer at front again. I would end up with my
> buffer inserted between the first and second buffers in the original
> packet.
>
> I am using the following code to do this in MPSend( ). It is in the
> w2k ddk’s passthru sample. Here 'originalPacket¡¯ is the packet to
> be sent, 'firstBuffer¡¯ is first buffer in that packet and
> ‘myBuffer’ is the buffer I construct and want to insert in the packet.
>
> NdisAllocateBufferPool(&myStatus,&myBufferPool,3);
>
> if(myStatus==NDIS_STATUS_SUCCESS){
>
> NdisAllocateMemoryWithTag(&myBaseAddress,60,‘toor’);
> NdisAllocateBuffer(&myStatus,&myBuffer,myBufferPool,myBaseAddress,14);
>
> if(myStatus==NDIS_STATUS_SUCCESS){
> NdisQueryBuffer(myBuffer,&myVirtualAddress,&myLength);
> if(myBuffer){
> //I write my own buffer here
> NdisUnchainBufferAtFront(originalPacket,&firstBuffer);
> if(firstBuffer){
> NdisChainBufferAtFront(originalPacket,myBuffer);
> NdisChainBufferAtFront(originalPacket,firstBuffer);
> }
> }
> }
> }
>
> However this gives a blue screen with the error 'BAD_POOL_CALL¡¯.
> What am I doing wrong.Any help would be much appreciated. Thanks in
> advance
> Regards,
> Yasser
>
> P.S I get the same error when I try to chain a buffer at the back.
>
>
>
>
>
>
>
> _________________________________________________________________
> MSN 8 helps eliminate e-mail viruses. Get 3 months FREE*.
>
http://join.msn.com/?page=features/virus&xAPID=42&PS=47575&PI=7324&DI=7474&S
U=
>
http://www.hotmail.msn.com/cgi-bin/getmsg&HL=1216hotmailtaglines_virusprotec
tion_3mf
>
>
>
>