X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/9782799d931fd74cdcc7832681b4684aa145a50f..63c371bbca5afccc4708761d83af6fc2443ca553:/src/mc/RemotePtr.hpp diff --git a/src/mc/RemotePtr.hpp b/src/mc/RemotePtr.hpp deleted file mode 100644 index e69af01a86..0000000000 --- a/src/mc/RemotePtr.hpp +++ /dev/null @@ -1,181 +0,0 @@ -/* Copyright (c) 2008-2015. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#ifndef SIMGRID_MC_REMOTE_PTR_HPP -#define SIMGRID_MC_REMOTE_PTR_HPP - -#include -#include -#include - -#include -#include - -namespace simgrid { -namespace mc { - -/** HACK, A value from another process - * - * This represents a value from another process: - * - * * constructor/destructor are disabled; - * - * * raw memory copy (std::memcpy) is used to copy Remote; - * - * * raw memory comparison is used to compare them; - * - * * when T is a trivial type, Remote is convertible to a T. - * - * We currently only handle the case where the type has the same layout - * in the current process and in the target process: we don't handle - * cross-architecture (such as 32-bit/64-bit access). - */ -template -union Remote { -private: - T buffer; -public: - Remote() {} - ~Remote() {} - Remote(T& p) - { - std::memcpy(&buffer, &p, sizeof(buffer)); - } - Remote(Remote const& that) - { - std::memcpy(&buffer, &that.buffer, sizeof(buffer)); - } - Remote& operator=(Remote const& that) - { - std::memcpy(&buffer, &that.buffer, sizeof(buffer)); - return *this; - } - T* getBuffer() { return &buffer; } - const T* getBuffer() const { return &buffer; } - std::size_t getBufferSize() const { return sizeof(T); } - operator T() const { - static_assert(std::is_trivial::value, "Cannot convert non trivial type"); - return buffer; - } - void clear() - { - std::memset(static_cast(&buffer), 0, sizeof(T)); - } - -}; - -/** Pointer to a remote address-space (process, snapshot) - * - * With this we can clearly identify the expected type of an address in the - * remote process while avoiding to use native local pointers. - * - * Some operators (+/-) assume use the size of the underlying element. This - * only works if the target applications is using the same target: it won't - * work for example, when inspecting a 32 bit application from a 64 bit - * model-checker. - * - * We do not actually store the target address space because we can - * always detect it in context. This way `RemotePtr` is as efficient - * as a `uint64_t`. - */ -template class RemotePtr { - std::uint64_t address_; -public: - RemotePtr() : address_(0) {} - RemotePtr(std::uint64_t address) : address_(address) {} - RemotePtr(T* address) : address_((std::uintptr_t)address) {} - RemotePtr(Remote p) : RemotePtr(*p.getBuffer()) {} - std::uint64_t address() const { return address_; } - - /** Turn into a local pointer - * - (if the remote process is not, in fact, remote) */ - T* local() const { return (T*) address_; } - - operator bool() const - { - return address_; - } - bool operator!() const - { - return !address_; - } - operator RemotePtr() const - { - return RemotePtr(address_); - } - RemotePtr operator+(std::uint64_t n) const - { - return RemotePtr(address_ + n * sizeof(T)); - } - RemotePtr operator-(std::uint64_t n) const - { - return RemotePtr(address_ - n * sizeof(T)); - } - RemotePtr& operator+=(std::uint64_t n) - { - address_ += n * sizeof(T); - return *this; - } - RemotePtr& operator-=(std::uint64_t n) - { - address_ -= n * sizeof(T); - return *this; - } -}; - -template -bool operator<(RemotePtr const& x, RemotePtr const& y) -{ - return x.address() < y.address(); -} - -template -bool operator>(RemotePtr const& x, RemotePtr const& y) -{ - return x.address() > y.address(); -} - -template -bool operator>=(RemotePtr const& x, RemotePtr const& y) -{ - return x.address() >= y.address(); -} - -template -bool operator<=(RemotePtr const& x, RemotePtr const& y) -{ - return x.address() <= y.address(); -} - -template -bool operator==(RemotePtr const& x, RemotePtr const& y) -{ - return x.address() == y.address(); -} - -template -bool operator!=(RemotePtr const& x, RemotePtr const& y) -{ - return x.address() != y.address(); -} - -template inline -RemotePtr remote(T *p) -{ - return RemotePtr(p); -} - -template inline -RemotePtr remote(uint64_t p) -{ - return RemotePtr(p); -} - -} -} - -#endif