2020-02-15 18:42:14 +01:00
|
|
|
//---
|
|
|
|
// fxos.symbols: User-defined symbols for OS objects
|
|
|
|
//---
|
|
|
|
|
|
|
|
#ifndef LIBFXOS_SYMBOLS_H
|
|
|
|
#define LIBFXOS_SYMBOLS_H
|
|
|
|
|
|
|
|
#include <optional>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2020-06-13 11:23:46 +02:00
|
|
|
#include <fxos/os.h>
|
|
|
|
|
2020-02-15 18:42:14 +01:00
|
|
|
namespace FxOS
|
|
|
|
{
|
|
|
|
|
2022-03-04 12:29:33 +01:00
|
|
|
class VirtualSpace;
|
|
|
|
|
2020-02-15 18:42:14 +01:00
|
|
|
/* A named symbol that can be substituted to literal values in the code. */
|
|
|
|
struct Symbol
|
|
|
|
{
|
|
|
|
/* Syscall: The value is a syscall number. The syscall number for an
|
|
|
|
address is determined by querying the OS object.
|
|
|
|
Address: The value is a fixed 32-bit virtual address. */
|
|
|
|
enum Type { Syscall=1, Address=2 };
|
|
|
|
|
|
|
|
enum Type type;
|
|
|
|
uint32_t value;
|
|
|
|
|
|
|
|
/* Symbol name, no particular conventions */
|
|
|
|
std::string name;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* A symbol table, essentially a set of symbols loaded from the same file */
|
2020-06-13 11:23:46 +02:00
|
|
|
class SymbolTable
|
2020-02-15 18:42:14 +01:00
|
|
|
{
|
2020-06-13 11:23:46 +02:00
|
|
|
public:
|
|
|
|
/* Construct a new symbol table for the specified OS and MPU; the two
|
|
|
|
constraints apply simultaneously. For both, an empty string
|
|
|
|
represents no constraint. */
|
|
|
|
SymbolTable(std::string os="", std::string mpu="");
|
|
|
|
|
2022-03-04 12:29:33 +01:00
|
|
|
/* Allow move but disable copy */
|
|
|
|
SymbolTable(SymbolTable const &other) = delete;
|
|
|
|
SymbolTable(SymbolTable &&other) = default;
|
|
|
|
|
2020-02-15 18:42:14 +01:00
|
|
|
std::string table_name;
|
|
|
|
std::vector<Symbol> symbols;
|
|
|
|
|
2020-06-13 11:23:46 +02:00
|
|
|
/* Validate constraints to see if table is usable */
|
|
|
|
bool is_usable_on(OS &os) const noexcept;
|
2021-03-16 14:43:43 +01:00
|
|
|
bool is_usable_on(VirtualSpace &space) const noexcept;
|
2020-02-15 18:42:14 +01:00
|
|
|
/* Add a symbol to the table */
|
|
|
|
void add(Symbol s);
|
|
|
|
/* Query a value for a certain type of symbol */
|
|
|
|
std::optional<std::string> query(Symbol::Type type, uint32_t value)
|
|
|
|
const;
|
2020-02-17 22:47:09 +01:00
|
|
|
/* Lookup the symbol behind a given name */
|
|
|
|
std::optional<Symbol> lookup(std::string name) const;
|
2020-06-13 11:23:46 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::string m_os_constraint;
|
|
|
|
std::string m_mpu_constraint;
|
2020-02-15 18:42:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace FxOS */
|
|
|
|
|
|
|
|
#endif /* LIBFXOS_SYMBOLS_H */
|