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 { @@ -847,7 +847,6 @@ impl SoftwareKeyboard {
// A reimplementation of `swkbdMessageCallback` from `libctru/source/applets/swkbd.c`.
// 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(
user: *mut libc::c_void,
sender: NS_APPID,

1
ctru-rs/src/console.rs

@ -6,7 +6,6 @@ @@ -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.
use std::cell::{RefMut, UnsafeCell};
use std::default::Default;
use ctru_sys::{consoleClear, consoleInit, consoleSelect, consoleSetWindow, PrintConsole};

1
ctru-rs/src/lib.rs

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

2
ctru-rs/src/linear.rs

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

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

@ -347,10 +347,12 @@ impl IrUser { @@ -347,10 +347,12 @@ impl IrUser {
let mut shared_mem_guard = IR_USER_STATE.lock().unwrap();
let shared_mem = shared_mem_guard.as_mut().unwrap();
unsafe {
shared_mem
.service_handle
.send_service_request(request, expected_response_len)
}
}
}
// Internal helper for rounding up a value to a multiple of another value.

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

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

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

@ -50,19 +50,28 @@ impl HandleExt for Handle { @@ -50,19 +50,28 @@ impl HandleExt for Handle {
) -> crate::Result<Vec<u32>> {
// Copy over the request
let cmd_buffer_ptr = unsafe { ctru_sys::getThreadCommandBuffer() };
unsafe {
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
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)?;
}
// Copy back the response
request.clear();
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)
}

Loading…
Cancel
Save