Re: sys_init_module()

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

 



=> NULL isn't used anywhere in this code. 0 is used. Essentially, you've
=> subtracted 0 from the original address, which is unnecessary.

Hi John,

I think you misinterpreted the thing. 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, i.e. it is treated as the NULL
pointer. 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)->persist_start) // this parses to 3.

3. (unsigned long)&(value at address (0 + 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

So, in this manner NULL comes into play. Do correct me if I am wrong in
interpreting the things.

neeraj



=> 
=> On Thu, 18 Apr 2002, Neeraj wrote:
=> 
=> > Thanks John.
=> >
=> > Later I understood the code. But I would like to ask that is this code portable
=> > ? becoz when you are using (struct module *)0L then it is going to become a NULL
=> > pointer and it is not necessary NULL will have a value 0 (zero). So would'nt it
=> > be better if this code is written as :
=> >
=> > ((unsigned long)&((struct module *)0L)->persist_start - (unsigned long)(struct
=> > module *)0L)
=> >
=> > I think this is portable!
=> >
=> > -neeraj
=> >
=> > => 0L refers to the number 0 as a Long integer.
=> > =>
=> > => Basically, what is happening is, the kernel is acting as if the module
=> > => struct is located at address 0. Obviously, this structure isn't there, but
=> > => the effect is that the address returned is the size of the data contained
=> > => in the structure before the persist_start member.
=> > =>
=> > => John
=> > =>
=> > => On Thu, 18 Apr 2002, Neeraj wrote:
=> > =>
=> > => > Hello friends,
=> > => >
=> > => > I have just started reading the kernel code and hence a kernel newbie. Right now
=> > => > I am reading the code of Linux kernel version 2.4.3. The file module.c conatins
=> > => > a function sys_init_module. I am not able to the understand the following LOC.
=> > => >
=> > => > <snip>
=> > => >
=> > => > if (mod_user_size < (unsigned long)&((struct module *)0L)->persist_start
=> > => >
=> > => > </snip>
=> > => >
=> > => > What does 0L refers to ? Can somebody please explain it to me.
=> > => >
=> > => > Thanks
=> > => > neeraj
=> > => >
=> > => >
=> > => >
=> > => > --
=> > => > Kernelnewbies: Help each other learn about the Linux kernel.
=> > => > Archive:       http://mail.nl.linux.org/kernelnewbies/
=> > => > FAQ:           http://kernelnewbies.org/faq/
=> > => >
=> > =>
=> > =>
=> >
=> > --
=> > Kernelnewbies: Help each other learn about the Linux kernel.
=> > Archive:       http://mail.nl.linux.org/kernelnewbies/
=> > FAQ:           http://kernelnewbies.org/faq/
=> >
=> 
=> 


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