RE: sys_init_module()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Neeraj,

this construct would work anywhere:

the ((struct module*)0L)->persist_start is not
equivalent to (null_pointer)->persist_start:

why? because its in your definition. A null pointer
need not be 0x000000000... so all we are doing here is
getting the offset of persist_start imagining that the
start address of the structure is at 0x000000000

Basically the offsets are being used relative to the
values at the start of the struct.

and ((struct module*)0L) is *NOT* null_pointer because
 
'The value of the null_pointer is arch/compiler
dependent and cannot be guaranteed that it will be
zero.'

hence on systems where NULL is 'not' 0x00000000 it is
not a NULL_pointer and on other systems it would work
just fine...

(struct module*)0L is always guaranteed to be
0x0000000000 right??!! and it means treat 0x0000000000
as address of the start of the struct module.

and we cast it to a type pointer to perform the
arithmetic.. theres no other use...

I should say this is crafty coding..

-Sharath


> Well, I think I got the point why I was not able to
> convey the actual reason
> behind that previous mail of mine. Please replace
> the NULL (in caps) to
> null-pointer (as defined in the ANSI standard) at
> every place in the mail.  So
> it goes like this -
> 
> As far as I remember, The C standard says that if a
> 0(zero) value is assigned to
> a pointer or is type-casted to a pointer then it is
> converted to the
> null-pointer (and not the #defined NULL).  The value
> of the null-pointer is
> arch/compiler dependent and cannot be guaranteed
> that it will be zero. The code
> in module.c makes use of this point that it presumes
> that the value of null
> pointer is zero. In my understanding the compiler
> interprets the code as:
> 
> 1. (unsigned long)&((struct module
> *)0L)->persist_start // this parses to 2.
> 
> 2. (unsigned long)&(null-pointer)->persist_start) //
> this parses to 3.
> 
> 3. (unsigned long)&(value at address (null-pointer +
> offset of persist_start)) // this parses to 4.
> 
> 4. (unsigned long)(0 + offset of persist_start) //
> and this gives the offset of
> persist_start in the structure as null-pointer is
> considered to be zero.
> 
> So, in this manner the null-pointer comes into play.
> Do correct me if I am wrong
> in interpreting the things. Also, on second
> thoughts, is it specific to gcc in
> any way such that gcc guarantees for every platform
> that the null-pointer (as
> defined in the ANSI standard) will have a value
> 0(zero) ? Or the above method of
> dereferencing will give the offset of the field in
> question ?
> 
> -neeraj
> 
> PS: I was a bit busy so could not post this query of
> mine with the required
> corrections.
> 
> 
> 
> --
> Kernelnewbies: Help each other learn about the Linux
> kernel.
> Archive:      
> http://mail.nl.linux.org/kernelnewbies/
> FAQ:           http://kernelnewbies.org/faq/
> 


=====
-Sharath

__________________________________________________
Do You Yahoo!?
Yahoo! Games - play chess, backgammon, pool and more
http://games.yahoo.com/
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux