From 40a355a42d4a9444dc753c04c6608dade2f06a23 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:13:27 +0200 Subject: Adding upstream version 125.0.1. Signed-off-by: Daniel Baumann --- .../crashreporter/mozannotation_server/src/lib.rs | 66 +++++++++++----------- .../src/process_reader/linux.rs | 4 +- 2 files changed, 36 insertions(+), 34 deletions(-) (limited to 'toolkit/crashreporter/mozannotation_server/src') diff --git a/toolkit/crashreporter/mozannotation_server/src/lib.rs b/toolkit/crashreporter/mozannotation_server/src/lib.rs index 4ecb8ec919..6ed5b3cc41 100644 --- a/toolkit/crashreporter/mozannotation_server/src/lib.rs +++ b/toolkit/crashreporter/mozannotation_server/src/lib.rs @@ -9,22 +9,21 @@ use crate::errors::*; use process_reader::ProcessReader; use mozannotation_client::{Annotation, AnnotationContents, AnnotationMutex}; -use nsstring::nsCString; use std::cmp::min; use std::iter::FromIterator; -use std::mem::size_of; +use std::mem::{size_of, ManuallyDrop}; use std::ptr::null_mut; use thin_vec::ThinVec; #[repr(C)] +#[derive(Debug)] pub enum AnnotationData { Empty, - UsizeData(usize), - NSCStringData(nsCString), ByteBuffer(ThinVec), } #[repr(C)] +#[derive(Debug)] pub struct CAnnotation { id: u32, data: AnnotationData, @@ -100,33 +99,33 @@ pub fn retrieve_annotations( // Read an annotation from the given address fn read_annotation(reader: &ProcessReader, address: usize) -> Result { - let raw_annotation = reader.copy_object::(address)?; + let raw_annotation = ManuallyDrop::new(reader.copy_object::(address)?); let mut annotation = CAnnotation { id: raw_annotation.id, data: AnnotationData::Empty, }; + if raw_annotation.address == 0 { + return Ok(annotation); + } + match raw_annotation.contents { AnnotationContents::Empty => {} - AnnotationContents::NSCString => { + AnnotationContents::NSCStringPointer => { let string = copy_nscstring(reader, raw_annotation.address)?; - annotation.data = AnnotationData::NSCStringData(string); - } - AnnotationContents::CString => { - let string = copy_null_terminated_string_pointer(reader, raw_annotation.address)?; - annotation.data = AnnotationData::NSCStringData(string); + annotation.data = AnnotationData::ByteBuffer(string); } - AnnotationContents::CharBuffer => { - let string = copy_null_terminated_string(reader, raw_annotation.address)?; - annotation.data = AnnotationData::NSCStringData(string); + AnnotationContents::CStringPointer => { + let buffer = copy_null_terminated_string_pointer(reader, raw_annotation.address)?; + annotation.data = AnnotationData::ByteBuffer(buffer); } - AnnotationContents::USize => { - let value = reader.copy_object::(raw_annotation.address)?; - annotation.data = AnnotationData::UsizeData(value); + AnnotationContents::CString => { + let buffer = copy_null_terminated_string(reader, raw_annotation.address)?; + annotation.data = AnnotationData::ByteBuffer(buffer); } - AnnotationContents::ByteBuffer(size) => { - let value = copy_bytebuffer(reader, raw_annotation.address, size)?; - annotation.data = AnnotationData::ByteBuffer(value); + AnnotationContents::ByteBuffer(size) | AnnotationContents::OwnedByteBuffer(size) => { + let buffer = copy_bytebuffer(reader, raw_annotation.address, size)?; + annotation.data = AnnotationData::ByteBuffer(buffer); } }; @@ -136,7 +135,7 @@ fn read_annotation(reader: &ProcessReader, address: usize) -> Result Result { +) -> Result, ReadError> { let buffer_address = reader.copy_object::(address)?; copy_null_terminated_string(reader, buffer_address) } @@ -144,7 +143,7 @@ fn copy_null_terminated_string_pointer( fn copy_null_terminated_string( reader: &ProcessReader, address: usize, -) -> Result { +) -> Result, ReadError> { // Try copying the string word-by-word first, this is considerably faster // than one byte at a time. if let Ok(string) = copy_null_terminated_string_word_by_word(reader, address) { @@ -155,7 +154,7 @@ fn copy_null_terminated_string( // at a time. It's slow but it might work in situations where the string // alignment causes word-by-word access to straddle page boundaries. let mut length = 0; - let mut string = Vec::::new(); + let mut string = ThinVec::::new(); loop { let char = reader.copy_object::(address + length)?; @@ -167,33 +166,34 @@ fn copy_null_terminated_string( } } - Ok(nsCString::from(&string[..length])) + Ok(string) } fn copy_null_terminated_string_word_by_word( reader: &ProcessReader, address: usize, -) -> Result { +) -> Result, ReadError> { const WORD_SIZE: usize = size_of::(); let mut length = 0; - let mut string = Vec::::new(); + let mut string = ThinVec::::new(); loop { - let mut array = reader.copy_array::(address + length, WORD_SIZE)?; + let array = reader.copy_array::(address + length, WORD_SIZE)?; let null_terminator = array.iter().position(|&e| e == 0); length += null_terminator.unwrap_or(WORD_SIZE); - string.append(&mut array); + string.extend(array.into_iter()); if null_terminator.is_some() { + string.truncate(length); break; } } - Ok(nsCString::from(&string[..length])) + Ok(string) } -fn copy_nscstring(reader: &ProcessReader, address: usize) -> Result { - // HACK: This assumes the layout of the string +fn copy_nscstring(reader: &ProcessReader, address: usize) -> Result, ReadError> { + // HACK: This assumes the layout of the nsCString object let length_address = address + size_of::(); let length = reader.copy_object::(length_address)?; @@ -201,9 +201,9 @@ fn copy_nscstring(reader: &ProcessReader, address: usize) -> Result(address)?; reader .copy_array::(data_address, length as _) - .map(nsCString::from) + .map(ThinVec::from) } else { - Ok(nsCString::new()) + Ok(ThinVec::::new()) } } diff --git a/toolkit/crashreporter/mozannotation_server/src/process_reader/linux.rs b/toolkit/crashreporter/mozannotation_server/src/process_reader/linux.rs index db6dbd3df2..34f8ef90d5 100644 --- a/toolkit/crashreporter/mozannotation_server/src/process_reader/linux.rs +++ b/toolkit/crashreporter/mozannotation_server/src/process_reader/linux.rs @@ -261,8 +261,10 @@ enum PTraceOperation { PeekData, } -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", target_env = "gnu"))] type PTraceOperationNative = libc::c_uint; +#[cfg(all(target_os = "linux", target_env = "musl"))] +type PTraceOperationNative = libc::c_int; #[cfg(target_os = "android")] type PTraceOperationNative = c_int; -- cgit v1.2.3