Skip to content
Snippets Groups Projects
Commit 44d71fea authored by Abdulla Kamar's avatar Abdulla Kamar Committed by CQ bot account: commit-bot@chromium.org
Browse files

[bootsvc] Add fuchsia.boot.RootJob service

This allows processes further down the job-hierarchy to be able to get
access to the RootJob. This is useful for processes such as the
devcoordinator (once component_manager is in place) and utilities like
ps.

Eventually, we will want to further limit or entirely get rid of this
interface. That will happen once component_manager is in place.

ZX-4002
ZX-4072

Change-Id: I4b1e75a7841a04ea2cc7da374e42257d4802e619
parent fc125577
No related branches found
No related tags found
No related merge requests found
......@@ -10,8 +10,8 @@ To test that crashlogs are being added to bootfs, you need to add a CRASHLOG ite
to the boot zbi. For example, to add the contents of README.md as the crashlog:
```
$ scripts/build-zircon-x64 &&
build-x64/tools/zbi -o build-x64/zircon.zbi build-x64/zircon.zbi \
build-gcc/tools/zbi -o build-gcc/zircon.zbi build-gcc/zircon.zbi \
-T CRASHLOG README.md &&
scripts/run-zircon-x64 -V -k -q $(pwd)/../buildtools/linux-x64/qemu/bin \
-c userboot=bin/bootsvc -c bootsvc.next=bin/bootsvc-tests
scripts/run-zircon-x64 -k -c userboot=bin/bootsvc \
-c bootsvc.next=bin/bootsvc-integration-test,testargument
```
......@@ -42,6 +42,7 @@ namespace {
constexpr char kArgumentsPath[] = "/bootsvc/" fuchsia_boot_Arguments_Name;
constexpr char kItemsPath[] = "/bootsvc/" fuchsia_boot_Items_Name;
constexpr char kRootJobPath[] = "/bootsvc/" fuchsia_boot_RootJob_Name;
constexpr char kRootResourcePath[] = "/bootsvc/" fuchsia_boot_RootResource_Name;
// Make sure the loader works
......@@ -166,6 +167,27 @@ bool TestBootItems() {
END_TEST;
}
// Make sure the fuchsia.boot.RootJob service works
bool TestBootRootJob() {
BEGIN_TEST;
zx::channel local, remote;
zx_status_t status = zx::channel::create(0, &local, &remote);
ASSERT_EQ(ZX_OK, status);
// Check that we can open the fuchsia.boot.RootJob service.
status = fdio_service_connect(kRootJobPath, remote.release());
ASSERT_EQ(ZX_OK, status);
// Check that we received a job from the service.
zx::job root_job;
status = fuchsia_boot_RootJobGet(local.get(), root_job.reset_and_get_address());
ASSERT_EQ(ZX_OK, status);
ASSERT_TRUE(root_job.is_valid());
END_TEST;
}
// Make sure the fuchsia.boot.RootResource service works
bool TestBootRootResource() {
BEGIN_TEST;
......@@ -222,6 +244,7 @@ RUN_TEST(TestNamespace)
RUN_TEST(TestArguments)
RUN_TEST(TestBootArguments)
RUN_TEST(TestBootItems)
RUN_TEST(TestBootRootJob)
RUN_TEST(TestBootRootResource)
RUN_TEST(TestVdsosPresent)
END_TEST_CASE(bootsvc_integration_tests)
......@@ -246,6 +246,8 @@ int main(int argc, char** argv) {
svcfs_svc->AddService(fuchsia_boot_Items_Name,
bootsvc::CreateItemsService(loop.dispatcher(), std::move(image_vmo),
std::move(item_map)));
svcfs_svc->AddService(fuchsia_boot_RootJob_Name,
bootsvc::CreateRootJobService(loop.dispatcher()));
svcfs_svc->AddService(fuchsia_boot_RootResource_Name,
bootsvc::CreateRootResourceService(loop.dispatcher()));
......
......@@ -6,6 +6,7 @@
#include <fuchsia/boot/c/fidl.h>
#include <lib/fidl-async/bind.h>
#include <lib/zx/job.h>
#include <zircon/process.h>
#include <zircon/processargs.h>
#include <zircon/status.h>
......@@ -80,6 +81,20 @@ zx_status_t RootResourceGet(void* ctx, fidl_txn_t* txn) {
return fuchsia_boot_RootResourceGet_reply(txn, resource.release());
}
zx_status_t RootJobGet(void* ctx, fidl_txn_t* txn) {
zx::job dup;
zx_status_t status = zx::job::default_job()->duplicate(ZX_RIGHT_SAME_RIGHTS, &dup);
if (status != ZX_OK) {
printf("bootsvc: Failed to duplicate root job: %s\n", zx_status_get_string(status));
return status;
}
return fuchsia_boot_RootJobGet_reply(txn, dup.release());
}
constexpr fuchsia_boot_RootJob_ops kRootJobOps = {
.Get = RootJobGet,
};
constexpr fuchsia_boot_RootResource_ops kRootResourceOps = {
.Get = RootResourceGet,
};
......@@ -123,6 +138,13 @@ fbl::RefPtr<fs::Service> CreateItemsService(async_dispatcher_t* dispatcher, zx::
});
}
fbl::RefPtr<fs::Service> CreateRootJobService(async_dispatcher_t* dispatcher) {
return fbl::MakeRefCounted<fs::Service>([dispatcher](zx::channel channel) {
auto dispatch = reinterpret_cast<fidl_dispatch_t*>(fuchsia_boot_RootJob_dispatch);
return fidl_bind(dispatcher, channel.release(), dispatch, nullptr, &kRootJobOps);
});
}
fbl::RefPtr<fs::Service> CreateRootResourceService(async_dispatcher_t* dispatcher) {
return fbl::MakeRefCounted<fs::Service>([dispatcher](zx::channel channel) {
auto dispatch = reinterpret_cast<fidl_dispatch_t*>(fuchsia_boot_RootResource_dispatch);
......
......@@ -49,6 +49,9 @@ fbl::RefPtr<fs::Service> CreateArgumentsService(async_dispatcher_t* dispatcher,
fbl::RefPtr<fs::Service> CreateItemsService(async_dispatcher_t* dispatcher, zx::vmo vmo,
ItemMap map);
// Create a service to provide the root job.
fbl::RefPtr<fs::Service> CreateRootJobService(async_dispatcher_t* dispatcher);
// Create a service to provide the root resource.
fbl::RefPtr<fs::Service> CreateRootResourceService(async_dispatcher_t* dispatcher);
......
......@@ -8,6 +8,7 @@ fidl_library("fuchsia-boot") {
sources = [
"arguments.fidl",
"items.fidl",
"root-job.fidl",
"root-resource.fidl",
]
}
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
library fuchsia.boot;
/// Protocol for providing the root job.
///
/// TODO(ZX-4072): Do not use this without first consulting the Zircon team.
[Discoverable, Layout = "Simple"]
protocol RootJob {
/// Get the root |job|.
Get() -> (handle<job> job);
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment