lkml.org 
[lkml]   [2000]   [Oct]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Problem with msgsnd
lkml@dm.ultramaster.com wrote:
>
> Marc Schneider wrote:
> >
> > msgsnd seems to be corrupting memory around the msgbuf pointer.
> >
> > for example I have the following code:
> >
> > pMsgBuf = malloc(iPacketLen + 4 + 8);
> > bzero(pMsgBuf, iPacketLen + 4 + 8);
> > pMsgBuf += 4; /* Build a guard band */
> >
> > printf("PMQ:pMsgBuf: %p\n",pMsgBuf);
> > printf("PMQ:-4: %p\n", *(pMsgBuf-4));
> >
> > rc = msgsnd(iMsgQueueID, pMsgBuf, iPacketLen, 0);
> >
>
> Two issues which may or may not directly address your problem. Quoting
> the man page:
>
> ..The structure member mtype must have a
> strictly positive integer value that can be used by the
> receiving process for message selection (see the section
> about msgrcv).
>
> Here, your 'mtype', the long at the beginning of the message, is 0.
>
> Secondly, the third parameter to msgsnd is the size of the data portion
> of the message, not the 'packetlen.' Usually msgsnd is passed a
>
> structure pointer, say a struct msgbuf *. In that case, msgsz is:
> sizeof(struct msgbuf) - sizeof(long).
>
> The first issue makes anything possible... The second is just a gotcha
> to avoid.
>
> David Mansfield

I don't actually show it in the above code snippet but, I do copy data
into the buffer pointed by pMsgBuf. The first four bytes is a long which
take a value between 1 and 20.

The actual data follows the four bytes. The amount of data copied is
specified by iPacketLen. My buffer is actually iPacketLen+4 bytes in
size. (The guard band of four bytes before and after the buffer is
actually not used and is only there to detect this error.)

Any other Ideas?

Marc Schneider
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 12:41    [W:0.058 / U:0.408 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site