1745904 Members
4369 Online
108723 Solutions
New Discussion юеВ

Bad structure alignment

 
Rohan_7
Advisor

Bad structure alignment

Hi

I have a structure
typedef struct ipc_msg {
int msg_size;
char msg_data[1024 * 32];
}ipc_msg;

In a function a local variable of this structure type is declared and used. The function definition looks like:
----------------------------------
int sic_recvmsg(socket_ipc_client *sic, void * msg_data)
{
int ret;
ipc_msg msg;
ret = recv_all(SIC_REC->socket, &msg, 0);
....
----------------------

The problem is that when never I call this function, I get SIGBUS. The last line in coredump is start of function.
When I see the address of 'msg', it gives 0x79739f88. As the sizeof ipc_msg is 32772(32768 + 4), the address is not properly aligned and i guess this is the problem.

Can anybody tell me why this is happening?

I am using gcc 3.3.3 on HP-UX 11.11.

Thanks in advance
Rohan
3 REPLIES 3
Mike Stroyan
Honored Contributor

Re: Bad structure alignment

0x79739f88 is properly aligned.
Look more closely at what code and address
is generating the SIGBUS. There isn't enough information here to tell what is causing the SIGBUS. If I had to make a guess I would expect to see that "SIC_REC->socket" uses the "sic" parameter and that was passed in as a bad pointer.
A. Clay Stephenson
Acclaimed Contributor

Re: Bad structure alignment

Compile/link this with the debugging data flag enabled (-g?) and no optimization and then let it die and use the debugger to examine the dump and do a stack trace. This should zero in on the problem -- down to the offending source line. There is nothing wrong with your struct per se although you might be hitting a limit on maximum struct size --- but I doubt it. I'm simply not up to speed on gcc because I don't use it.
If it ain't broke, I can fix that.
Rohan_7
Advisor

Re: Bad structure alignment

Hi

Thanks a lot for your responses.

It turned out to be a different issue!
Thread was hitting the maximum stack size allowed and hence it was giving the SIGBUS.
After increasing the max allowed thread size, its running properly.

Thanks again.
Rohan