26 return size_query(space, object_address, size);
30 uintptr_t &data_address)
const noexcept {
31 return data_query(space, object_address, data_address, size);
41 size_t size)
const noexcept {
73 span<char> scratch RELOCO_LIFETIMEBOUND RELOCO_LIFETIME_CAPTURE_BY_THIS,
74 Layout layout,
size_t max_limit = 4096) noexcept
75 : object_address_(object_address), space_(space), scratch_(scratch), layout_(layout), max_limit_(max_limit) {}
82 char (&scratch RELOCO_LIFETIMEBOUND RELOCO_LIFETIME_CAPTURE_BY_THIS)[N],
83 Layout layout,
size_t max_limit = 4096) noexcept
84 : object_address_(object_address), space_(space), scratch_(scratch, N), layout_(layout), max_limit_(max_limit) {}
86 [[nodiscard]]
constexpr uintptr_t
object_address() const noexcept {
return object_address_; }
90 [[nodiscard]]
constexpr span<char>
scratch() const noexcept RELOCO_LIFETIMEBOUND {
return scratch_; }
92 [[nodiscard]]
constexpr size_t max_limit() const noexcept {
return max_limit_; }
94 [[nodiscard]]
bool resolve(uintptr_t &data_address,
size_t &size)
const noexcept {
95 return layout_.read_size(space_, object_address_, size) &&
96 layout_.read_data_address(space_, object_address_, size, data_address);
100 uintptr_t object_address_{0};
101 address_space_ref space_{};
102 span<char> scratch_{};
104 size_t max_limit_{4096};
110template <
typename Layout>
112 span<char> scratch, Layout layout,
113 size_t max_limit = 4096) noexcept {
117template <
typename Layout,
size_t N>
119 char (&scratch)[N], Layout layout,
120 size_t max_limit = 4096) noexcept {
134 template <
typename SizeReader,
typename DataReader>
135 [[nodiscard]]
static constexpr auto callback_layout(SizeReader size_reader, DataReader data_reader)
noexcept {
136 auto size_query = make_remote_layout_query<size_t>(size_reader);
137 auto data_query = make_remote_layout_query<uintptr_t>(data_reader);
147 template <
typename RemotePtr = u
intptr_t,
typename RemoteSize =
size_t>
148 [[nodiscard]]
static constexpr auto pointer_size_layout(ptrdiff_t data_offset, ptrdiff_t size_offset)
noexcept {
149 auto size_query = make_remote_offset_query<size_t, RemoteSize>(size_offset);
150 auto data_query = make_remote_offset_query<uintptr_t, RemotePtr>(data_offset);
160 template <
typename RemotePtr = u
intptr_t,
typename RemoteSize =
size_t>
162 ptrdiff_t inline_data_offset,
163 size_t inline_capacity)
noexcept {
164 auto size_query = make_remote_offset_query<size_t, RemoteSize>(size_offset);
165 auto allocated_data_query = make_remote_offset_query<uintptr_t, RemotePtr>(data_offset);
167 allocated_data_query, inline_data_offset, inline_capacity};
168 auto data_query = make_remote_layout_query<uintptr_t>(data_reader);
177 if (view.object_address() == 0) {
186 uintptr_t data_address = 0;
188 if (!view.resolve(data_address, size)) {
194 if (data_address == 0) {
199 const size_t render_size = size < view.max_limit() ? size : view.max_limit();
200 const auto scratch = view.scratch();
201 if (render_size != 0 && scratch.empty()) {
207 while (total < render_size) {
208 const size_t remaining = render_size - total;
209 const size_t chunk_size = remaining < scratch.size() ? remaining : scratch.size();
210 if (data_address > std::numeric_limits<uintptr_t>::max() - total ||
211 !view.space().read_bytes(data_address + total, scratch.data(), chunk_size)) {
215 out.write(
"<fault>");
219 out.write(microfmt::string_view(scratch.data(), chunk_size));
223 if (size > view.max_limit())
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
Length-aware view over a remote C++ string object.
Definition remote_basic_string.hpp:62
constexpr span< char > scratch() const noexcept RELOCO_LIFETIMEBOUND
Definition remote_basic_string.hpp:90
constexpr size_t max_limit() const noexcept
Definition remote_basic_string.hpp:92
constexpr address_space_ref space() const noexcept
Definition remote_basic_string.hpp:88
bool resolve(uintptr_t &data_address, size_t &size) const noexcept
Definition remote_basic_string.hpp:94
constexpr remote_basic_string_view(uintptr_t object_address, address_space_ref space, span< char > scratch RELOCO_LIFETIMEBOUND RELOCO_LIFETIME_CAPTURE_BY_THIS, Layout layout, size_t max_limit=4096) noexcept
Constructs a view over a remote string object.
Definition remote_basic_string.hpp:72
constexpr remote_basic_string_view(uintptr_t object_address, address_space_ref space, char(&scratch RELOCO_LIFETIMEBOUND RELOCO_LIFETIME_CAPTURE_BY_THIS)[N], Layout layout, size_t max_limit=4096) noexcept
Constructs a view using a fixed C array as scratch storage.
Definition remote_basic_string.hpp:81
constexpr uintptr_t object_address() const noexcept
Definition remote_basic_string.hpp:86
#define MICROFMT_API_CLASS
Definition compat.hpp:181
RELOCO_BEGIN_UNSAFE_CODE constexpr uintptr_t add_address_offset(uintptr_t address, ptrdiff_t offset) noexcept
Definition address_space.hpp:52
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
constexpr auto make_remote_basic_string_view(uintptr_t object_address, address_space_ref space, span< char > scratch, Layout layout, size_t max_limit=4096) noexcept
Creates a length-aware remote string view with template deduction.
Definition remote_basic_string.hpp:111
Reusable callback and typed-offset accessors for remote layouts.
Definition remote_basic_string.hpp:21
bool read_data_address(address_space_ref space, uintptr_t object_address, size_t size, uintptr_t &data_address) const noexcept
Definition remote_basic_string.hpp:29
SizeQuery size_query
Definition remote_basic_string.hpp:22
DataQuery data_query
Definition remote_basic_string.hpp:23
bool read_size(address_space_ref space, uintptr_t object_address, size_t &size) const noexcept
Definition remote_basic_string.hpp:25
Definition remote_basic_string.hpp:35
bool operator()(address_space_ref space, uintptr_t object_address, uintptr_t &data_address, size_t size) const noexcept
Definition remote_basic_string.hpp:40
ptrdiff_t inline_data_offset
Definition remote_basic_string.hpp:37
DataQuery allocated_data_query
Definition remote_basic_string.hpp:36
size_t inline_capacity
Definition remote_basic_string.hpp:38
Factories for common remote C++ string object layouts.
Definition remote_basic_string.hpp:127
static constexpr auto pointer_size_layout(ptrdiff_t data_offset, ptrdiff_t size_offset) noexcept
Creates a layout whose object always stores a data pointer and size.
Definition remote_basic_string.hpp:148
static constexpr auto size_selected_layout(ptrdiff_t data_offset, ptrdiff_t size_offset, ptrdiff_t inline_data_offset, size_t inline_capacity) noexcept
Creates a layout selected by the decoded string length.
Definition remote_basic_string.hpp:161
static constexpr auto callback_layout(SizeReader size_reader, DataReader data_reader) noexcept
Creates a layout from explicit size and data-address readers.
Definition remote_basic_string.hpp:135