Replace #[no_mangle] with #[unsafe(no_mangle)]

This commit is contained in:
Sebastian Holmin 2025-02-07 16:24:52 +01:00
parent 29363ae5ca
commit 53a11fdfef
No known key found for this signature in database
GPG Key ID: 9C88494B3F2F9089
13 changed files with 35 additions and 35 deletions

View File

@ -72,7 +72,7 @@ where
}
}
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn mullvad_api_device_iter_next(
mut iter: MullvadApiDeviceIterator,
device_ptr: *mut MullvadApiDevice,
@ -93,12 +93,12 @@ pub extern "C" fn mullvad_api_device_iter_next(
true
}
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn mullvad_api_device_iter_drop(iter: MullvadApiDeviceIterator) {
iter.drop()
}
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn mullvad_api_device_drop(device: MullvadApiDevice) {
device.drop()
}

View File

@ -64,7 +64,7 @@ impl MullvadApiError {
}
}
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn mullvad_api_error_drop(error: MullvadApiError) {
error.drop()
}

View File

@ -7,9 +7,9 @@ use std::{
};
use crate::{
AccountsProxy, ApiEndpoint, DevicesProxy,
proxy::ApiConnectionMode,
rest::{self, MullvadRestHandle},
AccountsProxy, ApiEndpoint, DevicesProxy,
};
mod device;
@ -237,7 +237,7 @@ impl FfiClient {
/// * `hostname`: pointer to a null-terminated UTF-8 string representing the hostname that will be
/// used for TLS validation.
/// * `disable_tls`: only valid when built for tests, can be ignored when consumed by Swift.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn mullvad_api_client_initialize(
client_ptr: *mut MullvadApiClient,
api_address_ptr: *const libc::c_char,
@ -275,7 +275,7 @@ pub unsafe extern "C" fn mullvad_api_client_initialize(
///
/// * `account_str_ptr`: pointer to nul-terminated UTF-8 string containing the account number of the
/// account that will have all of it's devices removed.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn mullvad_api_remove_all_devices(
client_ptr: MullvadApiClient,
account_ptr: *const libc::c_char,
@ -297,7 +297,7 @@ pub unsafe extern "C" fn mullvad_api_remove_all_devices(
///
/// * `expiry_unix_timestamp`: a pointer to a signed 64 bit integer. If this function returns no
/// error, the expiry timestamp will be written to this pointer.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn mullvad_api_get_expiry(
client_ptr: MullvadApiClient,
account_str_ptr: *const libc::c_char,
@ -325,7 +325,7 @@ pub unsafe extern "C" fn mullvad_api_get_expiry(
/// * `device_iter_ptr`: a pointer to a `device::MullvadApiDeviceIterator`. If this function doesn't
/// return an error, the pointer will be initialized with a valid instance of
/// `device::MullvadApiDeviceIterator`, which can be used to iterate through the devices.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn mullvad_api_list_devices(
client_ptr: MullvadApiClient,
account_str_ptr: *const libc::c_char,
@ -355,7 +355,7 @@ pub unsafe extern "C" fn mullvad_api_list_devices(
///
/// * `new_device_ptr`: a pointer to enough memory to allocate a `MullvadApiDevice`. If this
/// function doesn't return an error, it will be initialized.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn mullvad_api_add_device(
client_ptr: MullvadApiClient,
account_str_ptr: *const libc::c_char,
@ -385,7 +385,7 @@ pub unsafe extern "C" fn mullvad_api_add_device(
/// * `account_str_ptr`: If a new account is created successfully, a pointer to an allocated C
/// string containing the new account number will be written to this pointer. It must be freed via
/// `mullvad_api_cstring_drop`.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn mullvad_api_create_account(
client_ptr: MullvadApiClient,
account_str_ptr: *mut *const libc::c_char,
@ -414,7 +414,7 @@ pub unsafe extern "C" fn mullvad_api_create_account(
/// * `client_ptr`: Must be a valid, initialized instance of `MullvadApiClient`
///
/// * `account_str_ptr`: Must be a null-terminated string representing the account to be deleted.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn mullvad_api_delete_account(
client_ptr: MullvadApiClient,
account_str_ptr: *const libc::c_char,
@ -426,7 +426,7 @@ pub unsafe extern "C" fn mullvad_api_delete_account(
}
}
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn mullvad_api_client_drop(client: MullvadApiClient) {
client.drop()
}
@ -436,7 +436,7 @@ pub extern "C" fn mullvad_api_client_drop(client: MullvadApiClient) {
/// # Safety
///
/// `cstr_ptr` must be a pointer to a string allocated by another `mullvad_api` function.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn mullvad_api_cstring_drop(cstr_ptr: *mut libc::c_char) {
let _ = unsafe { CString::from_raw(cstr_ptr) };
}

View File

@ -93,7 +93,7 @@ impl EncryptedDnsProxyState {
///
/// * The caller must ensure that the pointer to the [domain_name] string contains a nul terminator
/// at the end of the string.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn encrypted_dns_proxy_init(
domain_name: *const c_char,
) -> *mut EncryptedDnsProxyState {
@ -116,7 +116,7 @@ pub unsafe extern "C" fn encrypted_dns_proxy_init(
/// `ptr` must be a valid, exclusive pointer to `EncryptedDnsProxyState`, initialized
/// by `encrypted_dns_proxy_init`. This function is not thread safe, and should only be called
/// once.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn encrypted_dns_proxy_free(ptr: *mut EncryptedDnsProxyState) {
let _ = unsafe { Box::from_raw(ptr) };
}
@ -130,7 +130,7 @@ pub unsafe extern "C" fn encrypted_dns_proxy_free(ptr: *mut EncryptedDnsProxySta
///
/// `proxy_handle` will only contain valid values if the return value is zero. It is still valid to
/// deallocate the memory.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn encrypted_dns_proxy_start(
encrypted_dns_proxy: *mut EncryptedDnsProxyState,
proxy_handle: *mut ProxyHandle,
@ -166,7 +166,7 @@ pub unsafe extern "C" fn encrypted_dns_proxy_start(
/// # Safety
/// `proxy_config` must be a valid pointer to a `ProxyHandle` as initialized by
/// [`encrypted_dns_proxy_start`]. It should only ever be called once.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn encrypted_dns_proxy_stop(proxy_config: *mut ProxyHandle) -> i32 {
let ptr = unsafe { (*proxy_config).context };
if !ptr.is_null() {

View File

@ -118,7 +118,7 @@ extern "C" {
/// # Safety
/// `sender` must be pointing to a valid instance of a `EphemeralPeerCancelToken` created by the
/// `PacketTunnelProvider`.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn cancel_ephemeral_peer_exchange(
sender: *mut peer_exchange::ExchangeCancelToken,
) {
@ -132,7 +132,7 @@ pub unsafe extern "C" fn cancel_ephemeral_peer_exchange(
/// # Safety
/// `sender` must be pointing to a valid instance of a `EphemeralPeerCancelToken` created by the
/// `PacketTunnelProvider`.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn drop_ephemeral_peer_exchange_token(
sender: *mut peer_exchange::ExchangeCancelToken,
) {
@ -148,7 +148,7 @@ pub unsafe extern "C" fn drop_ephemeral_peer_exchange_token(
/// function is called, and thus must be copied here. `packet_tunnel` must be valid pointers to a
/// packet tunnel, the packet tunnel pointer must outlive the ephemeral peer exchange.
/// `cancel_token` should be owned by the caller of this function.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn request_ephemeral_peer(
public_key: *const u8,
ephemeral_key: *const u8,

View File

@ -10,7 +10,7 @@ pub struct ProxyHandle {
pub port: u16,
}
#[no_mangle]
#[unsafe(no_mangle)]
pub static CONFIG_SERVICE_PORT: u16 = talpid_tunnel_config_client::CONFIG_SERVICE_PORT;
mod ios {

View File

@ -14,7 +14,7 @@ static INIT_LOGGING: Once = Once::new();
///
/// `proxy_config` must be pointing to a valid memory region for the size of a `ProxyHandle`
/// instance.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn start_shadowsocks_proxy(
forward_address: *const u8,
forward_address_len: usize,
@ -90,7 +90,7 @@ pub unsafe extern "C" fn start_shadowsocks_proxy(
/// # Safety
/// `proxy_config` must be pointing to a valid instance of a `ProxyInstance`, as instantiated by
/// `start_shadowsocks_proxy`.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn stop_shadowsocks_proxy(proxy_config: *mut ProxyHandle) -> i32 {
let context_ptr = unsafe { (*proxy_config).context };
if context_ptr.is_null() {

View File

@ -14,7 +14,7 @@ pub enum TunnelObfuscatorProtocol {
Shadowsocks,
}
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn start_tunnel_obfuscator_proxy(
peer_address: *const u8,
peer_address_len: usize,
@ -56,7 +56,7 @@ pub unsafe extern "C" fn start_tunnel_obfuscator_proxy(
}
}
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn stop_tunnel_obfuscator_proxy(proxy_handle: *mut ProxyHandle) -> i32 {
let context_ptr = unsafe { (*proxy_handle).context };
if context_ptr.is_null() {

View File

@ -73,7 +73,7 @@ struct DaemonContext {
/// Spawn Mullvad daemon. There can only be a single instance, which must be shut down using
/// `MullvadDaemon.shutdown`. On success, nothing is returned. On error, an exception is thrown.
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "system" fn Java_net_mullvad_mullvadvpn_service_MullvadDaemon_initialize(
env: JNIEnv<'_>,
_class: JClass<'_>,
@ -121,7 +121,7 @@ pub extern "system" fn Java_net_mullvad_mullvadvpn_service_MullvadDaemon_initial
}
/// Shut down Mullvad daemon that was initialized using `MullvadDaemon.initialize`.
#[no_mangle]
#[unsafe(no_mangle)]
#[allow(non_snake_case)]
pub extern "system" fn Java_net_mullvad_mullvadvpn_service_MullvadDaemon_shutdown(
_: JNIEnv<'_>,

View File

@ -10,7 +10,7 @@ use mullvad_api::ApiEndpoint;
use std::path::Path;
use talpid_types::ErrorExt;
#[no_mangle]
#[unsafe(no_mangle)]
#[allow(non_snake_case)]
pub extern "system" fn Java_net_mullvad_mullvadvpn_dataproxy_MullvadProblemReport_collectReport(
env: JNIEnv<'_>,
@ -36,7 +36,7 @@ pub extern "system" fn Java_net_mullvad_mullvadvpn_dataproxy_MullvadProblemRepor
}
}
#[no_mangle]
#[unsafe(no_mangle)]
#[allow(non_snake_case)]
pub extern "system" fn Java_net_mullvad_mullvadvpn_dataproxy_MullvadProblemReport_sendProblemReport(
env: JNIEnv<'_>,

View File

@ -23,7 +23,7 @@ const MAX_PATH_SIZE: isize = 32_767;
/// SAFETY: path needs to be a windows path encoded as a string of u16 that terminates in 0 (two
/// nul-bytes). The string is also not allowed to be greater than `MAX_PATH_SIZE`.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn create_privileged_directory(path: *const u16) -> Status {
catch_and_log_unwind(|| {
let mut i = 0;
@ -52,7 +52,7 @@ pub unsafe extern "C" fn create_privileged_directory(path: *const u16) -> Status
/// is returned, and the required buffer size (in chars) is returned in `buffer_size`.
/// On success, `buffer_size` is set to the length of the string, including
/// the final null terminator.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn get_system_local_appdata(
buffer: *mut u16,
buffer_size: *mut usize,
@ -91,7 +91,7 @@ pub unsafe extern "C" fn get_system_local_appdata(
/// `InsufficientBufferSize` is returned, and the required buffer size (in
/// chars) is returned in `buffer_size`. On success, `buffer_size` is set to the
/// length of the string, including the final null terminator.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn get_system_version(buffer: *mut u16, buffer_size: *mut usize) -> Status {
use talpid_platform_metadata::version;
catch_and_log_unwind(|| {

View File

@ -157,7 +157,7 @@ impl ConnectivityListener {
}
/// Entry point for Android Java code to notify the connectivity status.
#[no_mangle]
#[unsafe(no_mangle)]
#[allow(non_snake_case)]
pub extern "system" fn Java_net_mullvad_talpid_ConnectivityListener_notifyConnectivityChange(
_: JNIEnv<'_>,

View File

@ -161,7 +161,7 @@ fn configured_routes(state: &NetworkState) -> HashSet<Route> {
}
/// Entry point for Android Java code to notify the current default network state.
#[no_mangle]
#[unsafe(no_mangle)]
#[allow(non_snake_case)]
pub extern "system" fn Java_net_mullvad_talpid_ConnectivityListener_notifyDefaultNetworkChange(
env: JNIEnv<'_>,