Skip to main content

tsffs/interfaces/
config.rs

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