mexec_boot/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;
6
7unsafe extern "C" {
8 #[link_name = "mexec_boot"]
9 fn mexec_boot_c(mexec_resource: zx::sys::zx_handle_t) -> zx::sys::zx_status_t;
10}
11
12/// Performs an mexec boot.
13///
14/// This function will obtain the kernel and data ZBIs, prepare them, and then
15/// call the mexec syscall.
16///
17/// `mexec_resource` must be a handle to the mexec resource.
18///
19/// This function does not return on success. On failure, it returns a
20/// `zx::Status`.
21pub fn mexec_boot(mexec_resource: zx::Unowned<'_, zx::Resource>) -> Result<(), zx::Status> {
22 // SAFETY: The C++ function does not take ownership of the handle.
23 let status = unsafe { mexec_boot_c(mexec_resource.raw_handle()) };
24 zx::Status::ok(status)?;
25 // The mexec_boot function should not return on success. If it does, it's an error.
26 Err(zx::Status::INTERNAL)
27}