From 5c20de212a1686c0407ed649eb46a121a0cb0b58 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Wed, 25 Sep 2024 16:22:45 +0200 Subject: [PATCH] base: Attached_dataspace::bytes accessor The new bytes() accessor returns a Byte_range_pointer as an alternative to the 'local_addr' for accessing the content of the dataspace. This facilitates the safe practice of passing (and validating) the buffer bounds along with the pointer. Issue #5351 --- repos/base/include/base/attached_dataspace.h | 11 +++++------ repos/base/include/base/attached_ram_dataspace.h | 5 +++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/repos/base/include/base/attached_dataspace.h b/repos/base/include/base/attached_dataspace.h index 8adaba4d48..98ef92b3dd 100644 --- a/repos/base/include/base/attached_dataspace.h +++ b/repos/base/include/base/attached_dataspace.h @@ -54,12 +54,6 @@ class Genode::Attached_dataspace : Noncopyable [&] (Region_map::Attach_error) { return nullptr; }); } - /* - * Noncopyable - */ - Attached_dataspace(Attached_dataspace const &); - Attached_dataspace &operator = (Attached_dataspace const &); - public: /** @@ -118,6 +112,11 @@ class Genode::Attached_dataspace : Noncopyable [&] (Region_map::Attach_error) { return 0UL; }); } + /** + * Return byte range of locally mapped dataspace + */ + Byte_range_ptr bytes() const { return { _ptr(), size() }; } + /** * Forget dataspace, thereby skipping the detachment on destruction * diff --git a/repos/base/include/base/attached_ram_dataspace.h b/repos/base/include/base/attached_ram_dataspace.h index f6b316ef94..b04c654c46 100644 --- a/repos/base/include/base/attached_ram_dataspace.h +++ b/repos/base/include/base/attached_ram_dataspace.h @@ -163,6 +163,11 @@ class Genode::Attached_ram_dataspace _alloc_and_attach(); } + + /** + * Return byte range of locally mapped dataspace + */ + Byte_range_ptr bytes() const { return { local_addr(), size() }; } }; #endif /* _INCLUDE__BASE__ATTACHED_RAM_DATASPACE_H_ */