Browse Source

Require unsafe blocks in unsafe fns

pull/165/head
Fenrir 10 months ago
parent
commit
a18dfc49f7
  1. 1
      ctru-rs/src/applets/swkbd.rs
  2. 1
      ctru-rs/src/console.rs
  3. 1
      ctru-rs/src/lib.rs
  4. 2
      ctru-rs/src/linear.rs
  5. 2
      ctru-rs/src/services/ir_user.rs
  6. 1
      ctru-rs/src/services/ndsp/mod.rs
  7. 13
      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)]

2
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) {
unsafe {
ctru_sys::linearFree(ptr.as_ptr().cast()); ctru_sys::linearFree(ptr.as_ptr().cast());
} }
} }
}

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

@ -347,11 +347,13 @@ 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();
unsafe {
shared_mem shared_mem
.service_handle .service_handle
.send_service_request(request, expected_response_len) .send_service_request(request, expected_response_len)
} }
} }
}
// Internal helper for rounding up a value to a multiple of another value. // Internal helper for rounding up a value to a multiple of another value.
fn round_up(value: usize, multiple: usize) -> usize { fn round_up(value: usize, multiple: usize) -> usize {

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;

13
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() };
unsafe {
std::ptr::copy_nonoverlapping(request.as_ptr(), cmd_buffer_ptr, request.len()); std::ptr::copy_nonoverlapping(request.as_ptr(), cmd_buffer_ptr, request.len());
// Send the request // Send the request
ResultCode(ctru_sys::svcSendSyncRequest(self))?; 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