Skip to main content

userboot/
lib.rs

1// Copyright 2026 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use zx::sys::zx_handle_t;
6use zx::{Channel, HandleInfo, NullableHandle, Status};
7
8unsafe extern "C" {
9    fn TakeBootstrapChannel() -> zx_handle_t;
10}
11
12/// This transfers ownership of the channel from the kernel where the message
13/// full of system handles can be read.
14pub fn take_bootstrap_channel() -> Channel {
15    unsafe { NullableHandle::from_raw(TakeBootstrapChannel()) }.into()
16}
17
18// Re-export these for general use.
19pub use zx_libc::sanitizer::{Log, log};
20
21/// This reads the system capability message from the bootstrap channel.
22/// It is mutually exclusive with take_bootstrap_channel().
23pub fn take_system_handles() -> Result<Vec<HandleInfo>, Status> {
24    let mut handles = Vec::new();
25    let channel = take_bootstrap_channel();
26    let mut bytes = Vec::new();
27    channel.read_etc_split(&mut bytes, &mut handles)?;
28    assert!(bytes.is_empty());
29    Ok(handles)
30}