Link to home
Start Free TrialLog in
Avatar of derick042497
derick042497

asked on

AIX 4.2 shared memory

I'm using AIX 4.2 and in the midst of porting over a working  C program written originally in SunOS. I managed to compile in AIX but encounter runtime error. I'm using the dbx debugger at the moment

These are the error messages

key = 1342742594
shmsz = 56736
shmid = 118786

initing real-time prices shm tables ....
addr(SHM_stkcodetbl_ptr) = 805306368
initing Stock Code Hash Table Shm....
addr(SHM_stknametbl_ptr) = 1073741824
initing Stock Name Hash Table Shm....
addr(SHM_stkmkt_ptr) = -1879048192
initing Stock Market Shm....
addr(SHM_stkcommon_ptr) = -1610612736
initing Stock Common Shm....
addr(SHM_timestamp_ptr) = 4294967295d
addr(SHM_timestamp_ptr) = 4294967295ld
addr(SHM_timestamp_ptr) = -1
addr(SHM_timestamp_ptr) = -1
initing Timestamp Shm....

(dbx) where
memset() at 0xd001ccc4
init_timestamp_shm(), line 306 in "initshm.c"
init_main_shmtbl(), line 767 in "initshm.c"
init_sun_shmtbl(), line 430 in "mainshm.c"
init_shmtbl_MODE(mode = 2), line 614 in "fep.c"
main(argc = 3, argv = 0x2ff22ce8), line 332 in "fep.c"

Segmentation fault in memset at 0xd001ccc4
0xd001ccc4 (memset+0x444) 98860000        stb   r4,0x0(r6)

(dbx) print *SHM_timestamp_ptr
(timestamp = "ÿ", sysdate = "", vernum = "")

(dbx) print SHM_timestamp_ptr
0xffffffff

(dbx) print *SHM_ent_dptr
(stock_code = "ÿ", newsID = "", news_subject = "", stkpar_value = "", desc = "",
 announce_date = 0, EX_date = 0, toSCANS_date = 0, lodge_date = 0, pay_date = 0,
 entitl_percent = "", entitl_sen = "", entitl_numerator = 0, entitl_denom = 0, e
ntitl_type = "", entitl_indicator = '\0', entitl_remark = "", dissem_date = -934
803275, dissem_time = 2050998400)

(dbx) print SHM_ent_dptr
0xffffffff



HEADER file
-----------
typedef struct {
        char    timestamp       [ TIMESTAMP_LEN +1  ];
        char    sysdate         [ SYSTEMDATE_LEN +1 ];
        char    vernum          [ VERNUM_LEN +1 ];

} TIMESTAMP_FEP;


typedef  struct {
     char    stock_code      [ STKCODE_LEN +1];
     int     key;
     int     next;
} HASH_ENTRY;


typedef struct {
 char    stock_code[ STKCODE_LEN +1];
 char    newsID[ NEWSID_LEN +1];
 char    news_subject    [ TEXT_LEN +1];
 char    stkpar_value    [ STKPAR_LEN+1];
 char    desc[ ENTT_DESC_LEN +1];
 int     announce_date ;
 int     EX_date ;
 int     toSCANS_date ;
 int     lodge_date ;
 int     pay_date ;
 char    entitl_percent  [ ENTT_PERCENT_LEN+1];
 char    entitl_sen[ ENTT_SEN_LEN+1];
 int     entitl_numerator;
 int     entitl_denom;
 char    entitl_type     [ ENTT_TYPE_LEN +1];
 char    entitl_indicator;
 char    entitl_remark   [ ENTT_REM_LEN +1];
 int     dissem_date ;
 int     dissem_time ;

} ENTITL;




SOURCE CODE (partly):
---------------------
  extern  TIMESTAMP_FEP *SHM_timestamp_ptr;
  extern HASH_ENTRY     *SHM_ent_hptr;
  extern ENTITL         *SHM_ent_dptr;


int
init_timestamp_shm ()
{
  TIMESTAMP_FEP *tmp_timestamp_ptr;


unsigned int   timestamp_addr;
unsigned long  ltimestamp_addr;

  timestamp_addr = (unsigned int)SHM_timestamp_ptr;
  ltimestamp_addr = (unsigned long)SHM_timestamp_ptr;

  tmp_timestamp_ptr = SHM_timestamp_ptr;        /* don't clobber original pointe
r       */
  fprintf(stderr,"addr(SHM_timestamp_ptr) = %ud \n", SHM_timestamp_ptr);
  fprintf(stderr,"addr(SHM_timestamp_ptr) = %uld \n", SHM_timestamp_ptr);

  fprintf(stderr,"addr(SHM_timestamp_ptr) = %d \n", timestamp_addr);
  fprintf(stderr,"addr(SHM_timestamp_ptr) = %ld \n", ltimestamp_addr);

#ifdef DEBUG
  fprintf(stderr, "initing Timestamp Shm....\n");
#endif
  /*memset ( tmp_timestamp_ptr, MyNULL, sizeof ( TIMESTAMP_FEP ));*/
  memset ( tmp_timestamp_ptr->timestamp, MyNULL, sizeof ( tmp_timestamp_ptr->tim   /* ERROR indicated by debugger */
estamp ));
  memset ( tmp_timestamp_ptr->sysdate, MyNULL, sizeof ( tmp_timestamp_ptr->sysda
te ));
  memset ( tmp_timestamp_ptr->vernum, MyNULL, sizeof ( tmp_timestamp_ptr->vernum
 ));

  return (0);

} /* -- init_timestamp_shm () -- */

int
init_entt_shm ( )
{
  HASH_ENTRY    *tmp_hash_ptr;
  ENTITL        *tmp_entt_ptr;
  int i;

  tmp_hash_ptr = SHM_ent_hptr;
  tmp_entt_ptr = SHM_ent_dptr;

#ifdef DEBUG
  fprintf(stderr, "initing Entitlement Shm....\n");
#endif
  /*memset ( tmp_hash_ptr, MyNULL, MAX_ENT_HASH_ENTRIES * sizeof (HASH_ENTRY));*
/
  memset ( tmp_hash_ptr->stock_code, MyNULL, MAX_ENT_HASH_ENTRIES * sizeof (tmp_
hash_ptr->stock_code));
  tmp_hash_ptr->key = 0;
  tmp_hash_ptr->next = 0;
  for ( i = 0;  i < MAX_ENT_HASH_ENTRIES; i++) {
        tmp_hash_ptr [i].next = DEAD;
        tmp_hash_ptr [i].key = DEAD;
 }/* for */

  /*
   * Init Entitlement Data Shm
   */
  /*memset ( tmp_entt_ptr, MyNULL, MAX_ENT_DATA_ENTRIES * sizeof( ENTITL));*/
  memset ( tmp_entt_ptr->stock_code, MyNULL, MAX_ENT_DATA_ENTRIES * sizeof( tmp_
entt_ptr->stock_code));
  memset ( tmp_entt_ptr->newsID, MyNULL, MAX_ENT_DATA_ENTRIES * sizeof( tmp_entt
_ptr->newsID));
  /*memset ( tmp_entt_ptr, MyNULL, MAX_ENT_DATA_ENTRIES * sizeof( ENTITL));*/
  memset ( tmp_entt_ptr->stock_code, MyNULL, MAX_ENT_DATA_ENTRIES * sizeof( tmp_
entt_ptr->stock_code));
  memset ( tmp_entt_ptr->newsID, MyNULL, MAX_ENT_DATA_ENTRIES * sizeof( tmp_entt
_ptr->newsID));
  memset ( tmp_entt_ptr->news_subject, MyNULL, MAX_ENT_DATA_ENTRIES * sizeof( tm
p_entt_ptr->news_subject));
  memset ( tmp_entt_ptr->stkpar_value, MyNULL, MAX_ENT_DATA_ENTRIES * sizeof( tm
p_entt_ptr->stkpar_value));
  memset ( tmp_entt_ptr->desc, MyNULL, MAX_ENT_DATA_ENTRIES * sizeof( tmp_entt_p
tr->desc));
  tmp_entt_ptr->announce_date = 0;
  tmp_entt_ptr->EX_date = 0;
  tmp_entt_ptr->toSCANS_date = 0;
  tmp_entt_ptr->lodge_date = 0;
  tmp_entt_ptr->pay_date = 0;
  memset ( tmp_entt_ptr->entitl_percent, MyNULL, MAX_ENT_DATA_ENTRIES * sizeof(
tmp_entt_ptr->entitl_percent));
  memset ( tmp_entt_ptr->entitl_sen, MyNULL, MAX_ENT_DATA_ENTRIES * sizeof( tmp_
entt_ptr->entitl_sen));
  tmp_entt_ptr->entitl_numerator = 0;
  tmp_entt_ptr->entitl_denom = 0;
  memset ( tmp_entt_ptr->entitl_type, MyNULL, MAX_ENT_DATA_ENTRIES * sizeof( tmp
_entt_ptr->entitl_type));
  tmp_entt_ptr->entitl_indicator = NULL;
  memset ( tmp_entt_ptr->entitl_remark, MyNULL, MAX_ENT_DATA_ENTRIES * sizeof( t
mp_entt_ptr->entitl_remark));
  tmp_entt_ptr->dissem_date = 0;
  tmp_entt_ptr->dissem_time = 0;

  return (0);

} /* -- init_entt_shm () -- */


---------------------------------------------

What is wrong with that statement? Is it because the shared memory allocated is not enough? I was told that I don't have to allocate shared memory in AIX. However, all the shared memory segments appear when I issued the "ipcs -m" command. Could it be that I'm accessing the wrong segment of the shared memory? It stops midway into initialising the shared memory.

Pls help me out.
Avatar of aditya070797
aditya070797

Hmm..
         0xffffffff seems like  a lot of junk.. Looks like your SHM_time_stamp_ptr is hosed from the start... check
if your variables are defined properly first. memset tries to 'set ' the contents of the memory location pointed to by the pointer, to  
the value provided.. if the pointer points to junk, it will sigabrt..
--Aditya Vedula.
ASKER CERTIFIED SOLUTION
Avatar of jos010697
jos010697

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of derick042497

ASKER

Attached is the code using shmat(). It ran fine until it reaches the code below (remarked). Is it alright to typecast a shared memory pointer to a structure pointer?

CODE:
----
int
attach_oddlots_shm ( )
{
  key_t    key;
  int      shmid;
  /*long   shmsz;*/
  size_t   shmsz;

  key = (key_t) ODD_LOTS_SHMKEY;
  shmsz = MAX_COUNTERS * sizeof ( ODD_LOTS );

  if ( ( shmid = shmget (key, shmsz, IPC_CREAT | 0644 )) == -1 )  {
 perror ("shmget ODD_LOTS");
 printf ("errno :%d", errno);
 return (-1);
  }

  /* Error 0xffffffff appears right after the statement below */
  if (( SHM_oddlots_ptr
                = (ODD_LOTS*) shmat ( shmid,(char*)0,0)) == NULL) {
        perror ("shmat ODD_LOTS");
        return (-1);
  }
  return (0);
}



STRUCTURE:
---------
typedef struct {
 char    stock_code[ STKCODE_LEN +1 ];
 char    delivery_basis;
 char    total_volume    [ ODDLOT_TOTALVOL_LEN +1];
 char    total_value     [ ODDLOT_TOTALVALUE_LEN+1];
        int     stk_refcode;
        char    buyin_price     [ ODDLOT_BUYINPRICE_LEN+1];
        int     buyin_qty;
        char    odd_lot_stat;
        char    buy_price       [ ODDLOT_BUYPRICE_LEN+1];
        int     buy_qty;
        char    sell_price      [ ODDLOT_SELLPRICE_LEN+1];
        int     sell_qty;
        char    lastdone_price  [ ODDLOT_LASTDONEPRICE_LEN+1];
        int     lastdone_qty;
} ODD_LOTS;

}