Skip to contentSkip to conversation

a question about memory access on IA64

DISCUSSION liuduo 3 participants 7 messages Jan 16, 2004

lore
Share & tools
lore

liuduo

author
#0 lore raw

Dear Sir:
nice to see you !
here is a problem about accessing memory on IA64 as follows,
we define a structrue is :
typedef struct b{

unsigned short  b1;
unsigned short  b2;
unsigned char   b3;
unsigned char  b4;
unsigned char  b5;
unsigned char  b6;

}B;

typedef struct a{
struct b bb[512];
int c;}A;

when we use the struct A on IA64, the segmentation fault occurs , and then we modify the struct A as follows :
typedef struct a{
int c;
struct b bb[512];
}A;
we can use it normally .
can you explain why ?
thanks a lot , and expect your reply urgently

yours : calis

Signature · 6 lines
===================Liu duo
tel:(010)62570007-509
email:[email protected]
Sinosoft Software.Co.Ltd.
Esmpro Group.Secic Department
===================
#1 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · liuduo

liuduo> Dear Sir: nice to see you ! here is a problem about liuduo> accessing memory on IA64 as follows, we define a structrue liuduo> is : typedef struct b{ unsigned short b1; unsigned short b2; liuduo> unsigned char b3; unsigned char b4; unsigned char b5; liuduo> unsigned char b6; }B;

  liuduo> typedef struct a{ struct b bb[512]; int c;}A;

liuduo> when we use the struct A on IA64, the segmentation fault liuduo> occurs , and then we modify the struct A as follows :
liuduo> typedef struct a{ int c; struct b bb[512]; }A; we can use it liuduo> normally . can you explain why ? thanks a lot , and expect liuduo> your reply urgently

The example you posted is not a complete, self-contained program, so it's impossible to say whats wrong. Perhaps it's a compiler bug, perhaps it's a kernel bug, perhaps it's a bug in the program. Please post a _minimal_ test program that reproduces the problem you're trying to solve and state what compiler version, etc. you're using. Then somebody may be able to help.

	--david
author
#2 lore raw
In reply to liuduo

David:
Sorry, i only describe the process about the error occurs .

    typedef struct b{
      char*  pDescriptName;
      char*           pVendorName;
      unsigned int	RevisionID;
     }B;

    typedef struct pci{
     int c;
     struct b bb[512];
     }PCI;

int main()
{

     struct pci a;

     //function for operation a
     func(&a);
     return 0;
}

the func is in an lib, it's an lib export function, and the func is as follows;

func(struct pci* a)

{
      char tmp[256];
     for(num=0;num<512;num++)
     {
      a->bb[num].pDescriptName = (char*)malloc(100);
      strcpy(a->bb[num].pDescriptName , "dddd");
      a->bb[num].pVendorName = (char*)malloc(100);
      strcpy(a->bb[num].pVendorName , "fffff");
      a->bb[num].RevisionID = 22;
     }
     a->c = 512;
}
when call the func , the segmentation fault occurs,
and then we modified the struct A as follows
     typedef struct pci{
     struct b bb[512];
     int c;
     }PCI;

it's normal.
please tell me why?
thanks a lot.

Signature · 6 lines
===================Liu duo
tel:(010)62570007-509
email:[email protected]
Sinosoft Software.Co.Ltd.
Esmpro Group.Secic Department
===================
#3 lore raw
In reply to liuduo
Quoted 25 lines · liuduo

David:
Sorry, i only describe the process about the error occurs .

   typedef struct b{
     char*  pDescriptName;
     char*           pVendorName;
     unsigned int	RevisionID;
    }B;

   typedef struct pci{
    int c;
    struct b bb[512];
    }PCI;

int main()
{

    struct pci a;

    //function for operation a
    func(&a);
    return 0;
}
Quoted 2 lines

the func is in an lib, it's an lib export function, and the func is as follows;

Do you mean that it works if you use the first struct definition, and if you pu the func into the same file? Does it have to be in a library to fail?

Could it be that you are using different structure packing for building the library, either through compiler options or #pragmas in some other header file?

Quoted 38 lines

func(struct pci* a)

{
     char tmp[256];
    for(num=0;num<512;num++)
    {
     a->bb[num].pDescriptName = (char*)malloc(100);
     strcpy(a->bb[num].pDescriptName , "dddd");
     a->bb[num].pVendorName = (char*)malloc(100);
     strcpy(a->bb[num].pVendorName , "fffff");
     a->bb[num].RevisionID = 22;
    }
    a->c = 512;
}
when call the func , the segmentation fault occurs,
and then we modified the struct A as follows
    typedef struct pci{
    struct b bb[512];
    int c;
    }PCI;

it's normal.
please tell me why?
thanks a lot.

Signature · 14 lines
=======================================
Liu duo
tel:(010)62570007-509
email:[email protected]
Sinosoft Software.Co.Ltd.
Esmpro Group.Secic Department
=======================================



-
To unsubscribe from this list: send the line "unsubscribe linux-ia64" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 4 lines
Martin

"all the hardcore hackers use aol"
    - Joseph "joey" Sarrach <[email protected]>
#4 lore raw
In reply to liuduo

Sorry, but your problem report is still very incomplete. Please provide a _self-contained_ minimal test program that reproduces the problem for you and describe you how compile the program. Without a complete test-case there are a million variations of what could be wrong.

	--david
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · liuduo

Liuduo> David:
Liuduo> Sorry, i only describe the process about the error occurs .

  Liuduo> typedef struct b{
  Liuduo> char*  pDescriptName;
  Liuduo> char*           pVendorName;
  Liuduo> unsigned int	RevisionID;
  Liuduo> }B;

  Liuduo> typedef struct pci{
  Liuduo> int c;
  Liuduo> struct b bb[512];
  Liuduo> }PCI;

  Liuduo> int main()
  Liuduo> {

Liuduo> struct pci a;

Liuduo> //function for operation a
Liuduo> func(&a);
Liuduo> return 0;
Liuduo> }
Liuduo> the func is in an lib, it's an lib export function, and the func is as Liuduo> follows;

  Liuduo> func(struct pci* a)
  Liuduo> {
  Liuduo> char tmp[256];
  Liuduo> for(num=0;num<512;num++)
  Liuduo> {
  a-> bb[num].pDescriptName = (char*)malloc(100);
  Liuduo> strcpy(a->bb[num].pDescriptName , "dddd");
  a-> bb[num].pVendorName = (char*)malloc(100);
  Liuduo> strcpy(a->bb[num].pVendorName , "fffff");
  a-> bb[num].RevisionID = 22;
  Liuduo> }
  a-> c = 512;
  Liuduo> }
  Liuduo> when call the func , the segmentation fault occurs,
  Liuduo> and then we modified the struct A as follows
  Liuduo> typedef struct pci{
  Liuduo> struct b bb[512];
  Liuduo> int c;
  Liuduo> }PCI;
  Liuduo> it's normal.
  Liuduo> please tell me why?
  Liuduo> thanks a lot.
  Liuduo> -- 
  Liuduo> ===================  Liuduo> Liu duo
  Liuduo> tel:(010)62570007-509
  Liuduo> email:[email protected]
  Liuduo> Sinosoft Software.Co.Ltd.
  Liuduo> Esmpro Group.Secic Department
  Liuduo> ===================
#5 lore raw
In reply to liuduo

Please reply to the list, not to me.

Quoted 44 lines · liuduo
Quoted 27 lines · Martin Pool
Quoted 25 lines · liuduo

David:
Sorry, i only describe the process about the error occurs .

 typedef struct b{
   char*  pDescriptName;
   char*           pVendorName;
   unsigned int	RevisionID;

}B;

typedef struct pci{
int c;
struct b bb[512];
}PCI;

int main()
{

struct pci a;

//function for operation a
func(&a);
return 0;
}

Quoted 7 lines
Quoted 3 lines

the func is in an lib, it's an lib export function, and the func is as follows;

Do you mean that it works if you use the first struct definition, and if you pu the func into the same file?

yes

Quoted 3 lines

Does it have to be in a
library to fail?

yes

Quoted 2 lines
Quoted 5 lines
Quoted 4 lines

Could it be that you are using different structure packing for building the library, either through compiler options or #pragmas in some other header file?

we use the #pragma pack (1) in the file that the func is in it.

Don't do that then. If you access a struct with different packing conventions, your program will lose its fingers.

Quoted 22 lines
Quoted 22 lines
Quoted 22 lines

func(struct pci* a)

{
   char tmp[256];
  for(num=0;num<512;num++)
  {
   a->bb[num].pDescriptName = (char*)malloc(100);
   strcpy(a->bb[num].pDescriptName , "dddd");
   a->bb[num].pVendorName = (char*)malloc(100);
   strcpy(a->bb[num].pVendorName , "fffff");
   a->bb[num].RevisionID = 22;

}
a->c = 512;
}
when call the func , the segmentation fault occurs, and then we modified the struct A as follows
typedef struct pci{
struct b bb[512];
int c;
}PCI;
it's normal.
please tell me why?
thanks a lot.

Signature · 1 line
Martin
author
#6 lore raw
In reply to liuduo

Hi:
Thanks for your help, i have solved the problem
Have a good time !

yours: calis

Quoted 81 lines · Martin Pool

Please reply to the list, not to me.

Quoted 40 lines · liuduo
Quoted 27 lines · Martin Pool
Quoted 25 lines · liuduo

David:
Sorry, i only describe the process about the error occurs .

typedef struct b{
char* pDescriptName;
char* pVendorName;
unsigned int RevisionID;
}B;

typedef struct pci{
int c;
struct b bb[512];
}PCI;

int main()
{

struct pci a;

//function for operation a
func(&a);
return 0;
}

Quoted 6 lines
Quoted 3 lines

the func is in an lib, it's an lib export function, and the func is as follows;

Do you mean that it works if you use the first struct definition, and if you pu the func into the same file?

yes

Quoted 3 lines

Does it have to be in a
library to fail?

Quoted 9 lines

yes

Quoted 5 lines

Could it be that you are using different structure packing for building the library, either through compiler options or #pragmas in some other header file?

we use the #pragma pack (1) in the file that the func is in it.

Don't do that then. If you access a struct with different packing conventions, your program will lose its fingers.

Quoted 23 lines
Quoted 23 lines
Quoted 23 lines

func(struct pci* a)
{
char tmp[256];
for(num=0;num<512;num++)
{
a->bb[num].pDescriptName = (char*)malloc(100); strcpy(a->bb[num].pDescriptName , "dddd"); a->bb[num].pVendorName = (char*)malloc(100); strcpy(a->bb[num].pVendorName , "fffff"); a->bb[num].RevisionID = 22;
}
a->c = 512;
}
when call the func , the segmentation fault occurs, and then we modified the struct A as follows
typedef struct pci{
struct b bb[512];
int c;
}PCI;
it's normal.
please tell me why?
thanks a lot.

Signature · 6 lines
===================Liu duo
tel:(010)62570007-509
email:[email protected]
Sinosoft Software.Co.Ltd.
Esmpro Group.Secic Department
===================