Skip to content

Commit

Permalink
Various minor fixes (#93)
Browse files Browse the repository at this point in the history
* Fix panic with `auxtools::byond_ffi::parse_args` in debug mode

* Update Cargo lockfile.

* Yeah we're reading unaligned pointers

* Warn on clippy lints rather than deny by default

* Fix "creating a shared reference to mutable static is discouraged" error

* Fix another `addr_of_mut`

* Work around doctest BS in `auxtools-impl` to avoid stupid errors (we don't HAVE doctests there anyways)
  • Loading branch information
Absolucy authored Oct 13, 2024
1 parent c0d3adf commit b498501
Show file tree
Hide file tree
Showing 8 changed files with 430 additions and 405 deletions.
814 changes: 417 additions & 397 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions auxtools-impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ license.workspace = true

[lib]
proc-macro = true
doctest = false

[dependencies]
proc-macro2 = "1.0"
Expand Down
7 changes: 4 additions & 3 deletions auxtools-impl/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(clippy::complexity, clippy::correctness, clippy::perf, clippy::style)]
#![warn(clippy::complexity, clippy::correctness, clippy::perf, clippy::style)]

use proc_macro::TokenStream;
use quote::quote;
Expand Down Expand Up @@ -180,7 +180,8 @@ pub fn pin_dll(attr: TokenStream) -> TokenStream {
///
/// Here we define a hook that multiplies a number passed to it by two.
/// It can now be used to hook procs, for example
/// `hooks::hook("/proc/double_up", double_up);` ```ignore
/// `hooks::hook("/proc/double_up", double_up);`
/// ```ignore
/// #[hook]
/// fn double_up(num: Value) {
/// if let Some(num) = num.as_number() {
Expand All @@ -189,7 +190,7 @@ pub fn pin_dll(attr: TokenStream) -> TokenStream {
/// Value::null()
/// }
/// ```
///
///
/// This function is used to hook `/mob/proc/on_honked`.
/// By specifying the proc path, we hook the proc immediately upon startup.
/// ```ignore
Expand Down
3 changes: 3 additions & 0 deletions auxtools/src/byond_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ thread_local! {
}

pub unsafe fn parse_args<'a>(argc: c_int, argv: *const *const c_char) -> Vec<Cow<'a, str>> {
if argc == 0 || argv.is_null() {
return Vec::new();
}
slice::from_raw_parts(argv, argc as usize)
.iter()
.map(|ptr| CStr::from_ptr(*ptr))
Expand Down
2 changes: 1 addition & 1 deletion auxtools/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(clippy::complexity, clippy::correctness, clippy::perf, clippy::style)]
#![warn(clippy::complexity, clippy::correctness, clippy::perf, clippy::style)]

//! For when BYOND is not enough. Probably often.
Expand Down
4 changes: 2 additions & 2 deletions auxtools/src/sigscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ impl Signature {
scanner.find(&self.bytes).map(|address| unsafe {
match self.treatment {
SignatureTreatment::NoOffset | SignatureTreatment::OffsetByInt(0) => std::mem::transmute(address as *const std::ffi::c_void),
SignatureTreatment::OffsetByInt(i) => *(address.offset(i) as *const *const std::ffi::c_void),
SignatureTreatment::OffsetByInt(i) => (address.offset(i) as *const *const std::ffi::c_void).read_unaligned(),
SignatureTreatment::OffsetByCall => {
let offset = *(address.offset(1) as *const isize);
let offset = (address.offset(1) as *const isize).read_unaligned();
address.offset(5).offset(offset) as *const () as *const std::ffi::c_void
}
}
Expand Down
2 changes: 1 addition & 1 deletion auxtools/src/string_intern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ macro_rules! byond_string {
($s:literal) => {
unsafe {
static mut STORE: $crate::InternedString = $crate::InternedString($s, std::cell::UnsafeCell::new(None));
$crate::inventory::submit!(unsafe { &STORE });
$crate::inventory::submit!(unsafe { &*::std::ptr::addr_of!(STORE) });
let x = &*STORE.1.get();
x.as_ref().unwrap()
}
Expand Down
2 changes: 1 addition & 1 deletion debug_server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn enable_debugging(mode: Value, port: Value) {
unsafe {
*DEBUG_SERVER.get() = Some(server);
debug_server_instruction_hook = DebugServerInstructionHook {
debug_server: &mut DEBUG_SERVER
debug_server: &mut *std::ptr::addr_of_mut!(DEBUG_SERVER)
};

INSTRUCTION_HOOKS.get_mut().push(Box::new(debug_server_instruction_hook));
Expand Down

0 comments on commit b498501

Please sign in to comment.