Browse Source

Merge pull request #165 from FenrirWolf/unsafe_blocks_in_unsafe_fn

Require unsafe blocks in unsafe fns
pull/169/head
FenrirWolf 10 months ago committed by GitHub
parent
commit
10163fd225
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      ctru-rs/src/applets/swkbd.rs
  2. 1
      ctru-rs/src/console.rs
  3. 1
      ctru-rs/src/lib.rs
  4. 4
      ctru-rs/src/linear.rs
  5. 8
      ctru-rs/src/services/ir_user.rs
  6. 1
      ctru-rs/src/services/ndsp/mod.rs
  7. 23
      ctru-rs/src/services/svc.rs

1
ctru-rs/src/applets/swkbd.rs

@ -847,7 +847,6 @@ impl SoftwareKeyboard {
// A reimplementation of `swkbdMessageCallback` from `libctru/source/applets/swkbd.c`. // A reimplementation of `swkbdMessageCallback` from `libctru/source/applets/swkbd.c`.
// This function sets up and then calls the callback set by `swkbdSetFilterCallback` // This function sets up and then calls the callback set by `swkbdSetFilterCallback`
#[deny(unsafe_op_in_unsafe_fn)]
unsafe extern "C" fn swkbd_message_callback( unsafe extern "C" fn swkbd_message_callback(
user: *mut libc::c_void, user: *mut libc::c_void,
sender: NS_APPID, sender: NS_APPID,

1
ctru-rs/src/console.rs

@ -6,7 +6,6 @@
//! Have a look at [`Soc::redirect_to_3dslink()`](crate::services::soc::Soc::redirect_to_3dslink) for a better alternative when debugging applications. //! Have a look at [`Soc::redirect_to_3dslink()`](crate::services::soc::Soc::redirect_to_3dslink) for a better alternative when debugging applications.
use std::cell::{RefMut, UnsafeCell}; use std::cell::{RefMut, UnsafeCell};
use std::default::Default;
use ctru_sys::{consoleClear, consoleInit, consoleSelect, consoleSetWindow, PrintConsole}; use ctru_sys::{consoleClear, consoleInit, consoleSelect, consoleSetWindow, PrintConsole};

1
ctru-rs/src/lib.rs

@ -18,6 +18,7 @@
#![crate_type = "rlib"] #![crate_type = "rlib"]
#![crate_name = "ctru"] #![crate_name = "ctru"]
#![warn(missing_docs)] #![warn(missing_docs)]
#![deny(unsafe_op_in_unsafe_fn)]
#![feature(custom_test_frameworks)] #![feature(custom_test_frameworks)]
#![feature(try_trait_v2)] #![feature(try_trait_v2)]
#![feature(allocator_api)] #![feature(allocator_api)]

4
ctru-rs/src/linear.rs

@ -42,6 +42,8 @@ unsafe impl Allocator for LinearAllocator {
#[doc(alias = "linearFree")] #[doc(alias = "linearFree")]
unsafe fn deallocate(&self, ptr: NonNull<u8>, _layout: Layout) { unsafe fn deallocate(&self, ptr: NonNull<u8>, _layout: Layout) {
ctru_sys::linearFree(ptr.as_ptr().cast()); unsafe {
ctru_sys::linearFree(ptr.as_ptr().cast());
}
} }
} }

8
ctru-rs/src/services/ir_user.rs

@ -347,9 +347,11 @@ impl IrUser {
let mut shared_mem_guard = IR_USER_STATE.lock().unwrap(); let mut shared_mem_guard = IR_USER_STATE.lock().unwrap();
let shared_mem = shared_mem_guard.as_mut().unwrap(); let shared_mem = shared_mem_guard.as_mut().unwrap();
shared_mem unsafe {
.service_handle shared_mem
.send_service_request(request, expected_response_len) .service_handle
.send_service_request(request, expected_response_len)
}
} }
} }

1
ctru-rs/src/services/ndsp/mod.rs

@ -21,7 +21,6 @@ use crate::error::ResultCode;
use crate::services::ServiceReference; use crate::services::ServiceReference;
use std::cell::{RefCell, RefMut}; use std::cell::{RefCell, RefMut};
use std::default::Default;
use std::error; use std::error;
use std::fmt; use std::fmt;
use std::sync::Mutex; use std::sync::Mutex;

23
ctru-rs/src/services/svc.rs

@ -50,19 +50,28 @@ impl HandleExt for Handle {
) -> crate::Result<Vec<u32>> { ) -> crate::Result<Vec<u32>> {
// Copy over the request // Copy over the request
let cmd_buffer_ptr = unsafe { ctru_sys::getThreadCommandBuffer() }; let cmd_buffer_ptr = unsafe { ctru_sys::getThreadCommandBuffer() };
std::ptr::copy_nonoverlapping(request.as_ptr(), cmd_buffer_ptr, request.len());
// Send the request unsafe {
ResultCode(ctru_sys::svcSendSyncRequest(self))?; std::ptr::copy_nonoverlapping(request.as_ptr(), cmd_buffer_ptr, request.len());
// Send the request
ResultCode(ctru_sys::svcSendSyncRequest(self))?;
// Handle the result returned by the service // Handle the result returned by the service
let result = unsafe { std::ptr::read(cmd_buffer_ptr.add(1)) }; let result = std::ptr::read(cmd_buffer_ptr.add(1));
ResultCode(result as ctru_sys::Result)?; ResultCode(result as ctru_sys::Result)?;
}
// Copy back the response // Copy back the response
request.clear(); request.clear();
request.resize(expected_response_len, 0); request.resize(expected_response_len, 0);
std::ptr::copy_nonoverlapping(cmd_buffer_ptr, request.as_mut_ptr(), expected_response_len); unsafe {
std::ptr::copy_nonoverlapping(
cmd_buffer_ptr,
request.as_mut_ptr(),
expected_response_len,
);
}
Ok(request) Ok(request)
} }

Loading…
Cancel
Save