1 /* Copyright (c) 2008-2022. 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;
80 * In order to support SMPI privatization, the can read the memory from the
81 * context of a given SMPI process: if specified, the code reads data from the
82 * correct SMPI privatization VMA.
86 RemoteProcess* remote_process_;
89 explicit AddressSpace(RemoteProcess* process) : remote_process_(process) {}
90 virtual ~AddressSpace() = default;
92 /** The process of this address space
94 * This is where we can get debug information, memory layout, etc.
96 simgrid::mc::RemoteProcess* get_remote_process() const { return remote_process_; }
98 /** Read data from the address space
100 * @param buffer target buffer for the data
101 * @param size number of bytes to read
102 * @param address remote source address of the data
105 virtual void* read_bytes(void* buffer, std::size_t size, RemotePtr<void> address,
106 ReadOptions options = ReadOptions::none()) const = 0;
108 /** Read a given data structure from the address space */
109 template <class T> inline void read(T* buffer, RemotePtr<T> ptr) const { this->read_bytes(buffer, sizeof(T), ptr); }
111 template <class T> inline void read(Remote<T>& buffer, RemotePtr<T> ptr) const
113 this->read_bytes(buffer.get_buffer(), sizeof(T), ptr);
116 /** Read a given data structure from the address space
118 * This version returns by value.
120 template <class T> inline Remote<T> read(RemotePtr<T> ptr) const
123 this->read_bytes(&res, sizeof(T), ptr);
127 /** Read a string of known size */
128 std::string read_string(RemotePtr<char> address, std::size_t len) const
132 this->read_bytes(&res[0], len, address);
137 } // namespace simgrid::mc