public inbox for linux-ia64@vger.kernel.org
 help / color / mirror / Atom feed
* a question about memory access on IA64
@ 2004-01-16  3:03 liuduo
  2004-01-16  3:16 ` David Mosberger
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: liuduo @ 2004-01-16  3:03 UTC (permalink / raw)
  To: linux-ia64

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






-- 
===================Liu duo
tel:(010)62570007-509
email:liuduo@sinosoft.com.cn
Sinosoft Software.Co.Ltd.
Esmpro Group.Secic Department
===================


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: a question about memory access on IA64
  2004-01-16  3:03 a question about memory access on IA64 liuduo
@ 2004-01-16  3:16 ` David Mosberger
  2004-01-16  3:56 ` liuduo
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: David Mosberger @ 2004-01-16  3:16 UTC (permalink / raw)
  To: linux-ia64

>>>>> On Fri, 16 Jan 2004 11:03:00 +0800, liuduo <liuduo@sinosoft.com.cn> said:

  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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* a question about memory access on IA64
  2004-01-16  3:03 a question about memory access on IA64 liuduo
  2004-01-16  3:16 ` David Mosberger
@ 2004-01-16  3:56 ` liuduo
  2004-01-16  4:16 ` Martin Pool
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: liuduo @ 2004-01-16  3:56 UTC (permalink / raw)
  To: linux-ia64

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.
-- 
===================Liu duo
tel:(010)62570007-509
email:liuduo@sinosoft.com.cn
Sinosoft Software.Co.Ltd.
Esmpro Group.Secic Department
===================



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: a question about memory access on IA64
  2004-01-16  3:03 a question about memory access on IA64 liuduo
  2004-01-16  3:16 ` David Mosberger
  2004-01-16  3:56 ` liuduo
@ 2004-01-16  4:16 ` Martin Pool
  2004-01-16  4:59 ` David Mosberger
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Martin Pool @ 2004-01-16  4:16 UTC (permalink / raw)
  To: linux-ia64

[-- Attachment #1: Type: text/plain, Size: 2039 bytes --]

On 16 Jan 2004, liuduo <liuduo@sinosoft.com.cn> wrote:
> 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;

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?

> 
> 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.
> -- 
> =======================================
> Liu duo
> tel:(010)62570007-509
> email:liuduo@sinosoft.com.cn
> 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 majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
-- 
Martin

"all the hardcore hackers use aol"
    - Joseph "joey" Sarrach <mrfr0sty@home.com>

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: a question about memory access on IA64
  2004-01-16  3:03 a question about memory access on IA64 liuduo
                   ` (2 preceding siblings ...)
  2004-01-16  4:16 ` Martin Pool
@ 2004-01-16  4:59 ` David Mosberger
  2004-01-16  7:01 ` Martin Pool
  2004-01-16  7:12 ` liuduo
  5 siblings, 0 replies; 7+ messages in thread
From: David Mosberger @ 2004-01-16  4:59 UTC (permalink / raw)
  To: linux-ia64

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

>>>>> On Fri, 16 Jan 2004 12:02:02 +0800, liuduo <liuduo@sinosoft.com.cn> said:

  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:liuduo@sinosoft.com.cn
  Liuduo> Sinosoft Software.Co.Ltd.
  Liuduo> Esmpro Group.Secic Department
  Liuduo> ===================


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: a question about memory access on IA64
  2004-01-16  3:03 a question about memory access on IA64 liuduo
                   ` (3 preceding siblings ...)
  2004-01-16  4:59 ` David Mosberger
@ 2004-01-16  7:01 ` Martin Pool
  2004-01-16  7:12 ` liuduo
  5 siblings, 0 replies; 7+ messages in thread
From: Martin Pool @ 2004-01-16  7:01 UTC (permalink / raw)
  To: linux-ia64

[-- Attachment #1: Type: text/plain, Size: 1973 bytes --]

Please reply to the list, not to me.

On 16 Jan 2004, liuduo <liuduo@sinosoft.com.cn> wrote:
> Martin Pool wrote:
> >On 16 Jan 2004, liuduo <liuduo@sinosoft.com.cn> wrote:
> >>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;
> >>
> >
> >Do you mean that it works if you use the first struct definition, and
> >if you pu the func into the same file? 
> >
> yes
> 
> >Does it have to be in a
> >library to fail?
> >
> yes
> 
> >
> >
> >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.

> >>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.

-- 
Martin

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: a question about memory access on IA64
  2004-01-16  3:03 a question about memory access on IA64 liuduo
                   ` (4 preceding siblings ...)
  2004-01-16  7:01 ` Martin Pool
@ 2004-01-16  7:12 ` liuduo
  5 siblings, 0 replies; 7+ messages in thread
From: liuduo @ 2004-01-16  7:12 UTC (permalink / raw)
  To: linux-ia64


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

yours: calis

Martin Pool wrote:

>Please reply to the list, not to me.
>
>On 16 Jan 2004, liuduo <liuduo@sinosoft.com.cn> wrote:
>
>>Martin Pool wrote:
>>
>>>On 16 Jan 2004, liuduo <liuduo@sinosoft.com.cn> wrote:
>>>
>>>>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;
>>>>
>>>Do you mean that it works if you use the first struct definition, and
>>>if you pu the func into the same file? 
>>>
>>yes
>>
>>>Does it have to be in a
>>>library to fail?
>>>
>>yes
>>
>>>
>>>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.
>
>>>>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.
>>>>
>

-- 
===================Liu duo
tel:(010)62570007-509
email:liuduo@sinosoft.com.cn
Sinosoft Software.Co.Ltd.
Esmpro Group.Secic Department
===================



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-01-16  7:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-01-16  3:03 a question about memory access on IA64 liuduo
2004-01-16  3:16 ` David Mosberger
2004-01-16  3:56 ` liuduo
2004-01-16  4:16 ` Martin Pool
2004-01-16  4:59 ` David Mosberger
2004-01-16  7:01 ` Martin Pool
2004-01-16  7:12 ` liuduo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox