From d764aa7254a6021ecd7712b035ac0f6afb986eaf Mon Sep 17 00:00:00 2001 From: Chris Martin Date: Wed, 8 Jan 2025 20:45:27 -0500 Subject: [PATCH] Break serializers into common and platform-specific --- src/linux.rs | 1 + src/linux/errors.rs | 2 +- src/linux/ptrace_dumper.rs | 1 + src/linux/serializers.rs | 40 ++++++++++++++++++++++++++++++++++++++ src/serializers.rs | 37 +---------------------------------- 5 files changed, 44 insertions(+), 37 deletions(-) create mode 100644 src/linux/serializers.rs diff --git a/src/linux.rs b/src/linux.rs index febdeabe..dc605084 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -15,6 +15,7 @@ pub mod minidump_writer; pub mod module_reader; pub mod ptrace_dumper; pub(crate) mod sections; +mod serializers; pub mod thread_info; pub use maps_reader::LINUX_GATE_LIBRARY_NAME; diff --git a/src/linux/errors.rs b/src/linux/errors.rs index f909fcbd..95322f10 100644 --- a/src/linux/errors.rs +++ b/src/linux/errors.rs @@ -1,5 +1,5 @@ use { - super::ptrace_dumper::InitError, + super::{ptrace_dumper::InitError, serializers::*}, crate::{ dir_section::FileWriterError, maps_reader::MappingInfo, mem_writer::MemoryWriterError, serializers::*, Pid, diff --git a/src/linux/ptrace_dumper.rs b/src/linux/ptrace_dumper.rs index d17f6ef2..7b04a2f5 100644 --- a/src/linux/ptrace_dumper.rs +++ b/src/linux/ptrace_dumper.rs @@ -2,6 +2,7 @@ use { super::{ auxv::AuxvError, errors::{AndroidError, MapsReaderError}, + serializers::*, }, crate::{ linux::{ diff --git a/src/linux/serializers.rs b/src/linux/serializers.rs new file mode 100644 index 00000000..73b33e2e --- /dev/null +++ b/src/linux/serializers.rs @@ -0,0 +1,40 @@ +//! Functions used by Serde to serialize types that we don't own (and thus can't implement +//! [Serialize] for) + +use {crate::serializers::*, serde::Serializer}; + +/// Serialize [goblin::error::Error] +pub fn serialize_goblin_error( + error: &goblin::error::Error, + serializer: S, +) -> Result { + serialize_generic_error(error, serializer) +} +/// Serialize [nix::Error] +pub fn serialize_nix_error( + error: &nix::Error, + serializer: S, +) -> Result { + serialize_generic_error(error, serializer) +} +/// Serialize [procfs_core::ProcError] +pub fn serialize_proc_error( + error: &procfs_core::ProcError, + serializer: S, +) -> Result { + serialize_generic_error(error, serializer) +} +/// Serialize [std::string::FromUtf8Error] +pub fn serialize_from_utf8_error( + error: &std::string::FromUtf8Error, + serializer: S, +) -> Result { + serialize_generic_error(error, serializer) +} +/// Serialize [std::time::SystemTimeError] +pub fn serialize_system_time_error( + error: &std::time::SystemTimeError, + serializer: S, +) -> Result { + serialize_generic_error(error, serializer) +} diff --git a/src/serializers.rs b/src/serializers.rs index 94615235..a42313da 100644 --- a/src/serializers.rs +++ b/src/serializers.rs @@ -4,7 +4,7 @@ use serde::Serializer; /// Useful for types that implement [Error][std::error::Error] and don't need any special /// treatment. -fn serialize_generic_error( +pub fn serialize_generic_error( error: &E, serializer: S, ) -> Result { @@ -21,41 +21,6 @@ pub fn serialize_io_error( ) -> Result { serialize_generic_error(error, serializer) } -/// Serialize [goblin::error::Error] -pub fn serialize_goblin_error( - error: &goblin::error::Error, - serializer: S, -) -> Result { - serialize_generic_error(error, serializer) -} -/// Serialize [nix::Error] -pub fn serialize_nix_error( - error: &nix::Error, - serializer: S, -) -> Result { - serialize_generic_error(error, serializer) -} -/// Serialize [procfs_core::ProcError] -pub fn serialize_proc_error( - error: &procfs_core::ProcError, - serializer: S, -) -> Result { - serialize_generic_error(error, serializer) -} -/// Serialize [std::string::FromUtf8Error] -pub fn serialize_from_utf8_error( - error: &std::string::FromUtf8Error, - serializer: S, -) -> Result { - serialize_generic_error(error, serializer) -} -/// Serialize [std::time::SystemTimeError] -pub fn serialize_system_time_error( - error: &std::time::SystemTimeError, - serializer: S, -) -> Result { - serialize_generic_error(error, serializer) -} /// Serialize [scroll::Error] pub fn serialize_scroll_error( error: &scroll::Error,