Expose restore_interactive through the C ABI and Python SDK#126
Merged
Conversation
4913182 to
3414266
Compare
Signed-off-by: Cong Wang <cwang@multikernel.io>
3414266 to
75ade51
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Sandbox::restore_interactive()was Rust-only: the C ABI exposed checkpoint capture/save/load/app_state but no way to restore a process image, so the Python SDK could not reach it (Checkpoint.restoreonly rehydratesapp_state). This PR exposes it end to end, with the same shape at every layer: restore returns a handle to the running process, and skipped-fd diagnostics are queryable off the sandbox rather than cluttering the call signature.Sandbox::restore_interactive(&cp)now returnsResult<Process<'_>>(matchingpopen); the process is already running on return. Fds that could not be transparently recreated (sockets, pipes, memfds, pseudo-filesystem paths) are recorded on theSandboxas structuredSkippedFd { fd, path }entries, queryable viaSandbox::restore_skipped().sandlock_restore_interactive(policy, name, cp) -> sandlock_handle_t*. The restored process is already running (nosandlock_start); on failure the half-built child is reaped before returning NULL. Skipped fds are enumerated withsandlock_handle_restore_skipped_len/_fd/_path(paths are malloc'd strings freed withsandlock_string_free, lifetime-independent of the handle).include/sandlock.hregenerated with cbindgen.Sandbox.restore_interactive(cp) -> Noneinstalls the handle sopid/pause/resume/kill/waitwork on the restored process;Sandbox.restore_skippedreturns the diagnostics asSkippedFdnamed tuples. RaisesRuntimeErrorif the sandbox is already running or the restore fails.python/README.mdSandbox method reference and Checkpoint section.Inherits the core engine limits: x86_64 only, transparent restore currently holds for vDSO-free programs.
Test plan
crates/sandlock-ffi/tests/restore.rs: end-to-end resume through the C ABI (checkpoint a vDSO-free counter guest, kill it, restore into a fresh handle, prove the counter advances past a sentinel), skipped-fd accessor consistency including out-of-range and NULL-handle sentinels, and a null-input case. Skips gracefully off x86_64 or without a C compiler.TestRestoreInteractiveinpython/tests/test_checkpoint.py: the same end-to-end proof through the Python SDK,restore_skippedshape checks, plus the already-running error case.build_fd_planunit tests updated to the structuredSkippedFdshape.🤖 Generated with Claude Code