16#ifndef LIEF_MACHO_FUNCTION_VARIANTS_COMMAND_H
17#define LIEF_MACHO_FUNCTION_VARIANTS_COMMAND_H
38struct linkedit_data_command;
79 static constexpr uint32_t
MAX_IMPL = (uint32_t(1) << 31) - 1;
81 static constexpr uint32_t
F_BIT = 20;
82 static constexpr uint32_t
F_MASK = (uint32_t(1) <<
F_BIT) - 1;
97#define FUNCTION_VARIANT_FLAG(name, value, _) name = (value | F_ARM64),
99#undef FUNCTION_VARIANT_FLAG
101#define FUNCTION_VARIANT_FLAG(name, value, _) name = (value | F_X86_64),
103#undef FUNCTION_VARIANT_FLAG
105#define FUNCTION_VARIANT_FLAG(name, value, _) name = (value | F_SYSTEM_WIDE),
107#undef FUNCTION_VARIANT_FLAG
109#define FUNCTION_VARIANT_FLAG(name, value, _) name = (value | F_PER_PROCESS),
111#undef FUNCTION_VARIANT_FLAG
147 return another_table_;
152 another_table_ = value;
157 return flag_bit_nums_;
161 const std::vector<FLAGS>&
flags()
const {
179 bool another_table_ =
false;
181 std::array<uint8_t, 4> flag_bit_nums_ = {};
182 std::vector<FLAGS> flags_;
258 entries_.push_back(std::move(entry));
270 KIND kind_ = KIND::UNKNOWN;
271 uint32_t offset_ = 0;
289 std::unique_ptr<LoadCommand>
clone()
const override {
290 return std::make_unique<FunctionVariants>(*
this);
304 data_offset_ = offset;
324 return runtime_table_;
328 return runtime_table_;
333 runtime_table_.push_back(std::move(table));
334 return runtime_table_.back();
339 std::ostream&
print(std::ostream& os)
const override;
347 uint64_t max_entries);
350 uint32_t data_offset_ = 0;
351 uint32_t data_size_ = 0;
353 std::vector<RuntimeTable> runtime_table_;
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:35
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:76
void another_table(bool value)
Set whether impl() refers to an entry in another runtime table.
Definition FunctionVariants.hpp:151
RuntimeTableEntry()=default
span< const uint8_t > flag_bit_nums() const
The flagBitNums value as a slice of bytes.
Definition FunctionVariants.hpp:156
static constexpr uint32_t F_SYSTEM_WIDE
Definition FunctionVariants.hpp:85
static constexpr uint32_t F_MASK
Definition FunctionVariants.hpp:82
const std::vector< FLAGS > & flags() const
Return the interpreted flag_bit_nums().
Definition FunctionVariants.hpp:161
std::string to_string() const
static constexpr uint32_t F_PER_PROCESS
Definition FunctionVariants.hpp:84
FLAGS
Flags describing the target platform, environment, or architecture for a given function implementatio...
Definition FunctionVariants.hpp:94
static constexpr uint32_t F_X86_64
Definition FunctionVariants.hpp:87
RuntimeTableEntry & operator=(const RuntimeTableEntry &)=default
static uint8_t get_raw(FLAGS f)
Definition FunctionVariants.hpp:114
bool another_table() const
Indicates whether impl() refers to an entry in another runtime table, rather than a direct function i...
Definition FunctionVariants.hpp:146
friend std::ostream & operator<<(std::ostream &os, const RuntimeTableEntry &entry)
Definition FunctionVariants.hpp:167
static constexpr uint32_t MAX_IMPL
The implementation address/index is encoded on 31 bits.
Definition FunctionVariants.hpp:79
static constexpr uint32_t F_ARM64
Definition FunctionVariants.hpp:86
uint32_t impl() const
The relative address of the implementation or an index if another_table() is set.
Definition FunctionVariants.hpp:131
static constexpr uint32_t F_BIT
Definition FunctionVariants.hpp:81
static std::vector< RuntimeTable > parse_payload(SpanStream &stream)
it_const_runtime_table runtime_table() const
Definition FunctionVariants.hpp:327
RuntimeTable & add(RuntimeTable table)
Append a new RuntimeTable and return a reference to the inserted table.
Definition FunctionVariants.hpp:332
FunctionVariants()=default
uint32_t data_offset() const
Offset in the __LINKEDIT SegmentCommand where the payload starts.
Definition FunctionVariants.hpp:294
span< const uint8_t > content() const
Return the data slice in the __LINKEDIT segment referenced by data_offset and data_size;.
Definition FunctionVariants.hpp:313
static result< RuntimeTable > parse_entry(BinaryStream &stream, uint64_t max_entries)
ref_iterator< runtime_table_t & > it_runtime_table
Iterator that outputs RuntimeTable&.
Definition FunctionVariants.hpp:278
friend class BinaryParser
Definition FunctionVariants.hpp:71
std::unique_ptr< LoadCommand > clone() const override
Definition FunctionVariants.hpp:289
FunctionVariants(const details::linkedit_data_command &cmd)
void data_offset(uint32_t offset)
Definition FunctionVariants.hpp:303
span< uint8_t > content()
Definition FunctionVariants.hpp:317
FunctionVariants & operator=(const FunctionVariants ©)=default
~FunctionVariants() override=default
FunctionVariants(const FunctionVariants ©)=default
void data_size(uint32_t size)
Definition FunctionVariants.hpp:307
it_runtime_table runtime_table()
Iterator over the different RuntimeTable entries located in the content of this __LINKEDIT command.
Definition FunctionVariants.hpp:323
uint32_t data_size() const
Size of the payload.
Definition FunctionVariants.hpp:299
std::vector< RuntimeTable > runtime_table_t
Definition FunctionVariants.hpp:275
friend class LinkEdit
Definition FunctionVariants.hpp:72
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:281
static bool classof(const LoadCommand *cmd)
Definition FunctionVariants.hpp:341
Definition LinkEdit.hpp:47
uint32_t size() const
Size of the command (should be greater than sizeof(load_command)).
Definition LoadCommand.hpp:137
LoadCommand::TYPE command() const
Command type.
Definition LoadCommand.hpp:132
@ FUNCTION_VARIANTS
Definition LoadCommand.hpp:104
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:79
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition endianness_support.hpp:59
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
@ UNKNOWN
Definition MachO/enums.hpp:25
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:316
Definition FunctionVariants.hpp:42
uint8_t flag_bit_nums[4]
Definition FunctionVariants.hpp:45
uint32_t impl
Definition FunctionVariants.hpp:43
uint32_t another_table
Definition FunctionVariants.hpp:44
#define LIEF_API
Definition visibility.h:45
#define LIEF_LOCAL
Definition visibility.h:46