Skip to content

Commit 46743c3

Browse files
kylewanginchinarvql
authored andcommitted
chore: modify TsdInfo
1 parent eac951f commit 46743c3

4 files changed

Lines changed: 17 additions & 15 deletions

File tree

agent/crates/trace-utils/cbindgen.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ include = [
7272
"V8UnwindInfo",
7373
"V8Offsets",
7474
"V8UnwindTable",
75-
"TSDInfo"
75+
"TsdInfo"
7676
]
7777
exclude = [
7878
"bpf_update_elem",
@@ -92,7 +92,7 @@ ProcessShardList = "process_shard_list_t"
9292
UnwindEntry = "unwind_entry_t"
9393
UnwindEntryShard = "unwind_entry_shard_t"
9494
UnwindTable = "unwind_table_t"
95-
TSDInfo = "tsd_info_t"
95+
TsdInfo = "tsd_info_t"
9696
PyCframe = "py_cframe_t"
9797
PyCodeObject = "py_code_object_t"
9898
PyFrameObject = "py_frame_object_t"

agent/crates/trace-utils/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use std::io::Write;
3030
use log::info;
3131

3232
// Crate internal modules
33-
pub use tsd::TSDInfo;
33+
pub use tsd::TsdInfo;
3434
use unwind::UnwindTable;
3535

3636
// ============================================================================
@@ -145,7 +145,7 @@ pub struct LuaRuntimeInfo {
145145
pub struct PythonUnwindInfo {
146146
pub auto_tls_key_addr: u64,
147147
pub version: u16,
148-
pub tsd_info: TSDInfo,
148+
pub tsd_info: TsdInfo,
149149
pub offsets_id: u8,
150150
pub _padding: [u8; 5],
151151
}

agent/crates/trace-utils/src/tsd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/// Thread Specific Data info for accessing per-thread PyThreadState.
1818
#[repr(C)]
1919
#[derive(Debug, Clone, Copy, Default)]
20-
pub struct TSDInfo {
20+
pub struct TsdInfo {
2121
/// Offset from thread pointer base (TPBASE) to TSD storage
2222
pub offset: i16,
2323
/// TSD key multiplier (glibc=16, musl=8)

agent/crates/trace-utils/src/unwind/tpbase.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,20 @@ fn read_kernel_code(addr: u64, size: usize) -> Result<Vec<u8>> {
179179
fn read_kernel_code_from_kcore(file: &mut File, addr: u64, size: usize) -> Result<Vec<u8>> {
180180
use object::{elf, read::elf::FileHeader, Endianness};
181181

182-
// Read the ELF header and program headers first.
183-
// Note: /proc/kcore is a virtual file representing kernel memory as an ELF core dump.
184-
// The ELF header starts at offset 0 and is always present (typically 64 bytes for ELF64).
185-
// The program headers follow immediately after and are also always present.
186-
// A 4096-byte initial read is sufficient for the header area since:
187-
// - ELF64 header is 64 bytes
188-
// - Each program header is 56 bytes, and typical kernels have < 70 segments
189-
// - Total header area rarely exceeds 4KB
190-
// EOF will not occur here as /proc/kcore always provides this data when readable.
182+
// Read the ELF header and program headers from /proc/kcore.
183+
// We attempt to read 4096 bytes which is usually enough for the ELF64 header (64 bytes)
184+
// plus program headers (56 bytes each). If the initial read is insufficient (e.g., many
185+
// memory segments), the code below will resize and re-read as needed.
191186
file.seek(SeekFrom::Start(0))?;
192187
let mut header_data = vec![0u8; 4096];
193-
file.read_exact(&mut header_data)?;
188+
let n = file.read(&mut header_data)?;
189+
if n < 64 {
190+
return Err(Error::Msg(format!(
191+
"Failed to read kcore ELF header: only got {} bytes",
192+
n
193+
)));
194+
}
195+
header_data.truncate(n);
194196

195197
// Parse header to get program header info
196198
let (endian, phoff, phnum, phentsize) = {

0 commit comments

Comments
 (0)