Coverage Report

Created: 2025-08-24 06:28

/src/elfutils/backends/x86_64_initreg_sample.c
Line
Count
Source (jump to first uncovered line)
1
/* Populate process registers from a linux perf_events sample.
2
   Copyright (C) 2025 Red Hat, Inc.
3
   This file is part of elfutils.
4
5
   This file is free software; you can redistribute it and/or modify
6
   it under the terms of either
7
8
     * the GNU Lesser General Public License as published by the Free
9
       Software Foundation; either version 3 of the License, or (at
10
       your option) any later version
11
12
   or
13
14
     * the GNU General Public License as published by the Free
15
       Software Foundation; either version 2 of the License, or (at
16
       your option) any later version
17
18
   or both in parallel, as here.
19
20
   elfutils is distributed in the hope that it will be useful, but
21
   WITHOUT ANY WARRANTY; without even the implied warranty of
22
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23
   General Public License for more details.
24
25
   You should have received copies of the GNU General Public License and
26
   the GNU Lesser General Public License along with this program.  If
27
   not, see <http://www.gnu.org/licenses/>.  */
28
29
#ifdef HAVE_CONFIG_H
30
# include <config.h>
31
#endif
32
33
#include <stdlib.h>
34
#if defined(__x86_64__) && defined(__linux__)
35
# include <linux/perf_event.h>
36
# include <asm/perf_regs.h>
37
#endif
38
39
#define BACKEND x86_64_
40
#include "libebl_CPU.h"
41
#include "libebl_PERF_FLAGS.h"
42
#if defined(__x86_64__) && defined(__linux__)
43
# include "linux-perf-regs.c"
44
# include "x86_initreg_sample.c"
45
#endif
46
47
/* Register ordering cf. linux arch/x86/include/uapi/asm/perf_regs.h,
48
   enum perf_event_x86_regs: */
49
Dwarf_Word
50
x86_64_sample_base_addr (const Dwarf_Word *regs, uint32_t n_regs,
51
       uint64_t regs_mask,
52
       /* XXX hypothetically needed if abi varies
53
          between samples in the same process;
54
          not needed on x86*/
55
       uint32_t abi __attribute__((unused)))
56
0
{
57
#if !defined(__x86_64__) || !defined(__linux__)
58
  (void)regs;
59
  (void)n_regs;
60
  (void)regs_mask;
61
  return 0;
62
#else /* __x86_64__ */
63
0
  return perf_sample_find_reg (regs, n_regs, regs_mask,
64
0
             7 /* index into perf_event_x86_regs */);
65
0
#endif
66
0
}
67
68
Dwarf_Word
69
x86_64_sample_pc (const Dwarf_Word *regs, uint32_t n_regs,
70
      uint64_t regs_mask,
71
      uint32_t abi __attribute__((unused)))
72
0
{
73
#if !defined(__x86_64__) || !defined(__linux__)
74
  (void)regs;
75
  (void)n_regs;
76
  (void)regs_mask;
77
  return 0;
78
#else /* __x86_64__ */
79
0
  return perf_sample_find_reg (regs, n_regs, regs_mask,
80
0
             8 /* index into perf_event_x86_regs */);
81
0
#endif
82
0
}
83
84
bool
85
x86_64_set_initial_registers_sample (const Dwarf_Word *regs, uint32_t n_regs,
86
             uint64_t regs_mask, uint32_t abi,
87
             ebl_tid_registers_t *setfunc,
88
             void *arg)
89
0
{
90
#if !defined(__x86_64__) || !defined(__linux__)
91
  (void)regs;
92
  (void)n_regs;
93
  (void)regs_mask;
94
  (void)abi;
95
  (void)setfunc;
96
  (void)arg;
97
  return false;
98
#else /* __x86_64__ */
99
0
  Dwarf_Word dwarf_regs[17];
100
0
  if (!x86_set_initial_registers_sample (regs, n_regs, regs_mask,
101
0
           abi, dwarf_regs, 9))
102
0
    return false;
103
0
  return setfunc (0, 17, dwarf_regs, arg);
104
0
#endif
105
0
}
106