-
Notifications
You must be signed in to change notification settings - Fork 102
/
sysmgr.txt
150 lines (125 loc) · 6.05 KB
/
sysmgr.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
main.cc: main()
auto command_line = fxl::CommandLineFromArgcArgv(argc, argv);
CommandLineFromIterators(argv, argv + argc); char **
CommandLineFromIteratorsFindFirstPositionalArg<InputIterator>(first, last, nullptr);
fxl::SetLogSettingsFromCommandLine(command_line)
ParseLogSettings(command_line, &settings)
async::Loop loop(&kAsyncLoopConfigMakeDefault);
Loop::Loop(const async_loop_config_t* config)
async_loop_create(config, &loop_);
async_loop_t* loop = calloc(1u, sizeof(async_loop_t));
初始化一些变量
zx_port_create(0u, &loop->port);
PortDispatcher::Create(options, &dispatcher, &rights);
PortDispatcher(options);
zx_timer_create(0u, ZX_CLOCK_MONOTONIC, &loop->timer);
zx_object_wait_async(loop->timer, loop->port, KEY_CONTROL,
ZX_TIMER_SIGNALED,
ZX_WAIT_ASYNC_REPEATING);
让port等待timer
async_set_default(&loop->async);
g_default = async;
fuchsia::sys::StartupContext::CreateFromStartupInfo()
CreateFromStartupInfoNotChecked();
directory_request = zx_take_startup_handle(PA_DIRECTORY_REQUEST);
service_root = subtle::CreateStaticServiceRootHandle()
创建通向/svc的通道
zx::channel::create(0, &h1, &h2)
fdio_service_connect("/svc/.", h1.release())
fdio_ns_connect(fdio_root_ns, svcpath, ZX_FS_RIGHT_READABLE | ZX_FS_RIGHT_WRITABLE, h);
ns_walk_locked(&vn, &path)
fdio_open_at(vn->remote, path, flags, h);
zxrio_connect(dir, h, ZXRIO_OPEN, flags, 0755, path);
fidl_open_request(svc, cnxn, flags, mode, name, len);
request->hdr.ordinal = ZXFIDL_OPEN;
message.Write(srv, 0);
incoming_services_.Bind(std::move(service_root));
directory_ = std::move(directory);
outgoing_.Serve(std::move(directory_request));
incoming_services_.ConnectToService(environment_.NewRequest());
incoming_services_.ConnectToService(launcher_.NewRequest());
总结:连上"/svc"总服务,打开自己的服务,连上2个子服务。
sysmgr::App app;
RegisterSingleton()注册一个callback给目录服务,当有请求过来时,
要做的事情是把发过来的请求channel handle交给相应的服务。具体如下。
fuchsia::sys::Services services;
dup_launch_info.directory_request = services.NewRequest();
这里生成一个通道。一端给Services留作directory_, 另一端发给服务进程。
这样就建立了Services到服务进程的通道。
it->second.ConnectToService(std::move(client_handle), service_name);
这里会把请求通道handle通过Services的directory_发送给服务进程。
zx::channel CreateStaticServiceRootHandle() {
zx::channel h1, h2;
if (zx::channel::create(0, &h1, &h2) != ZX_OK) return zx::channel();
// TODO(abarth): Use kServiceRootPath once that actually works.
if (fdio_service_connect("/svc/.", h1.release()) != ZX_OK)
return zx::channel();
return h2;
}
当访问一个服务路径的时候,会创建相应的服务,然后连接这个服务
it->second.ConnectToService(std::move(client_handle), service_name)
it->second的类型是component::Services
component::ConnectToService(directory_, std::move(request), service_path)
fdio_service_connect_at(directory.get(), service_path.c_str(),equest.release());
zxrio_connect(dir, h, ZXRIO_OPEN, ZX_FS_RIGHT_READABLE |
ZX_FS_RIGHT_WRITABLE, 0755, path);
zx_channel_write(svc, 0, &msg, ZXRIO_HDR_SZ + msg.datalen, msg.handle, 1)
"apps": [ "netcfg" ]
"apps": [ "thermd" ]
"apps": [ "wlancfg" ]
"apps": [
"device_runner"
]
"apps": [
[ "set_root_view", "dashboard" ]
]
"apps": [
[ "set_root_view", "term" ]
]
"apps": [
[ "set_root_view", "ermine_user_shell" ]
]
"startup_services": [
"fuchsia.amber.Control"
]
先看一下sysmgr是如何与appmgr里的fuchsia::sys::Launcher建立通道的。
sysmgr:
env_launcher_.NewRequest()
InterfaceRequest<Interface> NewRequest() 这个方法创建一个channel, 自己留下一头,
把另一头封在InterfaceRequest<Interface>()里返回出来。
留下的那头会自动bind上,但是没什么用,因为是默认的处理。
env_->GetLauncher(env_launcher_.NewRequest());
->会返回&impl_->proxy
impl_是InterfacePtr<T>::Impl,里面的proxy是Interface::Proxy_,另外还有一个ProxyController.
Environment_Proxy::GetLauncher(::fidl::InterfaceRequest<Launcher> launcher)
controller_->Send(&fuchsia_sys_EnvironmentGetLauncherRequestTable, _encoder.GetMessage(), nullptr);
message.Write(reader_.channel().get(), 0);
appmgr:
Namespace::GetLauncher(fidl::InterfaceRequest<Launcher> launcher)
launcher_bindings_.AddBinding(this, std::move(launcher));
std::make_unique<Binding>(std::forward<ImplPtr>(impl),std::move(request))
Binding与InterfacePtr<>::Impl相对应,里面有Interface::Stub_和StubController
Bind(request.TakeChannel(), async);
controller_.reader().Bind(std::move(channel), async);
wait_.object = channel_.get();
async_begin_wait(async_, &wait_);
async->ops->v1.begin_wait(async, wait);
zx_object_wait_async(wait->object, loop->port, (uintptr_t)wait, wait->trigger, ZX_WAIT_ASYNC_ONCE);
等下次通信的时候,会调用wait对象里的handler.
sysmgr启动app通过fuchsia::sys::Launcher::CreateComponent().
调用的是appmgr里的Namespace::CreateComponent()
sysmgr:
env_launcher_->CreateComponent(std::move(launch_info), nullptr);
appmgr:
realm_->CreateComponent(std::move(launch_info), std::move(controller));
====
blob.manifest里的.config
garnet/bin/kernel_crash_checker/kernel_crash_checker.config
garnet/bin/netcfg/netcfg.config
garnet/bin/netconnector/netconnector.config
garnet/bin/sysmgr/config/network.config
garnet/bin/sysmgr/config/services.config
garnet/bin/thermd/thermd.config
garnet/bin/wlancfg/wlancfg.config
garnet/go/src/amber/startup.config
topaz/bin/ermine/config/ermine.config