1 /* Copyright (c) 2008-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #ifndef SIMGRID_MC_REMOTE_PTR_HPP
8 #define SIMGRID_MC_REMOTE_PTR_HPP
15 /** Pointer to a remote address-space (process, snapshot)
17 * With this we can clearly identify the expected type of an address in the
18 * remote process while avoiding to use native local pointers.
20 * Some operators (+/-) assume use the size of the underlying element. This
21 * only works if the target applications is using the same target: it won't
22 * work for example, when inspecting a 32 bit application from a 64 bit
25 * We do not actually store the target address space because we can
26 * always detect it in context. This way `RemotePtr` is as efficient
29 template<class T> class RemotePtr {
30 std::uint64_t address_;
32 RemotePtr() : address_(0) {}
33 RemotePtr(std::uint64_t address) : address_(address) {}
34 RemotePtr(T* address) : address_((std::uintptr_t)address) {}
35 std::uint64_t address() const { return address_; }
41 bool operator!() const
45 operator RemotePtr<void>() const
47 return RemotePtr<void>(address_);
49 RemotePtr<T> operator+(std::uint64_t n) const
51 return RemotePtr<T>(address_ + n * sizeof(T));
53 RemotePtr<T> operator-(std::uint64_t n) const
55 return RemotePtr<T>(address_ - n * sizeof(T));
57 RemotePtr<T>& operator+=(std::uint64_t n)
59 address_ += n * sizeof(T);
62 RemotePtr<T>& operator-=(std::uint64_t n)
64 address_ -= n * sizeof(T);
69 template<class X, class Y>
70 bool operator<(RemotePtr<X> const& x, RemotePtr<Y> const& y)
72 return x.address() < y.address();
75 template<class X, class Y>
76 bool operator>(RemotePtr<X> const& x, RemotePtr<Y> const& y)
78 return x.address() > y.address();
81 template<class X, class Y>
82 bool operator>=(RemotePtr<X> const& x, RemotePtr<Y> const& y)
84 return x.address() >= y.address();
87 template<class X, class Y>
88 bool operator<=(RemotePtr<X> const& x, RemotePtr<Y> const& y)
90 return x.address() <= y.address();
93 template<class X, class Y>
94 bool operator==(RemotePtr<X> const& x, RemotePtr<Y> const& y)
96 return x.address() == y.address();
99 template<class X, class Y>
100 bool operator!=(RemotePtr<X> const& x, RemotePtr<Y> const& y)
102 return x.address() != y.address();
105 template<class T> inline
106 RemotePtr<T> remote(T *p)
108 return RemotePtr<T>(p);
111 template<class T=void> inline
112 RemotePtr<T> remote(uint64_t p)
114 return RemotePtr<T>(p);