diff --git a/Cargo.toml b/Cargo.toml index 9ef022f..d6a3fa7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,4 +70,4 @@ android_logger = "0.14" jni = { version = "0.21", default-features = false } [target.'cfg(target_os = "windows")'.dependencies] -windows-service = "0.7" +windows-service = "0.8" diff --git a/src/android.rs b/src/android.rs index 429c562..dd3dc57 100644 --- a/src/android.rs +++ b/src/android.rs @@ -15,7 +15,7 @@ static EXITING_FLAG: std::sync::Mutex> = std::s /// # Safety /// /// Run the overtls client with config file. -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn Java_com_github_shadowsocks_bg_OverTlsWrapper_runClient( mut env: JNIEnv, _: JClass, @@ -116,7 +116,7 @@ fn _protect_socket(env: &mut JNIEnv, vpn_service: &JObject, socket: i32) -> Resu /// # Safety /// /// Shutdown the client. -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn Java_com_github_shadowsocks_bg_OverTlsWrapper_stopClient(_: JNIEnv, _: JClass) -> jint { if let Ok(mut token) = EXITING_FLAG.lock() { if let Some(token) = token.take() { diff --git a/src/api.rs b/src/api.rs index 5fc97c1..a820337 100644 --- a/src/api.rs +++ b/src/api.rs @@ -14,7 +14,7 @@ struct CCallback(Option, *mut c_void); impl CCallback { unsafe fn call(self, arg: c_int) { if let Some(cb) = self.0 { - cb(arg, self.1); + unsafe { cb(arg, self.1) }; } } } @@ -30,7 +30,7 @@ static EXITING_FLAG: std::sync::Mutex> = std::s /// The callback function will be called when the client is listening on a port. /// It should be thread-safe and will be called with the port number and should be called only once. /// -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn over_tls_client_run( config_path: *const c_char, verbosity: ArgVerbosity, @@ -47,7 +47,7 @@ pub unsafe extern "C" fn over_tls_client_run( if config_path.is_null() { return Err("config_path is null".into()); } - let config_path = std::ffi::CStr::from_ptr(config_path).to_str()?; + let config_path = unsafe { std::ffi::CStr::from_ptr(config_path).to_str()? }; let mut config = Config::from_config_file(config_path)?; config.check_correctness(false)?; _over_tls_client_run(config, callback, ctx) @@ -72,7 +72,7 @@ pub unsafe extern "C" fn over_tls_client_run( /// It should be thread-safe and will be called with the port number and should be called only once. /// - `ctx`: The context pointer to be passed to the callback function. /// -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn over_tls_client_run_with_ssr_url( url: *const c_char, listen_addr: *const c_char, @@ -88,11 +88,11 @@ pub unsafe extern "C" fn over_tls_client_run_with_ssr_url( } let result = || { - let url = std::ffi::CStr::from_ptr(url).to_str()?; + let url = unsafe { std::ffi::CStr::from_ptr(url).to_str()? }; let listen_addr = if listen_addr.is_null() { std::net::SocketAddr::from(([127, 0, 0, 1], 1080)) } else { - std::ffi::CStr::from_ptr(listen_addr).to_str()?.parse()? + unsafe { std::ffi::CStr::from_ptr(listen_addr) }.to_str()?.parse()? }; let mut config = Config::from_ssr_url(url)?; @@ -121,8 +121,8 @@ fn _over_tls_client_run(config: Config, callback: Option c_int { if let Ok(mut token) = EXITING_FLAG.lock() { if let Some(token) = token.take() { @@ -149,9 +149,9 @@ pub unsafe extern "C" fn over_tls_client_stop() -> c_int { /// # Safety /// /// Create a SSR URL from the config file. -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn overtls_generate_url(cfg_path: *const c_char) -> *mut c_char { - let cfg_path = std::ffi::CStr::from_ptr(cfg_path); + let cfg_path = unsafe { std::ffi::CStr::from_ptr(cfg_path) }; let cfg_path = match cfg_path.to_str() { Ok(s) => s, Err(_) => return std::ptr::null_mut(), @@ -170,10 +170,10 @@ pub unsafe extern "C" fn overtls_generate_url(cfg_path: *const c_char) -> *mut c /// # Safety /// /// Free the string returned by `overtls_generate_url`. -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn overtls_free_string(s: *mut c_char) { if s.is_null() { return; } - drop(std::ffi::CString::from_raw(s)); + drop(unsafe { std::ffi::CString::from_raw(s) }); } diff --git a/src/dump_logger.rs b/src/dump_logger.rs index bab8d93..0bf52bb 100644 --- a/src/dump_logger.rs +++ b/src/dump_logger.rs @@ -14,7 +14,7 @@ pub(crate) fn check_logger() -> bool { /// # Safety /// /// set dump log info callback. -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn overtls_set_log_callback( set_logger: bool, callback: Option, @@ -41,7 +41,7 @@ struct DumpCallback(Option, @@ -36,7 +36,7 @@ struct TrafficStatusCallback(Option