1 /* Copyright (c) 2008-2020. 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"
15 /** Options for read operations
17 * This is a set of flags managed with bitwise operators. Only the
18 * meaningful operations are defined: addition, conversions to/from
19 * integers are not allowed.
22 std::uint32_t value_ = 0;
23 constexpr explicit ReadOptions(std::uint32_t value) : value_(value) {}
26 constexpr ReadOptions() {}
28 explicit constexpr operator bool() const { return value_ != 0; }
29 constexpr bool operator!() const { return value_ == 0; }
31 constexpr ReadOptions operator|(ReadOptions const& that) const
33 return ReadOptions(value_ | that.value_);
35 constexpr ReadOptions operator&(ReadOptions const& that) const
37 return ReadOptions(value_ & that.value_);
39 constexpr ReadOptions operator^(ReadOptions const& that) const
41 return ReadOptions(value_ ^ that.value_);
43 constexpr ReadOptions operator~() const
45 return ReadOptions(~value_);
48 ReadOptions& operator|=(ReadOptions const& that)
50 value_ |= that.value_;
53 ReadOptions& operator&=(ReadOptions const& that)
55 value_ &= that.value_;
58 ReadOptions& operator^=(ReadOptions const& that)
60 value_ &= that.value_;
64 /** Copy the data to the given buffer */
65 static constexpr ReadOptions none() { return ReadOptions(0); }
67 /** Allows to return a pointer to another buffer where the data is
68 * available instead of copying the data into the buffer
70 static constexpr ReadOptions lazy() { return ReadOptions(1); }
73 /** A given state of a given process (abstract base class)
75 * Currently, this might either be:
77 * * the current state of an existing process;
81 * In order to support SMPI privatization, the can read the memory from the
82 * context of a given SMPI process: if specified, the code reads data from the
83 * correct SMPI privatization VMA.
87 RemoteClient* process_;
90 explicit AddressSpace(RemoteClient* process) : process_(process) {}
91 virtual ~AddressSpace() = default;
93 /** The process of this address space
95 * This is where we can get debug informations, memory layout, etc.
97 simgrid::mc::RemoteClient* process() const { return process_; }
99 /** Read data from the address space
101 * @param buffer target buffer for the data
102 * @param size number of bytes to read
103 * @param address remote source address of the data
106 virtual void* read_bytes(void* buffer, std::size_t size, RemotePtr<void> address,
107 ReadOptions options = ReadOptions::none()) const = 0;
109 /** Read a given data structure from the address space */
110 template <class T> inline void read(T* buffer, RemotePtr<T> ptr) const { this->read_bytes(buffer, sizeof(T), ptr); }
112 template <class T> inline void read(Remote<T>& buffer, RemotePtr<T> ptr) const
114 this->read_bytes(buffer.get_buffer(), sizeof(T), ptr);
117 /** Read a given data structure from the address space
119 * This version returns by value.
121 template <class T> inline Remote<T> read(RemotePtr<T> ptr) const
124 this->read_bytes(&res, sizeof(T), ptr);
128 /** Read a string of known size */
129 std::string read_string(RemotePtr<char> address, std::size_t len) const
133 this->read_bytes(&res[0], len, address);