1 /* Copyright (c) 2008-2023. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef SIMGRID_MC_ADDRESS_SPACE_H
7 #define SIMGRID_MC_ADDRESS_SPACE_H
9 #include "src/mc/mc_forward.hpp"
10 #include "src/mc/remote/RemotePtr.hpp"
12 namespace simgrid::mc {
14 /** Options for read operations
16 * This is a set of flags managed with bitwise operators. Only the
17 * meaningful operations are defined: addition, conversions to/from
18 * integers are not allowed.
21 std::uint32_t value_ = 0;
22 constexpr explicit ReadOptions(std::uint32_t value) : value_(value) {}
25 constexpr ReadOptions() = default;
27 explicit constexpr operator bool() const { return value_ != 0; }
28 constexpr bool operator!() const { return value_ == 0; }
30 constexpr ReadOptions operator|(ReadOptions const& that) const
32 return ReadOptions(value_ | that.value_);
34 constexpr ReadOptions operator&(ReadOptions const& that) const
36 return ReadOptions(value_ & that.value_);
38 constexpr ReadOptions operator^(ReadOptions const& that) const
40 return ReadOptions(value_ ^ that.value_);
42 constexpr ReadOptions operator~() const
44 return ReadOptions(~value_);
47 ReadOptions& operator|=(ReadOptions const& that)
49 value_ |= that.value_;
52 ReadOptions& operator&=(ReadOptions const& that)
54 value_ &= that.value_;
57 ReadOptions& operator^=(ReadOptions const& that)
59 value_ ^= that.value_;
63 /** Copy the data to the given buffer */
64 static constexpr ReadOptions none() { return ReadOptions(0); }
66 /** Allows to return a pointer to another buffer where the data is
67 * available instead of copying the data into the buffer
69 static constexpr ReadOptions lazy() { return ReadOptions(1); }
72 /** A given state of a given process (abstract base class)
74 * Currently, this might either be:
76 * * the current state of an existing process;
82 RemoteProcessMemory* remote_process_memory_;
85 explicit AddressSpace(RemoteProcessMemory* process) : remote_process_memory_(process) {}
86 virtual ~AddressSpace() = default;
88 /** The process of this address space
90 * This is where we can get debug information, memory layout, etc.
92 simgrid::mc::RemoteProcessMemory* get_remote_process_memory() const { return remote_process_memory_; }
94 /** Read data from the address space
96 * @param buffer target buffer for the data
97 * @param size number of bytes to read
98 * @param address remote source address of the data
101 virtual void* read_bytes(void* buffer, std::size_t size, RemotePtr<void> address,
102 ReadOptions options = ReadOptions::none()) const = 0;
104 /** Read a given data structure from the address space */
105 template <class T> inline void read(T* buffer, RemotePtr<T> ptr) const { this->read_bytes(buffer, sizeof(T), ptr); }
107 template <class T> inline void read(Remote<T>& buffer, RemotePtr<T> ptr) const
109 this->read_bytes(buffer.get_buffer(), sizeof(T), ptr);
112 /** Read a given data structure from the address space
114 * This version returns by value.
116 template <class T> inline Remote<T> read(RemotePtr<T> ptr) const
119 this->read_bytes(&res, sizeof(T), ptr);
123 /** Read a string of known size */
124 std::string read_string(RemotePtr<char> address, std::size_t len) const
128 this->read_bytes(&res[0], len, address);
133 } // namespace simgrid::mc