2019-07-29 08:57:28 +01:00
|
|
|
// Copyright 2019 - Omar Sandoval
|
|
|
|
// SPDX-License-Identifier: GPL-3.0+
|
|
|
|
|
|
|
|
#ifndef DRGN_PLATFORM_H
|
|
|
|
#define DRGN_PLATFORM_H
|
|
|
|
|
2019-07-29 22:41:33 +01:00
|
|
|
#include <elfutils/libdwfl.h>
|
2019-07-29 08:57:28 +01:00
|
|
|
|
|
|
|
#include "drgn.h"
|
|
|
|
|
2019-10-18 10:03:32 +01:00
|
|
|
struct drgn_register {
|
|
|
|
const char *name;
|
|
|
|
enum drgn_register_number number;
|
|
|
|
};
|
|
|
|
|
2019-10-28 18:36:18 +00:00
|
|
|
/* Register in NT_PRSTATUS note or struct pt_regs used for stack unwinding. */
|
2019-10-24 22:26:45 +01:00
|
|
|
struct drgn_frame_register {
|
|
|
|
enum drgn_register_number number;
|
|
|
|
size_t size;
|
|
|
|
size_t prstatus_offset;
|
2019-10-28 18:36:18 +00:00
|
|
|
/* Name used in the kernel. */
|
|
|
|
const char *pt_regs_name;
|
|
|
|
/* Name used for the UAPI, if different from above. */
|
|
|
|
const char *pt_regs_name2;
|
2019-10-24 22:26:45 +01:00
|
|
|
};
|
|
|
|
|
2019-07-29 08:57:28 +01:00
|
|
|
struct drgn_architecture_info {
|
|
|
|
const char *name;
|
|
|
|
enum drgn_architecture arch;
|
|
|
|
enum drgn_platform_flags default_flags;
|
2019-10-18 10:03:32 +01:00
|
|
|
const struct drgn_register *registers;
|
|
|
|
size_t num_registers;
|
|
|
|
const struct drgn_register *(*register_by_name)(const char *name);
|
2019-10-24 22:26:45 +01:00
|
|
|
const struct drgn_frame_register *frame_registers;
|
|
|
|
size_t num_frame_registers;
|
2019-07-29 22:41:33 +01:00
|
|
|
struct drgn_error *(*linux_kernel_set_initial_registers)(Dwfl_Thread *,
|
2019-10-24 22:26:45 +01:00
|
|
|
const struct drgn_object *);
|
2020-04-09 22:59:42 +01:00
|
|
|
struct drgn_error *(*linux_kernel_get_page_offset)(struct drgn_program *,
|
|
|
|
uint64_t *);
|
2020-04-09 23:37:46 +01:00
|
|
|
struct drgn_error *(*linux_kernel_get_vmemmap)(struct drgn_program *,
|
|
|
|
uint64_t *);
|
2019-07-29 08:57:28 +01:00
|
|
|
};
|
|
|
|
|
2019-10-18 10:42:51 +01:00
|
|
|
static inline const struct drgn_register *
|
|
|
|
drgn_architecture_register_by_name(const struct drgn_architecture_info *arch,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
if (!arch->register_by_name)
|
|
|
|
return NULL;
|
|
|
|
return arch->register_by_name(name);
|
|
|
|
}
|
|
|
|
|
2019-07-29 08:57:28 +01:00
|
|
|
extern const struct drgn_architecture_info arch_info_unknown;
|
|
|
|
extern const struct drgn_architecture_info arch_info_x86_64;
|
|
|
|
|
|
|
|
struct drgn_platform {
|
|
|
|
const struct drgn_architecture_info *arch;
|
|
|
|
enum drgn_platform_flags flags;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize a @ref drgn_platform from an architecture, word size, and
|
|
|
|
* endianness.
|
|
|
|
*
|
|
|
|
* The default flags for the architecture are used other than the word size and
|
|
|
|
* endianness.
|
|
|
|
*/
|
|
|
|
void drgn_platform_from_arch(const struct drgn_architecture_info *arch,
|
|
|
|
bool is_64_bit, bool is_little_endian,
|
|
|
|
struct drgn_platform *ret);
|
|
|
|
|
|
|
|
/** Initialize a @ref drgn_platform from an ELF header. */
|
|
|
|
void drgn_platform_from_elf(GElf_Ehdr *ehdr, struct drgn_platform *ret);
|
|
|
|
|
|
|
|
#endif /* DRGN_PLATFORM_H */
|