inline asm question(s)

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

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi there people,
I'm trying to figure out for several days now how the following functions:

<from include/asm-i386/thread_info.h>
 86 /* how to get the thread information struct from C */
 87 static inline struct thread_info *current_thread_info(void)
 88 {
 89         struct thread_info *ti;
 90         __asm__("andl %%esp,%0; ":"=r" (ti) : "" (~(THREAD_SIZE - 1)));
 91         return ti;
 92 }

I've read several tutorials on inline asm but what is peculiar here is, that 
the input operand's constraint is "" (nothing) whereas the (~(THREAD_SIZE-1)) 
= (~(8192-1)) = (~0001 1111 1111 1111) = 1110 0000 0000 0000, IIRC, gets 
passed as a C arg.
What exactly happens here?

I also have another question:

<from include/linux/kernel.h>
203 /**
204  * container_of - cast a member of a structure out to the containing 
structure
205  *
206  * @ptr:        the pointer to the member.
207  * @type:       the type of the container struct this is embedded in.
208  * @member:     the name of the member within the struct.
209  *
210  */
211 #define container_of(ptr, type, member) ({                      \
212         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
213         (type *)( (char *)__mptr - offsetof(type,member) );})

I can't understand the ((type *)0) part - type is passed as an argument and it 
is some struct pointer but the trailing 0 ... what does it actually do?

offsetof is similar:

<from include/linux/stddef.h>
 12 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)

Thanks in advance,
Boris.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFA4mJsiBySr3Fn37QRArnwAJ40BJugFsZcml0yBFcfte0ioscgvwCglzvb
0yUGR6cEkpOBm1CgnAgMnNQ=
=Ifgz
-----END PGP SIGNATURE-----

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