fix(small crates): the proof lint now covers every first-party crate but one
Six crates were still unguarded, and all six are OURS — none vendored: pf-console-ui, pf-gpu, punktfunk-tray, clients/windows, tools/display-disturb, wdk-probe. Two of them ship (the tray and the Windows client), so "small" was about item count, not exposure. Five are closed here. Only 17 of their 75 unsafe items actually lacked a proof — pf-gpu, punktfunk-tray and display-disturb were already fully documented and needed nothing but the deny, which is the good case: the convention was being followed, just not enforced. The 17 that were missing are the usual Win32/COM shapes, and two were worth stating properly. `clients/windows`'s `GetCurrentPackageFullName` is called with `len = 0` and no buffer — that is the documented identity PROBE, which writes nothing, and reading it as a normal query would be a mistake. `pf-console-ui`'s two `destroy_image_view` calls are the load-bearing ones: the comment above one already argued that in-flight sampling of that slot ended two presents ago (the ring alternates and the presenter waits its fence before each record), which is exactly the kind of reasoning a `// SAFETY:` should carry and it was sitting there unlabelled. Also fixes a real Windows-only clippy error this uncovered: `pf-gpu` had a `#[cfg(target_os = "windows")]` fn AFTER its `mod tests`, tripping `items_after_test_module`. It never fired on Linux (the item does not exist there) and no CI job clippies pf-gpu on Windows, so it sat unseen. Moved above the test module. Remaining: `wdk-probe` (26 items) alone, and only because it needs the WDK to build — .47 cannot, so nothing here can verify a deny on it. Verified: Linux .21 fmt + both CI clippy steps rc=0; Windows .47 the four Windows-relevant crates at `-D warnings` rc=0.
This commit is contained in:
@@ -10,6 +10,9 @@
|
||||
//! own keyboard types through SDL text input) — plus the in-stream chrome: stats OSD,
|
||||
//! capture hint, start banner.
|
||||
|
||||
// Unsafe-proof program: every `unsafe {}` in the Skia/Vulkan overlay carries a `// SAFETY:` proof.
|
||||
#![deny(clippy::undocumented_unsafe_blocks)]
|
||||
|
||||
#[cfg(any(target_os = "linux", windows))]
|
||||
mod anim;
|
||||
#[cfg(any(target_os = "linux", windows))]
|
||||
|
||||
@@ -427,6 +427,9 @@ impl Shell {
|
||||
|
||||
fn draw_aurora(&self, canvas: &Canvas, w: f64, h: f64, t: f64) {
|
||||
let uniforms: [f32; 3] = [w as f32, h as f32, t as f32];
|
||||
// SAFETY: `uniforms` is a local `[f32; 3]` — exactly 12 bytes — and `f32` has no padding or
|
||||
// invalid bit patterns, so reading it as bytes is sound; the slice is copied by
|
||||
// `Data::new_copy` before `uniforms` goes out of scope.
|
||||
let bytes = unsafe { std::slice::from_raw_parts(uniforms.as_ptr().cast::<u8>(), 12) };
|
||||
match self.mesh.make_shader(Data::new_copy(bytes), &[], None) {
|
||||
Some(shader) => {
|
||||
|
||||
@@ -190,6 +190,9 @@ impl Drop for SkiaOverlay {
|
||||
fn drop(&mut self) {
|
||||
if let Some(gpu) = &mut self.gpu {
|
||||
for slot in self.slots.iter_mut().flat_map(Option::take) {
|
||||
// SAFETY: the view belongs to this slot and the overlay is being dropped, so no
|
||||
// further recording can reference it; the flush/submit + queue guard below is what
|
||||
// retires any work that still could.
|
||||
unsafe { gpu.device.destroy_image_view(slot.view, None) };
|
||||
drop(slot.surface);
|
||||
}
|
||||
@@ -208,6 +211,10 @@ impl Overlay for SkiaOverlay {
|
||||
let entry = shared.entry.clone();
|
||||
let instance = shared.instance.clone();
|
||||
let get_proc = move |of: skvk::GetProcOf| -> *const std::ffi::c_void {
|
||||
// SAFETY: Skia calls this loader with raw instance/device handles it received from the
|
||||
// `BackendContext` below — i.e. the very ones owned by `shared`, still live for the
|
||||
// overlay's lifetime — and `from_raw` only rewraps them for the ash entry points. Each
|
||||
// name is a NUL-terminated C string from Skia, borrowed for the call.
|
||||
unsafe {
|
||||
match of {
|
||||
skvk::GetProcOf::Instance(raw_instance, name) => entry
|
||||
@@ -223,6 +230,9 @@ impl Overlay for SkiaOverlay {
|
||||
}
|
||||
}
|
||||
};
|
||||
// SAFETY: the instance/physical-device/device handles come from `shared`, which owns them
|
||||
// and outlives this backend context, and `get_proc` above resolves through those same
|
||||
// handles. Skia stores them but does not take ownership — teardown stays ours.
|
||||
let backend = unsafe {
|
||||
skvk::BackendContext::new(
|
||||
shared.instance.handle().as_raw() as _,
|
||||
@@ -525,6 +535,9 @@ impl SkiaOverlay {
|
||||
if let Some(old) = self.slots[i].take() {
|
||||
// Any in-flight sampling of THIS slot ended two presents ago (the ring
|
||||
// alternates and the presenter waits its fence before each record).
|
||||
// SAFETY: the view belongs to the slot being replaced, and per the comment above any
|
||||
// in-flight sampling of THIS slot ended two presents ago — the ring alternates and the
|
||||
// presenter waits its fence before each record — so the GPU is done with it.
|
||||
unsafe { gpu.device.destroy_image_view(old.view, None) };
|
||||
}
|
||||
let info =
|
||||
@@ -549,6 +562,9 @@ impl SkiaOverlay {
|
||||
.vulkan_image_info()
|
||||
.context("backend texture is not Vulkan")?;
|
||||
let image = avk::Image::from_raw(*image_info.image() as u64);
|
||||
// SAFETY: a create call on the live device `gpu` owns, over a builder that is a local
|
||||
// outliving the call; `image` is the VkImage Skia just reported for this backend texture,
|
||||
// which the surface keeps alive. The returned view is owned by the slot stored below.
|
||||
let view = unsafe {
|
||||
gpu.device.create_image_view(
|
||||
&avk::ImageViewCreateInfo::default()
|
||||
|
||||
+39
-36
@@ -22,6 +22,9 @@
|
||||
//! running session keeps the device it opened on. [`session_begin`]/[`active`] record which GPU a
|
||||
//! live session actually encodes on, for the console's "in use" display.
|
||||
|
||||
// Unsafe-proof program: every `unsafe {}` in this leaf carries a `// SAFETY:` proof.
|
||||
#![deny(clippy::undocumented_unsafe_blocks)]
|
||||
|
||||
use anyhow::Result;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
@@ -716,6 +719,42 @@ pub fn active() -> Option<(ActiveGpu, u32)> {
|
||||
.map(|s| (s.gpu.clone(), s.sessions))
|
||||
}
|
||||
|
||||
/// Pick the render GPU LUID the Windows pipeline is created on: the IDD-push capturer's
|
||||
/// shared-texture ring, the IddCx `SET_RENDER_ADAPTER` pin, and (via the captured frame's device)
|
||||
/// NVENC/AMF/QSV all follow this one decision — see [`selected_gpu`] for the precedence (operator
|
||||
/// preference > `PUNKTFUNK_RENDER_ADAPTER` substring > max `DedicatedVideoMemory`). A configured
|
||||
/// preference that doesn't match a present GPU falls back to auto selection (with a warning) rather
|
||||
/// than returning `None`, so a stale preference never stops the host from streaming.
|
||||
///
|
||||
/// Lives here (not in a host module) so BOTH the capture and encode subsystem crates depend on it
|
||||
/// as a peer of GPU selection instead of the orchestrator — the plan's `windows/adapter.rs`, folded
|
||||
/// into `pf-gpu` (plan §W6). It was historically the SudoVDA backend's, then the host's
|
||||
/// `win_adapter.rs`; the LUID-shaped view of [`selected_gpu`] plus the per-decision logging.
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn resolve_render_adapter_luid() -> Option<windows::Win32::Foundation::LUID> {
|
||||
match selected_gpu() {
|
||||
Some(sel) => {
|
||||
tracing::info!(
|
||||
adapter = sel.info.name,
|
||||
vram_mb = sel.info.vram_bytes / (1024 * 1024),
|
||||
source = sel.source.tag(),
|
||||
"render adapter selected"
|
||||
);
|
||||
if sel.source == PickSource::PreferenceMissing {
|
||||
tracing::warn!(
|
||||
"the preferred GPU is not present — auto-selected the adapter above \
|
||||
(fix or clear the preference in the web console)"
|
||||
);
|
||||
}
|
||||
Some(sel.info.luid())
|
||||
}
|
||||
None => {
|
||||
tracing::warn!("no suitable render adapter found for SET_RENDER_ADAPTER");
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -914,39 +953,3 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Pick the render GPU LUID the Windows pipeline is created on: the IDD-push capturer's
|
||||
/// shared-texture ring, the IddCx `SET_RENDER_ADAPTER` pin, and (via the captured frame's device)
|
||||
/// NVENC/AMF/QSV all follow this one decision — see [`selected_gpu`] for the precedence (operator
|
||||
/// preference > `PUNKTFUNK_RENDER_ADAPTER` substring > max `DedicatedVideoMemory`). A configured
|
||||
/// preference that doesn't match a present GPU falls back to auto selection (with a warning) rather
|
||||
/// than returning `None`, so a stale preference never stops the host from streaming.
|
||||
///
|
||||
/// Lives here (not in a host module) so BOTH the capture and encode subsystem crates depend on it
|
||||
/// as a peer of GPU selection instead of the orchestrator — the plan's `windows/adapter.rs`, folded
|
||||
/// into `pf-gpu` (plan §W6). It was historically the SudoVDA backend's, then the host's
|
||||
/// `win_adapter.rs`; the LUID-shaped view of [`selected_gpu`] plus the per-decision logging.
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn resolve_render_adapter_luid() -> Option<windows::Win32::Foundation::LUID> {
|
||||
match selected_gpu() {
|
||||
Some(sel) => {
|
||||
tracing::info!(
|
||||
adapter = sel.info.name,
|
||||
vram_mb = sel.info.vram_bytes / (1024 * 1024),
|
||||
source = sel.source.tag(),
|
||||
"render adapter selected"
|
||||
);
|
||||
if sel.source == PickSource::PreferenceMissing {
|
||||
tracing::warn!(
|
||||
"the preferred GPU is not present — auto-selected the adapter above \
|
||||
(fix or clear the preference in the web console)"
|
||||
);
|
||||
}
|
||||
Some(sel.info.luid())
|
||||
}
|
||||
None => {
|
||||
tracing::warn!("no suitable render adapter found for SET_RENDER_ADAPTER");
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
//! then the host's loopback-only unauthenticated `GET /api/v1/local/summary` for the streaming
|
||||
//! details. Windows-subsystem binary — a console exe in the HKLM Run key would flash a terminal
|
||||
//! window at every sign-in.
|
||||
// Unsafe-proof program: every `unsafe {}` in the tray carries a `// SAFETY:` proof.
|
||||
#![deny(clippy::undocumented_unsafe_blocks)]
|
||||
#![cfg_attr(windows, windows_subsystem = "windows")]
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
|
||||
Reference in New Issue
Block a user