diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2023-08-02 15:27:06 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2023-08-08 10:40:48 +0200 |
| commit | 9766f2bef6cfcba6c45887da34dcfa422bc0a259 (patch) | |
| tree | 0f589ca09aa969a80b69d315834cee83137ee3e9 | |
| parent | 92c2dd83db7c4bc3da1f1093c730b0cbb97ca484 (diff) | |
| download | mullvadvpn-9766f2bef6cfcba6c45887da34dcfa422bc0a259.tar.xz mullvadvpn-9766f2bef6cfcba6c45887da34dcfa422bc0a259.zip | |
Migrate from libc::c_void to std::ffi::c_void
| -rw-r--r-- | Cargo.lock | 1 | ||||
| -rw-r--r-- | mullvad-daemon/src/exception_logging/unix.rs | 3 | ||||
| -rw-r--r-- | mullvad-daemon/src/exception_logging/win.rs | 3 | ||||
| -rw-r--r-- | mullvad-daemon/src/macos_launch_daemon.rs | 6 | ||||
| -rw-r--r-- | mullvad-daemon/src/system_service.rs | 3 | ||||
| -rw-r--r-- | talpid-core/src/firewall/windows.rs | 6 | ||||
| -rw-r--r-- | talpid-windows-net/Cargo.toml | 1 | ||||
| -rw-r--r-- | talpid-windows-net/src/net.rs | 3 | ||||
| -rw-r--r-- | talpid-wireguard/src/logging.rs | 3 | ||||
| -rw-r--r-- | talpid-wireguard/src/wireguard_go.rs | 17 |
10 files changed, 20 insertions, 26 deletions
diff --git a/Cargo.lock b/Cargo.lock index eb7309d0db..6bc9b89fc1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3772,7 +3772,6 @@ version = "0.0.0" dependencies = [ "err-derive", "futures", - "libc", "socket2 0.4.9", "talpid-types", "winapi", diff --git a/mullvad-daemon/src/exception_logging/unix.rs b/mullvad-daemon/src/exception_logging/unix.rs index 430fedb74f..6ded89e202 100644 --- a/mullvad-daemon/src/exception_logging/unix.rs +++ b/mullvad-daemon/src/exception_logging/unix.rs @@ -1,8 +1,9 @@ //! Installs signal handlers to catch critical program faults and logs them. -use libc::{c_int, c_void, siginfo_t}; +use libc::{c_int, siginfo_t}; use nix::sys::signal::{sigaction, SaFlags, SigAction, SigHandler, SigSet, Signal}; +use std::ffi::c_void; use std::{convert::TryFrom, sync::Once}; static INIT_ONCE: Once = Once::new(); diff --git a/mullvad-daemon/src/exception_logging/win.rs b/mullvad-daemon/src/exception_logging/win.rs index 343b04a59c..ff2201029e 100644 --- a/mullvad-daemon/src/exception_logging/win.rs +++ b/mullvad-daemon/src/exception_logging/win.rs @@ -1,8 +1,7 @@ -use libc::c_void; use mullvad_paths::log_dir; use std::{ borrow::Cow, - ffi::CStr, + ffi::{c_void, CStr}, fmt::Write, fs, io, mem, os::{raw::c_char, windows::io::AsRawHandle}, diff --git a/mullvad-daemon/src/macos_launch_daemon.rs b/mullvad-daemon/src/macos_launch_daemon.rs index 04a562e9a1..6fbc3b57b3 100644 --- a/mullvad-daemon/src/macos_launch_daemon.rs +++ b/mullvad-daemon/src/macos_launch_daemon.rs @@ -6,7 +6,7 @@ //! daemon in the system settings. use objc::{class, msg_send, sel, sel_impl}; -use std::ffi::CStr; +use std::ffi::{c_void, CStr}; type Id = *mut objc::runtime::Object; @@ -80,7 +80,7 @@ fn daemon_plist_url() -> Object { let nsurl_inst: Id = unsafe { msg_send![class!(NSURL), alloc] }; let nsurl_inst: Id = unsafe { msg_send![nsurl_inst, initWithString: nsstr_inst] }; - let _: libc::c_void = unsafe { msg_send![nsstr_inst, release] }; + let _: c_void = unsafe { msg_send![nsstr_inst, release] }; assert!(!nsurl_inst.is_null()); @@ -92,6 +92,6 @@ struct Object(Id); impl Drop for Object { fn drop(&mut self) { - let _: libc::c_void = unsafe { msg_send![self.0, release] }; + let _: c_void = unsafe { msg_send![self.0, release] }; } } diff --git a/mullvad-daemon/src/system_service.rs b/mullvad-daemon/src/system_service.rs index 11b3e88eac..07eb791584 100644 --- a/mullvad-daemon/src/system_service.rs +++ b/mullvad-daemon/src/system_service.rs @@ -1,10 +1,9 @@ use crate::cli; -use libc::c_void; use mullvad_daemon::{runtime::new_runtime_builder, DaemonShutdownHandle}; use once_cell::sync::Lazy; use std::{ env, - ffi::OsString, + ffi::{c_void, OsString}, ptr, slice, sync::{ atomic::{AtomicBool, AtomicUsize, Ordering}, diff --git a/talpid-core/src/firewall/windows.rs b/talpid-core/src/firewall/windows.rs index b7b4ac39f6..807308722d 100644 --- a/talpid-core/src/firewall/windows.rs +++ b/talpid-core/src/firewall/windows.rs @@ -335,7 +335,7 @@ fn widestring_ip(ip: IpAddr) -> WideCString { pub extern "system" fn log_sink( level: log::Level, msg: *const libc::c_char, - context: *mut libc::c_void, + context: *mut std::ffi::c_void, ) { if msg.is_null() { log::error!("Log message from FFI boundary is NULL"); @@ -409,11 +409,11 @@ fn multibyte_to_wide(mb_string: &CStr, codepage: u32) -> Result<Vec<u16>, io::Er #[allow(non_snake_case)] mod winfw { use super::{widestring_ip, AllowedEndpoint, AllowedTunnelTraffic, Error, WideCString}; - use libc; + use std::ffi::c_void; use talpid_types::net::TransportProtocol; type LogSink = - extern "system" fn(level: log::Level, msg: *const libc::c_char, context: *mut libc::c_void); + extern "system" fn(level: log::Level, msg: *const libc::c_char, context: *mut c_void); pub struct WinFwAllowedEndpointContainer { _clients: Box<[WideCString]>, diff --git a/talpid-windows-net/Cargo.toml b/talpid-windows-net/Cargo.toml index 351bc539ea..f3a6f7046f 100644 --- a/talpid-windows-net/Cargo.toml +++ b/talpid-windows-net/Cargo.toml @@ -10,7 +10,6 @@ publish.workspace = true [target.'cfg(windows)'.dependencies] err-derive = "0.3.1" -libc = "0.2" socket2 = { version = "0.4.2", features = ["all"] } futures = "0.3.15" winapi = { version = "0.3.6", features = ["ws2def"] } diff --git a/talpid-windows-net/src/net.rs b/talpid-windows-net/src/net.rs index ec146a5c72..92e8e97969 100644 --- a/talpid-windows-net/src/net.rs +++ b/talpid-windows-net/src/net.rs @@ -1,4 +1,3 @@ -use libc::c_void; use socket2::SockAddr; use std::{ ffi::{OsStr, OsString}, @@ -153,7 +152,7 @@ impl<'a> Drop for IpNotifierHandle<'a> { } unsafe extern "system" fn inner_callback( - context: *const c_void, + context: *const std::ffi::c_void, row: *const MIB_IPINTERFACE_ROW, notify_type: i32, ) { diff --git a/talpid-wireguard/src/logging.rs b/talpid-wireguard/src/logging.rs index bf91840644..f8536b08a6 100644 --- a/talpid-wireguard/src/logging.rs +++ b/talpid-wireguard/src/logging.rs @@ -1,5 +1,6 @@ use once_cell::sync::Lazy; use parking_lot::Mutex; +use std::ffi::c_void; use std::{collections::HashMap, fmt, fs, io::Write, path::Path}; static LOG_MUTEX: Lazy<Mutex<HashMap<u32, fs::File>>> = Lazy::new(|| Mutex::new(HashMap::new())); @@ -92,7 +93,7 @@ fn log_inner(logfile: &mut fs::File, level: LogLevel, tag: &str, msg: &str) { pub unsafe extern "system" fn wg_go_logging_callback( level: WgLogLevel, msg: *const libc::c_char, - context: *mut libc::c_void, + context: *mut c_void, ) { let mut map = LOG_MUTEX.lock(); if let Some(logfile) = map.get_mut(&(context as u32)) { diff --git a/talpid-wireguard/src/wireguard_go.rs b/talpid-wireguard/src/wireguard_go.rs index d12753258b..270161c993 100644 --- a/talpid-wireguard/src/wireguard_go.rs +++ b/talpid-wireguard/src/wireguard_go.rs @@ -95,7 +95,7 @@ impl WgGoTunnel { wg_config_str.as_ptr() as *const i8, tunnel_fd, Some(wg_go_logging_callback), - logging_context.0 as *mut libc::c_void, + logging_context.0 as *mut c_void, ) }; check_wg_status(handle)?; @@ -154,7 +154,7 @@ impl WgGoTunnel { &mut alias_ptr, &mut interface_luid, Some(wg_go_logging_callback), - logging_context.0 as *mut libc::c_void, + logging_context.0 as *mut c_void, ) }; check_wg_status(handle)?; @@ -424,11 +424,8 @@ fn check_wg_status(wg_code: i32) -> Result<()> { #[cfg(unix)] pub type Fd = std::os::unix::io::RawFd; -pub type LoggingCallback = unsafe extern "system" fn( - level: WgLogLevel, - msg: *const libc::c_char, - context: *mut libc::c_void, -); +pub type LoggingCallback = + unsafe extern "system" fn(level: WgLogLevel, msg: *const libc::c_char, context: *mut c_void); const ERROR_GENERAL_FAILURE: i32 = -1; const ERROR_INTERMITTENT_FAILURE: i32 = -2; @@ -445,7 +442,7 @@ extern "C" { settings: *const i8, fd: Fd, logging_callback: Option<LoggingCallback>, - logging_context: *mut libc::c_void, + logging_context: *mut c_void, ) -> i32; // Android @@ -454,7 +451,7 @@ extern "C" { settings: *const i8, fd: Fd, logging_callback: Option<LoggingCallback>, - logging_context: *mut libc::c_void, + logging_context: *mut c_void, ) -> i32; // Windows @@ -466,7 +463,7 @@ extern "C" { iface_name_out: *mut *mut std::os::raw::c_char, iface_luid_out: *mut u64, logging_callback: Option<LoggingCallback>, - logging_context: *mut libc::c_void, + logging_context: *mut c_void, ) -> i32; // Pass a handle that was created by wgTurnOn to stop a wireguard tunnel. |
