应用的启动及b2g,nuwa,preallocated ,app 间消息的获取与传输

17 篇文章 0 订阅

应用的启动及b2g,nuwa,preallocated ,app 消息的获取与传输。

几个阶段:

1.b2g 初始化自身,并请求与Prenuwa 连接,(做好准备,各种数据及环境配置窗口创建等)目的是Load Nuwa。(入口/nsAppRunner.cpp:4349,Fun:XRE_mainRun)

nsAppStartup.cpp:320,Fun:Run 作为与PreNuwa的接口吧?(启动app的入口)

2.PreNuwa 从b2g fork出来,初始化并运行ProcLoader service 端(ProcLoaderServiceRun)

3.(未知谁请求的)PProcLoaderParent.cpp:444,Fun:OnChannelConnected连接成功,ContentParent.cpp:772,Fun:RunNuwaProcess 开始load 请求,具体Load

4.开始RunNNuwaProcess(b2g, ContentParent.cpp:772,Fun:RunNuwaProcess),此为Load Nuwa的模块,细节一系列复杂操作,最终 preNuwa ContentChild.cpp:716,Fun:Init call -- GetIPCChannel()->BlockScripts();使b2g能连接通道?

5.Nuwa Load 请求成功,b2g GeckoChildProcessHost.cpp:1106,Fun:OnChannelConnected call -- OpenPrivilegedHandle(peer_pid: 547 ); 连接上通道,b2g  /ProcessUtils_linux.cpp:309,Fun:ProcLoaderClientDeinit   call MessageLoop::current() 释放client资源,意味着其使命完成。

6.PreNuwa 设置ContentChild.cpp:768,Fun:InitProcessAttributes call -- SetProcessName(NS_LITERAL_STRING('(Nuwa)'), false); 设置名字。目前为止只是有了nuwa的名字,

 

7.Nuwa进程 对Nuwa进行完善,ContentProcess.cpp:126,Fun:Init call -- mXREEmbed.Start(); 初始化/XPCOMInit.cpp:535,Fun:NS_InitXPCOM2 开启各种各样线程??(未完全确定是否是这里)

ContentChild.cpp:1104,Fun:InitXPCOM call -- InitOnContentProcessCreated();

...

ContentChild.cpp:2539,Fun:OnFinishNuwaPreparation

完成这里后,nuwa就具备基本的b2g线程,似乎也与hidden window 建立连接?但还可以基于此nuwa真正创建新进程。

 

8.将目前这个进程设置为Nuwa, Nuwa.cpp:1976,Fun:MakeNuwaProcess.

Nuwa.cpp:2000,Fun:MakeNuwaProcess call -- OnNuwaProcessReady()

NuwaChild.cpp:301,Fun:OnNuwaProcessReady call -- mozilla::unused << nuwaChild->SendNotifyReady()

接着b2g 就收到消息了,ContentParent.cpp:3141,Fun:OnNuwaReady call -- PreallocatedProcessManager::OnNuwaReady(); -

 

9.现在可以基于nuwa来fork进程了,preallocated process 管理器请求创建新进程(preallocated proc)

PreallocatedProcessManager.cpp:420,Fun:OnNuwaReady call -- NuwaFork(),

10.fork新进程,

b2g 发消息NuwaParent.cpp:285,Fun:operator() call -- mozilla::unused << self->SendFork();nuwa收到消息NuwaChild.cpp:179,Fun:RecvFork,

具体:

nuwa 进程Nuwa.cpp:1902,Fun:NuwaSpawnPrepare,

Nuwa.cpp:1944,Fun:NuwaSpawn call -- pid = ForkIPCProcess(); --->

Nuwa.cpp:1839,Fun:ForkIPCProcess call -- * Fork a new process that is ready for running IPC.

Nuwa.cpp:1790,Fun:AddNewProcess call -- AddNewIPCProcess(pid:757, aInfoList, aInfoSize);

/NuwaChild.cpp:278,Fun:AddNewIPCProcess call -- * AddNewIPCProcess() is called by Nuwa process to tell the parent * process that a new process is created 告诉b2g 新进程已创建,应该是返回值0/1,

/Nuwa.cpp:1876,Fun:ForkIPCProcess call -- ReplaceIPC(sProtoFdInfos, sProtoFdInfosSize);创建进程的点

Nuwa.cpp:1608,Fun:RecreateThreads call -- * Recreate all threads in a process forked from an Nuwa process.重建线程

/ContentChild.cpp:620,Fun:ResetTransports -----重置连接通道

 

11.设置进程名称,b2g与目标Preallocated proc建立连接并初始化它,设置名字

b2g 收到创建进程成功的消息,NuwaParent.cpp:238,Fun:RecvAddNewProcess ------------------------

GeckoChildProcessHost.cpp:472,Fun:LaunchAndWaitForProcessHandle call -- PrepareLaunch(); 准备启用APP进程,异步启动循环几次message loop后收到目标pid,GeckoChildProcessHost.cpp:1106,Fun:OnChannelConnected call -- OpenPrivilegedHandle(peer_pid: 757 );

建立连接成功,获取xpcom属性,获取隐藏窗口,也是在这里nuwa fork出的子进程完成了,return 0;

Pre_Preallocated proc ,Nuwa.cpp:1893,Fun:ForkIPCProcess call -- return pid:0; 子进程返回0

Pre_Preallocated proc ,ContentChild.cpp:774,Fun:InitProcessAttributes call -- SetProcessName(NS_LITERAL_STRING('(Preallocated app)'), false); ---> 进程设置自己的名字

ContentChild.cpp:590,Fun:InitOnContentProcessCreated --进程初始化

 

 

12.准备成为其他APP应用的进程,

ContentChild.cpp:2576,Fun:RecvAppInfo 接收到APP信息,谁发的?似乎是b2g 的nsAppstartup。

preallocated proc,ContentChild.cpp:998,Fun:GetProcessName 获取到进程名字,两个进程获取了同一个窗口???所以连接?未知

 

13.b2g 创建应用,

b2g ,ContentParent.cpp:1296,Fun:CreateBrowserOrApp call -- bool isInContentProcess = !XRE_IsParentProcess(); 创建应用,

b2g ,ContentParent.cpp:1454,Fun:CreateBrowserOrApp call -- p = GetNewOrPreallocatedAppProcess(ownApp, --->获取preallocated proc进程,

极其重要的一条,b2g ,ContentParent.cpp:1812,Fun:TransformPreallocatedIntoApp 把preallocated 和app 打通。

prea,ContentChild.cpp:764,Fun:InitProcessAttributes --初始化进程属性,设置进程名为home screen

 

 

完成了第一app 应用进程的创建。

 

b2g 中一直有nsAppStartup.cpp:599,Fun:GetShuttingDown -------,它是要关什么?且一直关,没完没了?公用的关闭应用进程用的?

homescreen 也ContentChild.cpp:998,Fun:GetProcessName -是要获取点击图标时获取的应用吗

 

14.第2个app 应用,

不知谁通知了preallcoated proc 管理器,在b2g里面就自动开始创建preallocated ,应该是有一个队列?或者前面将preallocated 给APP应用后会返回值,小意思。

 

循环,preallocated 的创建过程,

b2g,PreallocatedProcessManager.cpp:433,Fun:NuwaFork.

b2g, NuwaParent.cpp:276,Fun:ForkNewProcess

 

nuwa ,/NuwaChild.cpp:179,Fun:RecvFork ,

NuwaChild.cpp:143,Fun:NuwaFork,

NuwaChild.cpp:109,Fun:DoNuwaFork,

Nuwa.cpp:1944,Fun:NuwaSpawn call -- pid = ForkIPCProcess();

Nuwa.cpp:1838,Fun:ForkIPCProcess

等等,

/NuwaChild.cpp:288,Fun:AddNewIPCProcess call -- RefPtr<RunAddNewIPCProcess> runner = new RunAddNewIPCProcess(aPid:885, maps);把创建出的进程调度到主线程中?谁的主线程

NuwaChild.cpp:290,Fun:AddNewIPCProcess call -- NS_DispatchToMainThread(runner);

以上在nuwa中做的,

接着就进入preallocated ,进行线程重建,初始化等

b2g收到已创建的消息,开始准备装入APP应用进程ContentParent.cpp:3161,Fun:OnNewProcessCreated call -- content = new ContentParent(this,。GeckoChildProcessHost.cpp:472,Fun:LaunchAndWaitForProcessHandle call -- PrepareLaunch(); 准备启动,也在b2g中进行通道创建和连接,GeckoChildProcessHost.cpp:1205,Fun:InitializeChannel call -- CreateChannel(mExistingFileDescriptor);

ContentParent.cpp:2554,Fun:ContentParent call -- Open(mSubprocess->GetChannel(), base::GetProcId(mSubprocess->GetChildProcessHandle())); --->连接成功,对新创建的prea proc 进行初始化ContentParent.cpp:3166,Fun:OnNewProcessCreated call -- content->Init();

 

 

Pre preallocated 设置自己的名字为preallocated,

 

preallocated进程 收到appinfo,并接收到app int初始化

b2g 创建APP应用,并

ContentParent.cpp:822,Fun:GetNewOrPreallocatedAppProcess ----------------------------------
ContentParent.cpp:1812,Fun:TransformPreallocatedIntoApp ----------------------------------
将preallocated proc 与APP应用连接好,

然后连通好之后的preallocated proc

ContentChild.cpp:764,Fun:InitProcessAttributes ----------------------------------
ContentChild.cpp:774,Fun:InitProcessAttributes call -- SetProcessName(NS_LITERAL_STRING('(Preallocated app)'), false); --->
ContentChild.cpp:789,Fun:SetProcessName ----------------------------------
ContentChild.cpp:789,Fun:SetProcessName ----------------------------------
ContentChild.cpp:998,Fun:GetProcessName ----------------------------------
设置进程属性,设置进程名。

 

 

完成keyboad 应用的进程入驻。

 

15.接着又循环下去

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值