RE: sys_init_module()

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

 



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/


[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