Operating System - HP-UX
1745924 Members
4082 Online
108723 Solutions
New Discussion

BUS_ADRALN - Invalid address alignment, while C program execution on HP-UX B.11.31 U ia64

 
SOLVED
Go to solution
Neolord
Visitor

BUS_ADRALN - Invalid address alignment, while C program execution on HP-UX B.11.31 U ia64

Hello,

Please help to resolve problem for C program on HP-UX B.11.31 U ia64, which is resulting in core dump while execution with 

BUS_ADRALN error.


Program received signal SIGBUS, Bus error
si_code: 1 - BUS_ADRALN - Invalid address alignment. Please refer to the following link that helps in handling unaligned data: http://docs.hp.com/en/7730/newhelp0610/pragmas.htm#pragma-pack-ex3.
0x4000000000145280:1 in db_ins_curr_trans (umsg=0x87ffffffffff5920)
at ./dbcurrtran.pc:2528
2528 RAW_TO_ORACLE_VARCHAR_W_SZ( addldata,
(gdb) bt
#0 0x4000000000145280:1 in db_ins_curr_trans (umsg=0x87ffffffffff5920)
at ./dbcurrtran.pc:2528
#1 0x40000000000c1250:0 in speedup_db () at speedup_db.c:86
#2 0x40000000000a8970:0 in main (argc=1, argv=0x87fffffffffff338)
at tserv.c:184
(gdb)
_Unwind_InfoBlock::decodeVUF: Unrecognized flags 200000000000

 

Here is code list (partly):

int speedup_db( void )
{
   umf_ent ct_rec;
   memset( &ct_rec, 0, sizeof(umf_ent) );

   db_ins_curr_trans( &ct_rec );

...

}

 

int db_ins_curr_trans( umf_ent *umsg )
{

   RAW_TO_ORACLE_VARCHAR_W_SZ( addldata, umsg->iso.addldata + sizeof(size_t), *(size_t*)(umsg->iso.addldata) );

   ...

}

 

where RAW_TO_ORACLE_VARCHAR_W_SZ is macro:

#define RAW_TO_ORACLE_VARCHAR_W_SZ( dest, src, size ) \
raw_to_oracle_varchar( dest.arr, &dest.len, sizeof(dest.arr), src, size )

 

unsigned char *raw_to_oracle_varchar( unsigned char *dest, unsigned short *destlen, size_t destsize, const unsigned char *src, int srclen )
{
   if( sizeof(char)*(2 * srclen) > destsize )
   {
        srclen = (destsize / sizeof(char)) / 2;
   }

   memset( (void *)dest, '\0', destsize );
   *destlen = srclen * 2;
   bchtoa( src, (char *)dest, srclen );

   return dest;
} /* end of raw_to_oracle_varchar */

 

and umf_ent is a structure:

typedef struct
{
   ...
   isost iso;
} umf_ent;

 

typedef struct
{

   ...

   unsigned char addldata[ 1024 ];
   ...
} isost;

 

 

 


 

 

 

 

8 REPLIES 8
Dennis Handly
Acclaimed Contributor

Re: BUS_ADRALN - Invalid address alignment, while C program execution on HP-UX B.11.31 U ia64

>RAW_TO_ORACLE_VARCHAR_W_SZ(addldata, umsg->iso.addldata + sizeof(size_t), *(size_t*)(umsg->iso.addldata));

 

It could be aborting trying load up a 8 byte aligned size_t at addldata.  It appears that ct_rec is at least 8 byte aligned.

 

>typedef struct {
   ...
   isost iso;
} umf_ent;

typedef struct {

   ...

   unsigned char addldata[1024];
} isost;

 

These "..." are important.  Do they have any pointers there that would align addldata on an 8 byte boundary?

 

Neolord
Visitor

Re: BUS_ADRALN - Invalid address alignment, while C program execution on HP-UX B.11.31 U ia64

Please find the header file attached, sorry for extradata in advance.

Dennis Handly
Acclaimed Contributor

Re: BUS_ADRALN - Invalid address alignment, while C program execution on HP-UX B.11.31 U ia64

>Please find the header file attached, sorry for extra data in advance.

 

You are going to have to do your homework and let the compiler compute this offset info for us.

Add this to your program and supply the results:

 

#include <stddef.h>

#include <stdio.h>

 

printf("offset of addldata: %lu\n", offsetof(isost, addldata));

printf("offset of iso:%lu\n", offsetof(umf_ent, iso));

 

This is likely only a multiple of 4 and not 8 for 64 bit mode.

 

Or just go into the debugger and in db_ins_curr_trans, print out:

   p umsg->iso.addldata

Neolord
Visitor

Re: BUS_ADRALN - Invalid address alignment, while C program execution on HP-UX B.11.31 U ia64

current results:
offset of addldata: 1332
offset of iso: 816
(gdb) p umsg->iso.addldata
$1 = '\000' <repeats 1023 times>

 

so, now I've noticed that recently one field was added to umf structure and length of the other one was changed, so before these changes the result of offset of addldata was multiple of 8 and there was no BUS_ADRALN error raised:
offset of addldata: 1312
offset of iso: 816

But even before changes it seems to be dangerous way to expect / fit this offset to be always multiple of 8 - sizeof(size_t). Am I right ? 

 

Neolord
Visitor

Re: BUS_ADRALN - Invalid address alignment, while C program execution on HP-UX B.11.31 U ia64

Dennis Handly
Acclaimed Contributor
Solution

Re: BUS_ADRALN - Invalid address alignment, while C program execution on HP-UX B.11.31 U ia64

>offset of addldata: 1332  offset of iso: 816

 

The sum of the two in hex is: 0x864  (so 4 byte aligned)

 

>(gdb) p umsg->iso.addldata  $1 = '\000' <repeats 1023 times>

 

I guess you needed to take the address: p &umsg->iso.addldata[0]

 

>it seems to be dangerous way to expect / fit this offset to be always multiple of 8 - sizeof(size_t).

 

Easily solved.  Add an alignment bitfield:

   int ppmci;

   size_t :0;  // align next field

   unsigned char addldata[UMF_ADDLDATA_SZ];

 

 

offset of addldata: 1332
offset of iso: 816
Neolord
Visitor

Re: BUS_ADRALN - Invalid address alignment, while C program execution on HP-UX B.11.31 U ia64

I guess you needed to take the address: p &umsg->iso.addldata[0]

Да, извиняюсь:

(gdb) p &umsg.iso.addldata
$1 = (unsigned char (*)[1024]) 0x87ffffffffffdf74

Dennis Handly
Acclaimed Contributor

Re: BUS_ADRALN - Invalid address alignment, while C program execution on HP-UX B.11.31 U ia64

>$1 = (unsigned char (*)[1024]) 0x87ffffffffffdf74

 

This shows the alignment is just 4.