28 using pointer_query =
decltype(make_remote_offset_query<uintptr_t, RemotePtr>(0));
39 span<std::byte> scratch RELOCO_LIFETIMEBOUND, ptrdiff_t ptr_offset = 0) noexcept
40 : ptr_addr_(ptr_addr), space_(space), scratch_(scratch),
41 pointer_(make_remote_offset_query<uintptr_t, RemotePtr>(ptr_offset)) {}
49 uintptr_t obj_addr = 0;
50 if (!pointer_(space_, ptr_addr_, obj_addr)) {
64 T *val_ptr = allocator.allocate<T>();
67 if (!space_.read_bytes(obj_addr, val_ptr,
sizeof(T)))
77 span<std::byte> scratch_;
78 pointer_query pointer_;
91template <
typename T,
typename RemotePtr = u
intptr_t,
typename RemoteRefCount =
int32_t>
93 using pointer_query =
decltype(make_remote_offset_query<uintptr_t, RemotePtr>(0));
94 using count_query =
decltype(make_remote_offset_query<RemoteRefCount, RemoteRefCount>(0));
109 span<std::byte> scratch RELOCO_LIFETIMEBOUND, ptrdiff_t ptr_offset,
110 ptrdiff_t control_block_offset, ptrdiff_t use_count_offset,
111 ptrdiff_t weak_count_offset) noexcept
112 : addr_(shared_ptr_addr), space_(space), scratch_(scratch),
113 pointer_(make_remote_offset_query<uintptr_t, RemotePtr>(ptr_offset)),
114 control_block_(make_remote_offset_query<uintptr_t, RemotePtr>(control_block_offset)),
115 use_count_(make_remote_offset_query<RemoteRefCount, RemoteRefCount>(use_count_offset)),
116 weak_count_(make_remote_offset_query<RemoteRefCount, RemoteRefCount>(weak_count_offset)) {}
124 uintptr_t obj_addr = 0;
125 if (!pointer_(space_, addr_, obj_addr)) {
130 out.write(
"shared_ptr(nullptr)");
134 uintptr_t cb_addr = 0;
135 if (!control_block_(space_, addr_, cb_addr)) {
139 RemoteRefCount use_cnt = -1;
140 RemoteRefCount weak_cnt = -1;
143 std::ignore = use_count_(space_, cb_addr, use_cnt);
144 std::ignore = weak_count_(space_, cb_addr, weak_cnt);
147 out.write(
"shared_ptr(");
154 if (T *val_ptr = allocator.allocate<T>()) {
155 if (space_.read_bytes(obj_addr, val_ptr,
sizeof(T))) {
158 out.write(
"<fault>");
164 static_cast<int64_t
>(weak_cnt));
171 span<std::byte> scratch_;
172 pointer_query pointer_;
173 pointer_query control_block_;
174 count_query use_count_;
175 count_query weak_count_;
188template <
typename T,
typename RemotePtr = u
intptr_t,
typename RemoteRefCount =
int32_t>
190 using pointer_query =
decltype(make_remote_offset_query<uintptr_t, RemotePtr>(0));
191 using count_query =
decltype(make_remote_offset_query<RemoteRefCount, RemoteRefCount>(0));
203 span<std::byte> scratch RELOCO_LIFETIMEBOUND, ptrdiff_t ptr_offset,
204 ptrdiff_t ref_count_offset) noexcept
205 : addr_(intrusive_ptr_addr), space_(space), scratch_(scratch),
206 pointer_(make_remote_offset_query<uintptr_t, RemotePtr>(ptr_offset)),
207 ref_count_(make_remote_offset_query<RemoteRefCount, RemoteRefCount>(ref_count_offset)) {}
215 uintptr_t obj_addr = 0;
216 if (!pointer_(space_, addr_, obj_addr)) {
221 out.write(
"intrusive_ptr(nullptr)");
225 RemoteRefCount ref_cnt = 0;
226 std::ignore = ref_count_(space_, obj_addr, ref_cnt);
228 out.write(
"intrusive_ptr(");
235 if (T *val_ptr = allocator.allocate<T>()) {
236 if (space_.read_bytes(obj_addr, val_ptr,
sizeof(T))) {
239 out.write(
"<fault>");
251 span<std::byte> scratch_;
252 pointer_query pointer_;
253 count_query ref_count_;
270 [[nodiscard]]
constexpr uintptr_t
address() const noexcept {
return static_cast<uintptr_t
>(ptr_); }
271 [[nodiscard]]
constexpr bool is_null() const noexcept {
return ptr_ == 0; }
272 [[nodiscard]]
constexpr explicit operator bool() const noexcept {
return ptr_ != 0; }
285template <
typename T,
typename RemotePtr = u
intptr_t,
typename RemoteRefCount =
int32_t>
class remote_shared_ptr {
289 [[nodiscard]]
constexpr uintptr_t
address() const noexcept {
return static_cast<uintptr_t
>(ptr_); }
291 return static_cast<uintptr_t
>(control_block_);
293 [[nodiscard]]
constexpr bool is_null() const noexcept {
return ptr_ == 0; }
294 [[nodiscard]]
constexpr explicit operator bool() const noexcept {
return ptr_ != 0; }
298 RemotePtr control_block_{0};
308template <
typename T, ptrdiff_t RefCountOffset = 0,
typename RemotePtr = u
intptr_t,
typename RemoteRefCount =
int32_t>
314 [[nodiscard]]
constexpr uintptr_t
address() const noexcept {
return static_cast<uintptr_t
>(ptr_); }
315 [[nodiscard]]
constexpr bool is_null() const noexcept {
return ptr_ == 0; }
316 [[nodiscard]]
constexpr explicit operator bool() const noexcept {
return ptr_ != 0; }
331 RELOCO_BEGIN_UNSAFE_CODE
334 uintptr_t obj_addr = uptr.
address();
336 out.write(
"nullptr");
339 span<std::byte> scratch_bytes(
reinterpret_cast<std::byte *
>(work_buf.data()), work_buf.size());
346template <
typename T,
typename RemotePtr,
typename RemoteRefCount>
350 RELOCO_BEGIN_UNSAFE_CODE
353 if (sptr.is_null()) {
354 out.write(
"shared_ptr(nullptr)");
357 span<std::byte> scratch_bytes(
reinterpret_cast<std::byte *
>(work_buf.data()), work_buf.size());
359 reinterpret_cast<uintptr_t
>(field_ptr), space, scratch_bytes, 0,
sizeof(RemotePtr), 0,
sizeof(RemoteRefCount));
365template <
typename T, ptrdiff_t RefCountOffset,
typename RemotePtr,
typename RemoteRefCount>
369 RELOCO_BEGIN_UNSAFE_CODE
373 if (iptr.is_null()) {
374 out.write(
"intrusive_ptr(nullptr)");
378 span<std::byte> scratch_bytes(
reinterpret_cast<std::byte *
>(work_buf.data()), work_buf.size());
380 scratch_bytes, 0, RefCountOffset);
394 out.write(
"nullptr");
405 out.write(
"shared_ptr(nullptr)");
416 out.write(
"intrusive_ptr(nullptr)");
433 if (!view.format(out)) {
434 out.write(
"<fault>");
439template <
typename T,
typename RemotePtr,
typename RemoteRefCount>
445 if (!view.format(out)) {
446 out.write(
"<fault>");
451template <
typename T,
typename RemotePtr,
typename RemoteRefCount>
457 if (!view.format(out)) {
458 out.write(
"<fault>");
Type-erased remote address-space access and remote string/object views.
Type-erased, two-word handle to a remote address space.
Definition address_space.hpp:204
Definition microfmt.hpp:881
Formattable view over an intrusive pointer with an embedded count.
Definition remote_smart_ptr.hpp:189
constexpr remote_intrusive_ptr_view(uintptr_t intrusive_ptr_addr, address_space_ref space, span< std::byte > scratch RELOCO_LIFETIMEBOUND, ptrdiff_t ptr_offset, ptrdiff_t ref_count_offset) noexcept
Constructs a view over a remote intrusive-pointer object.
Definition remote_smart_ptr.hpp:202
bool format(const sink &out) const noexcept
Loads and renders the pointee and its embedded reference count.
Definition remote_smart_ptr.hpp:214
Layout wrapper for a remote intrusive pointer.
Definition remote_smart_ptr.hpp:309
static constexpr ptrdiff_t ref_count_offset() noexcept
Definition remote_smart_ptr.hpp:318
constexpr remote_intrusive_ptr(RemotePtr ptr) noexcept
Definition remote_smart_ptr.hpp:312
constexpr bool is_null() const noexcept
Definition remote_smart_ptr.hpp:315
constexpr remote_intrusive_ptr() noexcept
Definition remote_smart_ptr.hpp:311
constexpr uintptr_t address() const noexcept
Definition remote_smart_ptr.hpp:314
Definition remote_object.hpp:231
Formattable view over a shared pointer and its remote control block.
Definition remote_smart_ptr.hpp:92
constexpr remote_shared_ptr_view(uintptr_t shared_ptr_addr, address_space_ref space, span< std::byte > scratch RELOCO_LIFETIMEBOUND, ptrdiff_t ptr_offset, ptrdiff_t control_block_offset, ptrdiff_t use_count_offset, ptrdiff_t weak_count_offset) noexcept
Constructs a view over a remote shared-pointer object.
Definition remote_smart_ptr.hpp:108
bool format(const sink &out) const noexcept
Loads and renders the pointee and reference counts.
Definition remote_smart_ptr.hpp:123
Layout wrapper for a remote shared pointer.
Definition remote_smart_ptr.hpp:285
constexpr uintptr_t control_block_address() const noexcept
Definition remote_smart_ptr.hpp:290
constexpr bool is_null() const noexcept
Definition remote_smart_ptr.hpp:293
constexpr remote_shared_ptr() noexcept
Definition remote_smart_ptr.hpp:287
constexpr uintptr_t address() const noexcept
Definition remote_smart_ptr.hpp:289
Formattable view over a unique pointer stored in a remote process.
Definition remote_smart_ptr.hpp:27
bool format(const sink &out) const noexcept
Loads and renders the pointee or nullptr.
Definition remote_smart_ptr.hpp:48
constexpr remote_unique_ptr_view(uintptr_t ptr_addr, address_space_ref space, span< std::byte > scratch RELOCO_LIFETIMEBOUND, ptrdiff_t ptr_offset=0) noexcept
Constructs a view over a remote unique-pointer object.
Definition remote_smart_ptr.hpp:38
Layout wrapper for a remote unique pointer.
Definition remote_smart_ptr.hpp:265
constexpr bool is_null() const noexcept
Definition remote_smart_ptr.hpp:271
constexpr remote_unique_ptr(RemotePtr ptr) noexcept
Definition remote_smart_ptr.hpp:268
constexpr remote_unique_ptr() noexcept
Definition remote_smart_ptr.hpp:267
constexpr uintptr_t address() const noexcept
Definition remote_smart_ptr.hpp:270
Zero-allocation bump allocator for scratch buffers.
Definition scratch_allocator.hpp:27
reloco::sink sink
Type-erased, zero-allocation output sink.
Definition microfmt.hpp:46
RELOCO_CONSTEXPR20 void format_to(const sink &out, microfmt::string_view fmt, const Args &...args) noexcept
Definition microfmt.hpp:1766
RELOCO_END_UNSAFE_CODE
Definition remote_object.hpp:132
Reusable callback and typed-offset accessors for remote layouts.
Remote object dumping, layout macros, and string pointer wrappers with 32-bit compatibility support.
static RELOCO_BEGIN_UNSAFE_CODE void format(address_space_ref space, const void *field_ptr, span< char > work_buf, const sink &out) noexcept
Definition remote_smart_ptr.hpp:370
static RELOCO_BEGIN_UNSAFE_CODE void format(address_space_ref space, const void *field_ptr, span< char > work_buf, const sink &out) noexcept
Definition remote_smart_ptr.hpp:351
static RELOCO_BEGIN_UNSAFE_CODE void format(address_space_ref space, const void *field_ptr, span< char > work_buf, const sink &out) noexcept
Definition remote_smart_ptr.hpp:332
Default field formatter policy. Can be specialized or overloaded for custom remote types,...
Definition remote_object.hpp:49
Traits customization point for remote object metadata.
Definition remote_object.hpp:217
Definition remote_object.hpp:229