User:Tedd/ipc-doc-preview: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 114: Line 114:
After the object creation is completed, the '''[https://github.com/mozilla/gecko-dev/blob/6f80c55849c36f46f48941f735c8228b7e2f36d0/ipc/chromium/src/chrome/common/ipc_channel_posix.cc#L395 Connect]''' method can be called, this method will tell ''libevent'' to notify us whenever something has been written to '''pipe_''' and is ready to be received.  
After the object creation is completed, the '''[https://github.com/mozilla/gecko-dev/blob/6f80c55849c36f46f48941f735c8228b7e2f36d0/ipc/chromium/src/chrome/common/ipc_channel_posix.cc#L395 Connect]''' method can be called, this method will tell ''libevent'' to notify us whenever something has been written to '''pipe_''' and is ready to be received.  


'''[https://github.com/mozilla/gecko-dev/blob/6f80c55849c36f46f48941f735c8228b7e2f36d0/ipc/chromium/src/chrome/common/ipc_channel_posix.cc#L818 OnFileCanReadWithoutBlocking]''' is the callback for this event.
'''[https://github.com/mozilla/gecko-dev/blob/6f80c55849c36f46f48941f735c8228b7e2f36d0/ipc/chromium/src/chrome/common/ipc_channel_posix.cc#L818 OnFileCanReadWithoutBlocking]''' is the callback for this event. This function will then call a function to read the message from the file descriptor and then the message will be passed to the '''OnMessageReceived''' function inside the '''listener_''' (this will be covered later).


Here a short illustration of the call flow:
Here a short illustration of the call flow:
Line 147: Line 147:
Inside the '''ContentParent''' constructor, a couple of interesting things happen.
Inside the '''ContentParent''' constructor, a couple of interesting things happen.
* we insert the new '''ContentParent''' into the global static list called '''[https://github.com/mozilla/gecko-dev/blob/6f80c55849c36f46f48941f735c8228b7e2f36d0/dom/ipc/ContentParent.cpp#L512 sContentParent]'''
* we insert the new '''ContentParent''' into the global static list called '''[https://github.com/mozilla/gecko-dev/blob/6f80c55849c36f46f48941f735c8228b7e2f36d0/dom/ipc/ContentParent.cpp#L512 sContentParent]'''
* we create a '''[https://github.com/mozilla/gecko-dev/blob/6f80c55849c36f46f48941f735c8228b7e2f36d0/ipc/glue/GeckoChildProcessHost.h#L28 GeckoChildProcessHost]''' instance  
* we create a '''[https://github.com/mozilla/gecko-dev/blob/6f80c55849c36f46f48941f735c8228b7e2f36d0/ipc/glue/GeckoChildProcessHost.h#L28 GeckoChildProcessHost]''' instance
* we call the '''[https://github.com/mozilla/gecko-dev/blob/6f80c55849c36f46f48941f735c8228b7e2f36d0/ipc/glue/GeckoChildProcessHost.cpp#L385 LaunchAndWaitForProcessHandle]''' method of '''GeckoChildProcessHost'''
* we call the '''[https://github.com/mozilla/gecko-dev/blob/6f80c55849c36f46f48941f735c8228b7e2f36d0/ipc/glue/GeckoChildProcessHost.cpp#L385 LaunchAndWaitForProcessHandle]''' method of '''GeckoChildProcessHost'''


The '''LaunchAndWaitForProcessHandle''' method will schedule a task inside the ''IOLoop'' thread. In the ''IOLoop'' thread, '''[https://github.com/mozilla/gecko-dev/blob/6f80c55849c36f46f48941f735c8228b7e2f36d0/ipc/glue/GeckoChildProcessHost.cpp#L479 RunPerformAsyncLaunch]''' is called. After a few calls, we will end up in the '''[https://github.com/mozilla/gecko-dev/blob/6f80c55849c36f46f48941f735c8228b7e2f36d0/ipc/chromium/src/base/process_util_linux.cc#L191 LaunchApp]''' function. This is where the forking happens. After the '''fork''', it will call '''execve''' to re-execute itself.
The '''LaunchAndWaitForProcessHandle''' method will schedule a task inside the ''IOLoop'' thread. In the ''IOLoop'' thread, '''[https://github.com/mozilla/gecko-dev/blob/6f80c55849c36f46f48941f735c8228b7e2f36d0/ipc/glue/GeckoChildProcessHost.cpp#L479 RunPerformAsyncLaunch]''' is called. After a few calls, we will end up in the '''[https://github.com/mozilla/gecko-dev/blob/6f80c55849c36f46f48941f735c8228b7e2f36d0/ipc/chromium/src/base/process_util_linux.cc#L191 LaunchApp]''' function. This is where the forking happens. After the '''fork''', it will call '''execve''' in the child to re-execute itself.


[[File:Ipc nuwa fork.png|900px|frameless|center|Call flow for nuwa fork]]
[[File:Ipc nuwa fork.png|900px|frameless|center|Call flow for nuwa fork]]


=== connect to the channel ===
=== connect to the channel ===
We covered the actual spawning, what's left is the part where the parent (''b2g'') and the child (''nuwa'') connect to the same IPC channel.
We have two important calls for that on the parent side, one is made before the child was spawned, the other after the spawn. The first one is in the '''RunPerformAsynchLaunch''' function, before actually calling '''PerformAsynchLaunch''' (the position is marked with a 'x' in the above diagram), we call '''[https://github.com/mozilla/gecko-dev/blob/6f80c55849c36f46f48941f735c8228b7e2f36d0/ipc/glue/GeckoChildProcessHost.cpp#L405 InitializeChannel]''' this will call '''[https://github.com/mozilla/gecko-dev/blob/6f80c55849c36f46f48941f735c8228b7e2f36d0/ipc/chromium/src/chrome/common/child_process_host.cc#L77 CreateChannel]'''. At this point a new '''IPC::Channel''' object is created, so please checkout the [[#Channel]] section above.
The '''GeckoChildProcessHost''' object created inside the '''ContentParent''' constructor, serves as the '''listener_''' inside the '''IPC::Channel''' object. So '''GeckoChildProcessHost''' will supply the '''[https://github.com/mozilla/gecko-dev/blob/6f80c55849c36f46f48941f735c8228b7e2f36d0/ipc/glue/GeckoChildProcessHost.cpp#L895 OnMessageReceived]''' function. There is nothing done there, it just saves all the incoming messages.
At this point we can consider the parent process to be connected to the channel. This was the first important call.
The second one is called as soon as '''LaunchAndWaitForProcessHandle''' returned (''nuwa'' process is running at this point). Since the current '''OnMessageReceived''' handler doesn't do any good, we will have to assign a new '''listener_'''. In order to do that, this is being executed ('''mSubprocess''' is an instance of '''GeckoChildProcessHost''' which is created in '''ContentParent'''):
<pre>
Open(mSubprocess->GetChannel(), mSubprocess->GetOwnedChildProcessHandle());
</pre>


== Preallocated ==
== Preallocated ==
Confirmed users
85

edits

Navigation menu