Operating System - HP-UX
1751976 Members
5009 Online
108784 Solutions
New Discussion юеВ

How to fix a SIGBUS fault

 
SOLVED
Go to solution
arunava
Occasional Advisor

How to fix a SIGBUS fault

Hi,

I am trying to port an application from TRU64 to HPUX. When running the migrated application on HPUX, I am getting a SIGBUS signal and the application core dumps. Did some reading .. it seems this is caused by "unaligned access". The call which is failing is a TUXEDO function "tpcall()". Would be great if any could guide me in what is wrong here and how to fix this ..
Thanks in advance..
7 REPLIES 7
Dennis Handly
Acclaimed Contributor
Solution

Re: How to fix a SIGBUS fault

>it seems this is caused by "unaligned access"

Possibly. What does it say when you bring it up in gdb?
Are you using any misaligned data structures?
arunava
Occasional Advisor

Re: How to fix a SIGBUS fault

>> What does it say when you bring it up in gdb?
When i open the core with gdb, it says : "BUS_ADRALN - Invalid address alignment.". Also there is a link to a doc that explains some pragmas related to data alignment. Reading those right now ....
>>Are you using any misaligned data structures?
The data structures used in this particular call are Tuxedo data structures (i.e. FBFR32) and data in these structures is populated using Tuxedo calls (Fadd32). Is there any thing I should look out for .. that might indicate that these are misaligned ..
Dennis Handly
Acclaimed Contributor

Re: How to fix a SIGBUS fault

>When I open the core with gdb, it says: "BUS_ADRALN - Invalid address alignment.".

Then you have misaligned data or a garbage pointer value.

>Is there any thing I should look out for that might indicate that these are misaligned.

Seeing pragma pack in the source.

Can you provide a stack trace of the abort. Are you calling tpcall directly? Is the misaligned address related to a parm you are passing?

You could use a hammer and just call allow_unaligned_data_access:
http://docs.hp.com/en/14487/pragmas.htm#pragma-pack-ex3
arunava
Occasional Advisor

Re: How to fix a SIGBUS fault

Hi,
Fixed the issue!! In the tpcall(), one of the parameters is a long *. But in the code, the variable that was passed, was declared as FLDLEN32 and cast to a long. The compiler was giving a warning related to "trying to cast to a more strongly aligned type". Changed the declaration of the variable from FLDLEN32 to long and it worked!!
Still I was wondering why it didnt give any problems on TRU64. I found this: (http://gcc.gnu.orgml/gcc/2005-02/msg00892.html). This guy says that unaligned access is handled by the OS itself in TRU64, but not in HPUX.

Thanks for the help.
Dennis Handly
Acclaimed Contributor

Re: How to fix a SIGBUS fault

>unaligned access is handled by the OS itself in TRU64, but not in HP-UX.

HP-UX will do it but you have to call allow_unaligned_data_access.
Steven Schweda
Honored Contributor

Re: How to fix a SIGBUS fault

> Still I was wondering why it didnt give any
> problems on TRU64.

It probably _was_ slower at run time.
arunava
Occasional Advisor

Re: How to fix a SIGBUS fault

Hi,
Found the definition of FLDLEN32. Its typedef'd to int.
So, in this case, the function expected a long * and we were passing it an int *. And the code compiled with a warning and ran fine on Tru64. But core dumped on HP UX.