tsffs/interfaces/
config.rs

1// Copyright (C) 2024 Intel Corporation
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::{arch::ArchitectureHint, Tsffs};
5use simics::{debug, get_processor_number, interface, AsConfObject, ConfObject, Result};
6use std::{
7    ffi::{c_char, CStr},
8    str::FromStr,
9};
10
11extern crate ffi2 as ffi;
12
13#[interface(name = "config")]
14impl Tsffs {
15    /// Add a processor to be traced. By default, only the processor the start event occurs on
16    /// is used for tracing.
17    pub fn add_trace_processor(&mut self, cpu: *mut ConfObject) -> Result<()> {
18        debug!(
19            self.as_conf_object(),
20            "add_trace_processor({:#x})", cpu as usize
21        );
22
23        self.add_processor(cpu, false)?;
24
25        Ok(())
26    }
27
28    /// Set an architecture hint to be used for a particular processor. This allows overriding
29    /// the detected or reported architecture for the processor object. This is particularly
30    /// useful for x86 processors which report as x86-64 processors, or when fuzzing x86 code
31    /// running on an x86-64 processor in a backward compatibility mode.
32    pub fn add_architecture_hint(&mut self, cpu: *mut ConfObject, hint: *mut c_char) -> Result<()> {
33        let hint = unsafe { CStr::from_ptr(hint) }.to_str()?;
34        let processor_number = get_processor_number(cpu)?;
35        debug!(
36            self.as_conf_object(),
37            "add_architecture_hint({processor_number}, {hint})"
38        );
39        self.architecture_hints
40            .insert(processor_number, ArchitectureHint::from_str(hint)?);
41
42        Ok(())
43    }
44}