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
This commit is contained in:
Norman Feske 2024-09-25 16:22:45 +02:00 committed by Christian Helmuth
parent e738162bde
commit 5c20de212a
2 changed files with 10 additions and 6 deletions

View File

@ -54,12 +54,6 @@ class Genode::Attached_dataspace : Noncopyable
[&] (Region_map::Attach_error) { return nullptr; }); [&] (Region_map::Attach_error) { return nullptr; });
} }
/*
* Noncopyable
*/
Attached_dataspace(Attached_dataspace const &);
Attached_dataspace &operator = (Attached_dataspace const &);
public: public:
/** /**
@ -118,6 +112,11 @@ class Genode::Attached_dataspace : Noncopyable
[&] (Region_map::Attach_error) { return 0UL; }); [&] (Region_map::Attach_error) { return 0UL; });
} }
/**
* Return byte range of locally mapped dataspace
*/
Byte_range_ptr bytes() const { return { _ptr<char>(), size() }; }
/** /**
* Forget dataspace, thereby skipping the detachment on destruction * Forget dataspace, thereby skipping the detachment on destruction
* *

View File

@ -163,6 +163,11 @@ class Genode::Attached_ram_dataspace
_alloc_and_attach(); _alloc_and_attach();
} }
/**
* Return byte range of locally mapped dataspace
*/
Byte_range_ptr bytes() const { return { local_addr<char>(), size() }; }
}; };
#endif /* _INCLUDE__BASE__ATTACHED_RAM_DATASPACE_H_ */ #endif /* _INCLUDE__BASE__ATTACHED_RAM_DATASPACE_H_ */