Add FreeBSD support for remote_server

Gate crash-handler and minidumper behind cfg(not(target_os = "freebsd"))
since neither crate supports FreeBSD. Provide no-op stubs in the crashes
crate so remote_server compiles and links without them.

Add target_os = "freebsd" to gpui queue module cfg gates (same POSIX
APIs as Linux).

Fix MaybeUninit usage in fs::current_path() for FreeBSD: use zeroed()
and assume_init_mut() instead of uninit() + as_mut_ptr() which is UB
when accessing fields of uninitialized memory.

Release Notes:

- N/A
This commit is contained in:
G36maid 2026-05-01 12:21:13 +08:00
parent 481854f754
commit 7959d600c1
8 changed files with 69 additions and 12 deletions

4
Cargo.lock generated
View file

@ -4144,11 +4144,15 @@ name = "crashes"
version = "0.1.0"
dependencies = [
"async-process",
"cfg-if",
"crash-handler",
"futures 0.3.32",
"log",
"mach2 0.5.0",
"minidumper",
"parking_lot",
"paths",
"release_channel",
"serde",
"serde_json",
"system_specs",

View file

@ -6,13 +6,19 @@ edition.workspace = true
license = "GPL-3.0-or-later"
[dependencies]
async-process.workspace = true
crash-handler.workspace = true
cfg-if.workspace = true
futures.workspace = true
log.workspace = true
minidumper.workspace = true
parking_lot.workspace = true
release_channel.workspace = true
serde.workspace = true
serde_json.workspace = true
[target.'cfg(not(target_os = "freebsd"))'.dependencies]
async-process.workspace = true
crash-handler.workspace = true
minidumper.workspace = true
paths.workspace = true
system_specs.workspace = true
zstd.workspace = true
@ -26,4 +32,4 @@ windows.workspace = true
workspace = true
[lib]
path = "src/crashes.rs"
path = "src/lib.rs"

View file

@ -0,0 +1,33 @@
use std::future::Future;
use std::path::Path;
use futures::future::BoxFuture;
use serde::{Deserialize, Serialize};
pub static REQUESTED_MINIDUMP: std::sync::atomic::AtomicBool =
std::sync::atomic::AtomicBool::new(false);
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct InitCrashHandler {
pub session_id: String,
pub zed_version: String,
pub binary: String,
pub release_channel: String,
pub commit_sha: String,
}
pub fn init<F: Future<Output = ()> + Send + Sync + 'static>(
_crash_init: InitCrashHandler,
_spawn: impl FnOnce(BoxFuture<'static, ()>),
_wait_timer: impl (Fn(std::time::Duration) -> F) + Send + Sync + 'static,
) {
log::info!("crash handler disabled on FreeBSD");
}
pub fn crash_server(_socket: &Path) {
log::info!("crash server disabled on FreeBSD");
}
pub fn set_gpu_info(_specs: ()) {}
pub fn set_user_info(_info: ()) {}

11
crates/crashes/src/lib.rs Normal file
View file

@ -0,0 +1,11 @@
#[cfg(not(target_os = "freebsd"))]
mod crashes_full;
#[cfg(not(target_os = "freebsd"))]
pub use crashes_full::*;
#[cfg(target_os = "freebsd")]
mod crashes_freebsd;
#[cfg(target_os = "freebsd")]
pub use crashes_freebsd::*;

View file

@ -576,14 +576,15 @@ impl FileHandle for std::fs::File {
};
let fd = self.as_fd();
let mut kif = MaybeUninit::<libc::kinfo_file>::uninit();
let mut kif = MaybeUninit::<libc::kinfo_file>::zeroed();
// SAFETY: zeroed memory is a valid initial state for kinfo_file.
let kif = unsafe { kif.assume_init_mut() };
kif.kf_structsize = libc::KINFO_FILE_SIZE;
let result = unsafe { libc::fcntl(fd.as_raw_fd(), libc::F_KINFO, kif.as_mut_ptr()) };
let result = unsafe { libc::fcntl(fd.as_raw_fd(), libc::F_KINFO, kif as *mut _) };
anyhow::ensure!(result != -1, "fcntl returned -1");
// SAFETY: `fcntl` will initialize the kif.
let c_str = unsafe { CStr::from_ptr(kif.assume_init().kf_path.as_ptr()) };
let c_str = unsafe { CStr::from_ptr(kif.kf_path.as_ptr()) };
anyhow::ensure!(!c_str.is_empty(), "Could find a path for the file handle");
let path = PathBuf::from(OsStr::from_bytes(c_str.to_bytes()));
Ok(path)

View file

@ -35,7 +35,7 @@ mod platform;
pub mod prelude;
/// Profiling utilities for task timing and thread performance tracking.
pub mod profiler;
#[cfg(any(target_os = "windows", target_os = "linux", target_family = "wasm"))]
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "freebsd", target_family = "wasm"))]
#[expect(missing_docs)]
pub mod queue;
mod scene;
@ -102,7 +102,7 @@ pub use keymap::*;
pub use path_builder::*;
pub use platform::*;
pub use profiler::*;
#[cfg(any(target_os = "windows", target_os = "linux", target_family = "wasm"))]
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "freebsd", target_family = "wasm"))]
pub use queue::{PriorityQueueReceiver, PriorityQueueSender};
pub use refineable::*;
pub use scene::*;

View file

@ -75,11 +75,13 @@ thiserror.workspace = true
rayon.workspace = true
uuid = { workspace = true, features = ["v4"] }
[target.'cfg(not(windows))'.dependencies]
[target.'cfg(not(any(target_os = "windows", target_os = "freebsd")))'.dependencies]
crash-handler.workspace = true
minidumper.workspace = true
[target.'cfg(not(windows))'.dependencies]
fork.workspace = true
libc.workspace = true
minidumper.workspace = true
[target.'cfg(windows)'.dependencies]
windows.workspace = true