16#ifndef LIEF_MACHO_FUNCTION_VARIANTS_COMMAND_H
17#define LIEF_MACHO_FUNCTION_VARIANTS_COMMAND_H
37struct linkedit_data_command;
78 static constexpr uint32_t
MAX_IMPL = (uint32_t(1) << 31) - 1;
80 static constexpr uint32_t
F_BIT = 20;
81 static constexpr uint32_t
F_MASK = (uint32_t(1) <<
F_BIT) - 1;
96#define FUNCTION_VARIANT_FLAG(name, value, _) name = (value | F_ARM64),
98#undef FUNCTION_VARIANT_FLAG
100#define FUNCTION_VARIANT_FLAG(name, value, _) name = (value | F_X86_64),
102#undef FUNCTION_VARIANT_FLAG
104#define FUNCTION_VARIANT_FLAG(name, value, _) name = (value | F_SYSTEM_WIDE),
106#undef FUNCTION_VARIANT_FLAG
108#define FUNCTION_VARIANT_FLAG(name, value, _) name = (value | F_PER_PROCESS),
110#undef FUNCTION_VARIANT_FLAG
146 return another_table_;
151 another_table_ = value;
156 return flag_bit_nums_;
160 const std::vector<FLAGS>&
flags()
const {
178 bool another_table_ =
false;
180 std::array<uint8_t, 4> flag_bit_nums_ = {};
181 std::vector<FLAGS> flags_;
257 entries_.push_back(std::move(entry));
269 KIND kind_ = KIND::UNKNOWN;
270 uint32_t offset_ = 0;
288 std::unique_ptr<LoadCommand>
clone()
const override {
303 data_offset_ = offset;
323 return runtime_table_;
327 return runtime_table_;
332 runtime_table_.push_back(std::move(table));
333 return runtime_table_.back();
338 std::ostream&
print(std::ostream& os)
const override;
348 uint32_t data_offset_ = 0;
349 uint32_t data_size_ = 0;
351 std::vector<RuntimeTable> runtime_table_;
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:34
Class used to parse a single binary (i.e. non-FAT).
Definition BinaryParser.hpp:79
This class exposes information about a given implementation.
Definition FunctionVariants.hpp:75
void another_table(bool value)
Set whether impl() refers to an entry in another runtime table.
Definition FunctionVariants.hpp:150
RuntimeTableEntry()=default
span< const uint8_t > flag_bit_nums() const
The flagBitNums value as a slice of bytes.
Definition FunctionVariants.hpp:155
static constexpr uint32_t F_SYSTEM_WIDE
Definition FunctionVariants.hpp:84
static constexpr uint32_t F_MASK
Definition FunctionVariants.hpp:81
const std::vector< FLAGS > & flags() const
Return the interpreted flag_bit_nums().
Definition FunctionVariants.hpp:160
std::string to_string() const
static constexpr uint32_t F_PER_PROCESS
Definition FunctionVariants.hpp:83
FLAGS
Flags describing the target platform, environment, or architecture for a given function implementatio...
Definition FunctionVariants.hpp:93
static constexpr uint32_t F_X86_64
Definition FunctionVariants.hpp:86
RuntimeTableEntry & operator=(const RuntimeTableEntry &)=default
static uint8_t get_raw(FLAGS f)
Definition FunctionVariants.hpp:113
bool another_table() const
Indicates whether impl() refers to an entry in another runtime table, rather than a direct function i...
Definition FunctionVariants.hpp:145
friend std::ostream & operator<<(std::ostream &os, const RuntimeTableEntry &entry)
Definition FunctionVariants.hpp:166
static constexpr uint32_t MAX_IMPL
The implementation address/index is encoded on 31 bits.
Definition FunctionVariants.hpp:78
static constexpr uint32_t F_ARM64
Definition FunctionVariants.hpp:85
uint32_t impl() const
The relative address of the implementation or an index if another_table() is set.
Definition FunctionVariants.hpp:130
static constexpr uint32_t F_BIT
Definition FunctionVariants.hpp:80
static std::vector< RuntimeTable > parse_payload(SpanStream &stream)
it_const_runtime_table runtime_table() const
Definition FunctionVariants.hpp:326
static result< RuntimeTable > parse_entry(BinaryStream &stream)
RuntimeTable & add(RuntimeTable table)
Append a new RuntimeTable and return a reference to the inserted table.
Definition FunctionVariants.hpp:331
FunctionVariants()=default
uint32_t data_offset() const
Offset in the __LINKEDIT SegmentCommand where the payload starts.
Definition FunctionVariants.hpp:293
span< const uint8_t > content() const
Return the data slice in the __LINKEDIT segment referenced by data_offset and data_size;.
Definition FunctionVariants.hpp:312
ref_iterator< runtime_table_t & > it_runtime_table
Iterator that outputs RuntimeTable&.
Definition FunctionVariants.hpp:277
friend class BinaryParser
Definition FunctionVariants.hpp:70
std::unique_ptr< LoadCommand > clone() const override
Definition FunctionVariants.hpp:288
FunctionVariants(const details::linkedit_data_command &cmd)
void data_offset(uint32_t offset)
Definition FunctionVariants.hpp:302
span< uint8_t > content()
Definition FunctionVariants.hpp:316
FunctionVariants & operator=(const FunctionVariants ©)=default
~FunctionVariants() override=default
FunctionVariants(const FunctionVariants ©)=default
void data_size(uint32_t size)
Definition FunctionVariants.hpp:306
it_runtime_table runtime_table()
Iterator over the different RuntimeTable entries located in the content of this __LINKEDIT command.
Definition FunctionVariants.hpp:322
uint32_t data_size() const
Size of the payload.
Definition FunctionVariants.hpp:298
std::vector< RuntimeTable > runtime_table_t
Definition FunctionVariants.hpp:274
friend class LinkEdit
Definition FunctionVariants.hpp:71
std::ostream & print(std::ostream &os) const override
const_ref_iterator< const runtime_table_t & > it_const_runtime_table
Iterator that outputs const RuntimeTable&.
Definition FunctionVariants.hpp:280
static bool classof(const LoadCommand *cmd)
Definition FunctionVariants.hpp:340
Definition LinkEdit.hpp:47
uint32_t size() const
Size of the command (should be greater than sizeof(load_command)).
Definition LoadCommand.hpp:135
LoadCommand::TYPE command() const
Command type.
Definition LoadCommand.hpp:130
@ FUNCTION_VARIANTS
Definition LoadCommand.hpp:103
Definition SpanStream.hpp:32
Iterator which returns reference on container's values.
Definition iterators.hpp:47
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:78
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition endianness_support.hpp:60
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
@ UNKNOWN
Definition MachO/enums.hpp:24
const char * to_string(BuildToolVersion::TOOLS tool)
LIEF namespace.
Definition Abstract/Binary.hpp:41
tcb::span< ElementType, Extent > span
Definition span.hpp:22
ref_iterator< CT, U, typename decay_t< CT >::const_iterator > const_ref_iterator
Iterator which returns a const ref on container's values.
Definition iterators.hpp:320
Definition FunctionVariants.hpp:41
uint8_t flag_bit_nums[4]
Definition FunctionVariants.hpp:44
uint32_t impl
Definition FunctionVariants.hpp:42
uint32_t another_table
Definition FunctionVariants.hpp:43
#define LIEF_API
Definition visibility.h:45
#define LIEF_LOCAL
Definition visibility.h:46