Use a read-only mapping for reading from shared memory
This makes it a lot harder for readers to accidentally write.
Change-Id: I29025f37b0767825e57314cc1221510fd9455b55
diff --git a/aos/events/shm_event_loop.h b/aos/events/shm_event_loop.h
index d7ea5e6..8dabcb5 100644
--- a/aos/events/shm_event_loop.h
+++ b/aos/events/shm_event_loop.h
@@ -83,7 +83,7 @@
// Returns the local mapping of the shared memory used by the watcher on the
// specified channel. A watcher must be created on this channel before calling
// this.
- absl::Span<char> GetWatcherSharedMemory(const Channel *channel);
+ absl::Span<const char> GetWatcherSharedMemory(const Channel *channel);
// Returns the local mapping of the shared memory used by the provided Sender.
template <typename T>
@@ -93,8 +93,12 @@
// Returns the local mapping of the private memory used by the provided
// Fetcher to hold messages.
+ //
+ // Note that this may be the entire shared memory region held by this fetcher,
+ // depending on its channel's read_method.
template <typename T>
- absl::Span<char> GetFetcherPrivateMemory(aos::Fetcher<T> *fetcher) const {
+ absl::Span<const char> GetFetcherPrivateMemory(
+ aos::Fetcher<T> *fetcher) const {
return GetShmFetcherPrivateMemory(GetRawFetcher(fetcher));
}
@@ -127,7 +131,7 @@
absl::Span<char> GetShmSenderSharedMemory(const aos::RawSender *sender) const;
// Private method to access the private memory mapping of a ShmFetcher.
- absl::Span<char> GetShmFetcherPrivateMemory(
+ absl::Span<const char> GetShmFetcherPrivateMemory(
const aos::RawFetcher *fetcher) const;
std::vector<std::function<void()>> on_run_;