Re: fixed memory bytes

Previous thread: ASLR implementation by Zubin Mithra on Tuesday, January 4, 2011 - 6:04 am. (2 messages)

Next thread: none
From: mohit verma
Date: Tuesday, January 4, 2011 - 10:40 am

hi all,
i have seen many places in  kernel where the variables specially the
structures should be of  fixed size independent of the architecture. i went
through the  definitions of them  but dint  get  clearly (or frankly  say
...dint get them even a bit) .


so ,can please someone  help me to understand this??


thanks in advance for help........
-- 
........................
*MOHIT VERMA*
From: Mulyadi Santosa
Date: Tuesday, January 4, 2011 - 10:58 am

Your question isn't specific enough, so I'll just guess. Let's say
"int". In 32 bit, AFAIK it's  4 byte, but in 64 bit (like IA 64, not
sure if it's x64) it's 8 byte. So, if you just say "int", you will
likely getting screwed up.

By using types like u_int or something like that, you pretty much say
"I mean 4 byte kind of integer" etc

-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
From: Rajesh S R
Date: Tuesday, January 4, 2011 - 11:07 am

On Tue, Jan 4, 2011 at 11:28 PM, Mulyadi Santosa

Still there can be padding issues due to byte alignment, which may vary
across architecture. Am not sure if that is controllable (probably some



-- 
Rajesh S R
http://rajeshsr.co.cc/blogs/
From: John Mahoney
Date: Tuesday, January 4, 2011 - 11:24 am

I believe you are referring to __attribute__( ( packed ) )

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
From: John Mahoney
Date: Tuesday, January 4, 2011 - 2:15 pm

Please reply all..I added back list.


I am not sure of your definition of boundary, but I would say it does
the opposite.  It tells the compiler not to align the struct to
boundaries.

--
John

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
From: mohit verma
Date: Tuesday, January 4, 2011 - 11:22 am

that is it mulyadi. but how the compiler or kernel forces the things to get



-- 
........................
*MOHIT VERMA*
From: Mulyadi Santosa
Date: Tuesday, January 4, 2011 - 11:25 am

Hi..



well, AFAIK by mapping that new type into native one...for example,
let's say I have "u_int", which in turn when this code is compiled for
x86 32 bit, it is a typedef of "int".

-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
From: Denis Kirjanov
Date: Tuesday, January 4, 2011 - 12:17 pm

Linux (compiler actually) supports C99 fixed-width types such as 8,
16, 32, 64 bits.
Just look through the include/linux/types.h
and small example here:



-- 
Regards,
Denis

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
From: sk.syed2
Date: Tuesday, January 4, 2011 - 3:20 pm

while writing portable applications always remember that "unsigned
long" is the size of pointer and not necessarily unsigned int.

For example on x86_64 sizeof(unsigned int) != sizeof(void *).

-syed

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
From: julie Sullivan
Date: Tuesday, January 4, 2011 - 3:59 pm

Hi Mohit

I'm not sure whether we are interpreting your question correctly. Do you
mean

1. you've seen some code in the kernel which you think means the size of a
structure/
variable (and its resulting binary footprint) is set to be the same (in
bytes),
regardless of the architecture, and you are confused about it?

2. you think that there should be a way of fixing the structure/variable
(binary footprint)
size to be the same (in bytes) regardless of the architecture and you are
wondering if this
is possible?

In my (uninformed) opinion (2) is not be possible with the kernel due to
portability
issues - not only do natural word types differ (as others here are
explaining) but you
have no control over what optimization settings the kernel's user might set
in gcc,
for example. This is one of the problems with trying to maintain
closed-source drivers
and other binary code for the kernel, as I understand.

Thanks
Julie
Previous thread: ASLR implementation by Zubin Mithra on Tuesday, January 4, 2011 - 6:04 am. (2 messages)

Next thread: none