kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* fixed memory bytes
@ 2011-01-04 17:40 mohit verma
  2011-01-04 17:58 ` Mulyadi Santosa
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: mohit verma @ 2011-01-04 17:40 UTC (permalink / raw)
  To: kernelnewbies

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*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110104/01b3c9ef/attachment.html 

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

* fixed memory bytes
  2011-01-04 17:40 fixed memory bytes mohit verma
@ 2011-01-04 17:58 ` Mulyadi Santosa
  2011-01-04 18:07   ` Rajesh S R
  2011-01-04 18:22   ` mohit verma
  2011-01-04 19:17 ` Denis Kirjanov
  2011-01-04 22:59 ` julie Sullivan
  2 siblings, 2 replies; 11+ messages in thread
From: Mulyadi Santosa @ 2011-01-04 17:58 UTC (permalink / raw)
  To: kernelnewbies

On Wed, Jan 5, 2011 at 00:40, mohit verma <mohit89mlnc@gmail.com> wrote:
>
> 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) .

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

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

* fixed memory bytes
  2011-01-04 17:58 ` Mulyadi Santosa
@ 2011-01-04 18:07   ` Rajesh S R
  2011-01-04 18:24     ` John Mahoney
  2011-01-04 18:22   ` mohit verma
  1 sibling, 1 reply; 11+ messages in thread
From: Rajesh S R @ 2011-01-04 18:07 UTC (permalink / raw)
  To: kernelnewbies

On Tue, Jan 4, 2011 at 11:28 PM, Mulyadi Santosa
<mulyadi.santosa@gmail.com>wrote:

> On Wed, Jan 5, 2011 at 00:40, mohit verma <mohit89mlnc@gmail.com> wrote:
> >
> > 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) .
>
> 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
>

Still there can be padding issues due to byte alignment, which may vary
across architecture. Am not sure if that is controllable (probably some
pragma to gcc?). Probably, OP is asking about it?

>
> --
> regards,
>
> Mulyadi Santosa
> Freelance Linux trainer and consultant
>
> blog: the-hydra.blogspot.com
> training: mulyaditraining.blogspot.com
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>



-- 
Rajesh S R
http://rajeshsr.co.cc/blogs/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110104/2050762f/attachment.html 

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

* fixed memory bytes
  2011-01-04 17:58 ` Mulyadi Santosa
  2011-01-04 18:07   ` Rajesh S R
@ 2011-01-04 18:22   ` mohit verma
  2011-01-04 18:25     ` Mulyadi Santosa
  1 sibling, 1 reply; 11+ messages in thread
From: mohit verma @ 2011-01-04 18:22 UTC (permalink / raw)
  To: kernelnewbies

>
> >By using types like u_int or something like that, you pretty much say
> >"I mean 4 byte kind of integer" etc
>
that is it mulyadi. but how the compiler or kernel forces the things to get
initialized in that fixed size only independent of the architecture??

>
> --
> regards,
>
> Mulyadi Santosa
> Freelance Linux trainer and consultant
>
> blog: the-hydra.blogspot.com
> training: mulyaditraining.blogspot.com
>



-- 
........................
*MOHIT VERMA*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110104/1fd16a93/attachment.html 

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

* fixed memory bytes
  2011-01-04 18:07   ` Rajesh S R
@ 2011-01-04 18:24     ` John Mahoney
       [not found]       ` <AANLkTi=jsycWuiG0GdnNjMDz8LJ2amaS6YJsgKPYD3cU@mail.gmail.com>
  0 siblings, 1 reply; 11+ messages in thread
From: John Mahoney @ 2011-01-04 18:24 UTC (permalink / raw)
  To: kernelnewbies

On Tue, Jan 4, 2011 at 1:07 PM, Rajesh S R <srrajesh1989@gmail.com> wrote:
>
>
> On Tue, Jan 4, 2011 at 11:28 PM, Mulyadi Santosa <mulyadi.santosa@gmail.com>
> wrote:
>>
>> On Wed, Jan 5, 2011 at 00:40, mohit verma <mohit89mlnc@gmail.com> wrote:
>> >
>> > 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) .
>>
>> 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
>
>
> Still there can be padding issues due to byte alignment, which may vary
> across architecture. Am not sure if that is controllable (probably some
> pragma to gcc?). Probably, OP is asking about it?

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

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

* fixed memory bytes
  2011-01-04 18:22   ` mohit verma
@ 2011-01-04 18:25     ` Mulyadi Santosa
  0 siblings, 0 replies; 11+ messages in thread
From: Mulyadi Santosa @ 2011-01-04 18:25 UTC (permalink / raw)
  To: kernelnewbies

Hi..

On Wed, Jan 5, 2011 at 01:22, mohit verma <mohit89mlnc@gmail.com> wrote:
> that is it mulyadi. but how the compiler or kernel forces the things to get
> initialized in that fixed size only independent of the architecture??


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

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

* fixed memory bytes
  2011-01-04 17:40 fixed memory bytes mohit verma
  2011-01-04 17:58 ` Mulyadi Santosa
@ 2011-01-04 19:17 ` Denis Kirjanov
  2011-01-04 22:20   ` sk.syed2
  2011-01-04 22:59 ` julie Sullivan
  2 siblings, 1 reply; 11+ messages in thread
From: Denis Kirjanov @ 2011-01-04 19:17 UTC (permalink / raw)
  To: kernelnewbies

On Tue, Jan 4, 2011 at 8:40 PM, mohit verma <mohit89mlnc@gmail.com> wrote:
>
> 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) .

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:
http://lxr.linux.no/#linux+v2.6.36/arch/powerpc/boot/types.h#L8
>
> so ,can please someone? help me to understand this??
>
>
> thanks in advance for help........
> --
> ........................
> MOHIT VERMA
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>



-- 
Regards,
Denis

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

* fixed memory bytes
       [not found]       ` <AANLkTi=jsycWuiG0GdnNjMDz8LJ2amaS6YJsgKPYD3cU@mail.gmail.com>
@ 2011-01-04 21:15         ` John Mahoney
  0 siblings, 0 replies; 11+ messages in thread
From: John Mahoney @ 2011-01-04 21:15 UTC (permalink / raw)
  To: kernelnewbies

Please reply all..I added back list.

On Tue, Jan 4, 2011 at 1:58 PM, mohit verma <mohit89mlnc@gmail.com> wrote:
> thnx john,.........
> but i know that this indicates to compiler to? align the structure to its
> nearest boundries. ? is that so?

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

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

* fixed memory bytes
  2011-01-04 19:17 ` Denis Kirjanov
@ 2011-01-04 22:20   ` sk.syed2
  0 siblings, 0 replies; 11+ messages in thread
From: sk.syed2 @ 2011-01-04 22:20 UTC (permalink / raw)
  To: kernelnewbies

> 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:
> http://lxr.linux.no/#linux+v2.6.36/arch/powerpc/boot/types.h#L8
>>

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

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

* fixed memory bytes
  2011-01-04 17:40 fixed memory bytes mohit verma
  2011-01-04 17:58 ` Mulyadi Santosa
  2011-01-04 19:17 ` Denis Kirjanov
@ 2011-01-04 22:59 ` julie Sullivan
  2011-01-05  6:13   ` Rajat Sharma
  2 siblings, 1 reply; 11+ messages in thread
From: julie Sullivan @ 2011-01-04 22:59 UTC (permalink / raw)
  To: kernelnewbies

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

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110104/8cc94257/attachment.html 

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

* fixed memory bytes
  2011-01-04 22:59 ` julie Sullivan
@ 2011-01-05  6:13   ` Rajat Sharma
  0 siblings, 0 replies; 11+ messages in thread
From: Rajat Sharma @ 2011-01-05  6:13 UTC (permalink / raw)
  To: kernelnewbies

A nice kernel document regarding unaligned memory access. It may not
be directly answering all the questions asked, but once gone through
and understood completely, it will become easy to figure out how to
write portable kernel code.

http://lxr.linux.no/#linux+v2.6.36/Documentation/unaligned-memory-access.txt

Rajat

On Wed, Jan 5, 2011 at 4:29 AM, julie Sullivan <kernelmail.jms@gmail.com> wrote:
>
>> 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) .
>
> 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
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>

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

end of thread, other threads:[~2011-01-05  6:13 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-04 17:40 fixed memory bytes mohit verma
2011-01-04 17:58 ` Mulyadi Santosa
2011-01-04 18:07   ` Rajesh S R
2011-01-04 18:24     ` John Mahoney
     [not found]       ` <AANLkTi=jsycWuiG0GdnNjMDz8LJ2amaS6YJsgKPYD3cU@mail.gmail.com>
2011-01-04 21:15         ` John Mahoney
2011-01-04 18:22   ` mohit verma
2011-01-04 18:25     ` Mulyadi Santosa
2011-01-04 19:17 ` Denis Kirjanov
2011-01-04 22:20   ` sk.syed2
2011-01-04 22:59 ` julie Sullivan
2011-01-05  6:13   ` Rajat Sharma

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).