| 1 |
// Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 |
|
| 4 |
/** |
| 5 |
* @file |
| 6 |
* |
| 7 |
* ORC unwinder definitions. |
| 8 |
* |
| 9 |
* As of Linux v6.12, ORC is only defined for x86-64 and LoongArch. We don't |
| 10 |
* support LoongArch, so the definitions below are x86-64-specific. The |
| 11 |
* LoongArch format is different, so if we ever want to support LoongArch or a |
| 12 |
* another architecture that adds its own ORC format, this will need |
| 13 |
* reorganization. |
| 14 |
* |
| 15 |
* There are multiple versions of the ORC format for x86-64: |
| 16 |
* |
| 17 |
* - Version 4 since Linux kernel commit 1735858caa4b ("objtool/x86: Reorder |
| 18 |
* ORC register numbering") (in v7.1). |
| 19 |
* - Version 3 since Linux kernel commit fb799447ae29 ("x86,objtool: Split |
| 20 |
* UNWIND_HINT_EMPTY in two") (in v6.4). |
| 21 |
* - Version 2 between that and Linux kernel commit ffb1b4a41016 |
| 22 |
* ("x86/unwind/orc: Add 'signal' field to ORC metadata") (in v6.3). |
| 23 |
* - Version 1 before that, introduced in Linux kernel commit ee9f8fce9964 |
| 24 |
* ("x86/unwind: Add the ORC unwinder") (in v4.14). |
| 25 |
* |
| 26 |
* (The version numbers are our own invention and aren't used in the Linux |
| 27 |
* kernel.) |
| 28 |
* |
| 29 |
* The format changes affect the interpretation of @ref drgn_orc_entry::flags |
| 30 |
* (versions 1-3) and the register numbering (version 4). The getters assume |
| 31 |
* the latest version. |
| 32 |
*/ |
| 33 |
|
| 34 |
#ifndef DRGN_ORC_H |
| 35 |
#define DRGN_ORC_H |
| 36 |
|
| 37 |
#include <stdbool.h> |
| 38 |
#include <stdint.h> |
| 39 |
|
| 40 |
struct drgn_orc_entry { |
| 41 |
int16_t sp_offset; |
| 42 |
int16_t bp_offset; |
| 43 |
/** |
| 44 |
* Bit layout by version: |
| 45 |
* |
| 46 |
* |Version| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| 11| |
| 47 |
* |-------|---|---|---|---|---|---|---|---|---|---|---|---| |
| 48 |
* | 3| sp_reg |||| bp_reg |||| type ||| S | |
| 49 |
* | 2| sp_reg |||| bp_reg |||| type || S | E | |
| 50 |
* | 1| sp_reg |||| bp_reg |||| type || E | | |
| 51 |
* |
| 52 |
* S = signal |
| 53 |
* E = end |
| 54 |
*/ |
| 55 |
uint16_t flags; |
| 56 |
}; |
| 57 |
|
| 58 |
enum { |
| 59 |
// In versions 1 and 2, UNDEFINED and END_OF_STACK didn't exist, and |
| 60 |
// CALL = 0, REGS = 1, and REGS_PARTIAL = 2. |
| 61 |
DRGN_ORC_TYPE_UNDEFINED = 0, |
| 62 |
DRGN_ORC_TYPE_END_OF_STACK = 1, |
| 63 |
DRGN_ORC_TYPE_CALL = 2, |
| 64 |
DRGN_ORC_TYPE_REGS = 3, |
| 65 |
DRGN_ORC_TYPE_REGS_PARTIAL = 4, |
| 66 |
}; |
| 67 |
|
| 68 |
enum { |
| 69 |
DRGN_ORC_REG_UNDEFINED = 0, |
| 70 |
DRGN_ORC_REG_AX = 1, |
| 71 |
DRGN_ORC_REG_DX = 2, |
| 72 |
DRGN_ORC_REG_SP = 3, |
| 73 |
DRGN_ORC_REG_BP = 4, |
| 74 |
DRGN_ORC_REG_DI = 5, |
| 75 |
DRGN_ORC_REG_R10 = 6, |
| 76 |
DRGN_ORC_REG_R13 = 7, |
| 77 |
DRGN_ORC_REG_PREV_SP = 8, |
| 78 |
DRGN_ORC_REG_SP_INDIRECT = 9, |
| 79 |
DRGN_ORC_REG_BP_INDIRECT = 10, |
| 80 |
}; |
| 81 |
|
| 82 |
static inline int drgn_orc_sp_reg(const struct drgn_orc_entry *orc) |
| 83 |
{ |
| 84 |
return orc->flags & 0xf; |
| 85 |
} |
| 86 |
|
| 87 |
static inline int drgn_orc_bp_reg(const struct drgn_orc_entry *orc) |
| 88 |
{ |
| 89 |
return (orc->flags >> 4) & 0xf; |
| 90 |
} |
| 91 |
|
| 92 |
static inline int drgn_orc_type(const struct drgn_orc_entry *orc) |
| 93 |
{ |
| 94 |
return (orc->flags >> 8) & 0x7; |
| 95 |
} |
| 96 |
|
| 97 |
static inline bool drgn_orc_signal(const struct drgn_orc_entry *orc) |
| 98 |
{ |
| 99 |
return orc->flags & 0x800; |
| 100 |
} |
| 101 |
|
| 102 |
#endif /* DRGN_ORC_H */ |