public inbox for linux-ia64@vger.kernel.org
 help / color / mirror / Atom feed
* Re: shared memory between 32bit & 64bit applications
@ 2004-05-03 13:25 Matthew Wilcox
  2004-05-03 13:28 ` ARADHYA, CHINMAYA TM (STSD)
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Matthew Wilcox @ 2004-05-03 13:25 UTC (permalink / raw)
  To: linux-ia64

On Mon, May 03, 2004 at 06:46:09PM +0530, ARADHYA, CHINMAYA TM (STSD) wrote:
> The information which is held in the shared memory
> is interpreted as in the structure
> typedef struct shmtest
> {
>         int req;
>         long long id;
>         int abc;
> }shmtest_t;
> 
> The 64 bit application fills in {1,5,5} in the shared
> memory and when I access these values from a 32 bit application
> I get it as {1,21474836480,0}. I guess this is due to 
> switch  of lower and upper significant bytes. 

Nope.  You're being bitten by different struct padding rules.

#include <stdio.h>

struct foo {
        int req;
        long long id;
        int abc;
};

int main(void) { return printf("%d\n", sizeof(struct foo)); }

On ia64, this prints 24; on i386 it prints 16.

You could declare it __attribute__((packed)) or you could reorder the
elements in the struct to put the largest elements first.

-- 
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain

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

* shared memory between 32bit & 64bit applications
  2004-05-03 13:25 shared memory between 32bit & 64bit applications Matthew Wilcox
@ 2004-05-03 13:28 ` ARADHYA, CHINMAYA TM (STSD)
  2004-05-03 15:07 ` Grant Grundler
  2004-05-04  2:04 ` Keith Owens
  2 siblings, 0 replies; 4+ messages in thread
From: ARADHYA, CHINMAYA TM (STSD) @ 2004-05-03 13:28 UTC (permalink / raw)
  To: linux-ia64

hi,

I am seeing this weird problem when I am trying
to pass on some data from a 64bit application to 
a 32bit application via shared memory. 

The information which is held in the shared memory
is interpreted as in the structure
typedef struct shmtest
{
        int req;
        long long id;
        int abc;
}shmtest_t;

The 64 bit application fills in {1,5,5} in the shared
memory and when I access these values from a 32 bit application
I get it as {1,21474836480,0}. I guess this is due to 
switch  of lower and upper significant bytes. 
Strangely when the 64bit application fills in 
{2,69472139471924,6} the value read by the 32bit application
would be {2,4481622812292808704,16175}.

Could somebody tell me whether I need to do something different
to handle shared memory b/w 32-64bit applications..or am I missing
out some thing basic.

Kernel version: 2.4.21-4.EL

TIA
-Chinmaya

PS: Please point me to the right group if this question does
not belong here.


 

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

* Re: shared memory between 32bit & 64bit applications
  2004-05-03 13:25 shared memory between 32bit & 64bit applications Matthew Wilcox
  2004-05-03 13:28 ` ARADHYA, CHINMAYA TM (STSD)
@ 2004-05-03 15:07 ` Grant Grundler
  2004-05-04  2:04 ` Keith Owens
  2 siblings, 0 replies; 4+ messages in thread
From: Grant Grundler @ 2004-05-03 15:07 UTC (permalink / raw)
  To: linux-ia64

On Mon, May 03, 2004 at 06:46:09PM +0530, ARADHYA, CHINMAYA TM (STSD) wrote:
> The 64 bit application fills in {1,5,5} in the shared
> memory and when I access these values from a 32 bit application
> I get it as {1,21474836480,0}.

Besides the different padding rules mentioned by willy, I'd
advise debugging with with hex output instead of decimal.
It makes it very obvious which bits are going where.

And do some experiments with filling in the fields with
known values and then dumping the entire struct as a byte array.

grant

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

* Re: shared memory between 32bit & 64bit applications
  2004-05-03 13:25 shared memory between 32bit & 64bit applications Matthew Wilcox
  2004-05-03 13:28 ` ARADHYA, CHINMAYA TM (STSD)
  2004-05-03 15:07 ` Grant Grundler
@ 2004-05-04  2:04 ` Keith Owens
  2 siblings, 0 replies; 4+ messages in thread
From: Keith Owens @ 2004-05-04  2:04 UTC (permalink / raw)
  To: linux-ia64

On Mon, 3 May 2004 14:25:11 +0100, 
Matthew Wilcox <willy@debian.org> wrote:
>Nope.  You're being bitten by different struct padding rules.
>
>#include <stdio.h>
>
>struct foo {
>        int req;
>        long long id;
>        int abc;
>};
>
>int main(void) { return printf("%d\n", sizeof(struct foo)); }
>
>On ia64, this prints 24; on i386 it prints 16.
>
>You could declare it __attribute__((packed)) or you could reorder the
>elements in the struct to put the largest elements first.

Or compile i386 code with -malign-double which will align i386 long
long values on 8 byte boundaries, the same as ia64.


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

end of thread, other threads:[~2004-05-04  2:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-03 13:25 shared memory between 32bit & 64bit applications Matthew Wilcox
2004-05-03 13:28 ` ARADHYA, CHINMAYA TM (STSD)
2004-05-03 15:07 ` Grant Grundler
2004-05-04  2:04 ` Keith Owens

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