blob: 39fb1fa87ab2ef94a9ed5a8b4b2472901e49d061 [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2022 The Chromium Authors
Samuel Großcc95616f2022-04-28 09:48:252// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef BASE_MEMORY_SHARED_MEMORY_MAPPER_H_
6#define BASE_MEMORY_SHARED_MEMORY_MAPPER_H_
7
Arthur Sonzognie5fff99c2024-02-21 15:58:248#include <stdint.h>
9
10#include <optional>
11
Samuel Großcc95616f2022-04-28 09:48:2512#include "base/base_export.h"
13#include "base/containers/span.h"
14#include "base/memory/platform_shared_memory_handle.h"
Samuel Großcc95616f2022-04-28 09:48:2515
16namespace base {
17
18// Interface to implement mapping and unmapping of shared memory regions into
19// the virtual address space. The default implementation,
20// |PlatformSharedMemoryMapper| uses the platform-specific APIs to map the
21// region anywhere in the address space. Other implementations can be used for
22// example to always map the regions into an existing address space reservation.
23// Implementations of this interface should generally be statically allocated
24// as SharedMemoryMappings keep a reference to their mapper.
25class BASE_EXPORT SharedMemoryMapper {
26 public:
27 // Returns the default shared memory mapper.
28 static SharedMemoryMapper* GetDefaultInstance();
29
30 // Maps the shared memory region identified through the provided platform
31 // handle into the caller's address space.
Arthur Sonzognie5fff99c2024-02-21 15:58:2432 virtual std::optional<span<uint8_t>> Map(
Samuel Großcc95616f2022-04-28 09:48:2533 subtle::PlatformSharedMemoryHandle handle,
34 bool write_allowed,
35 uint64_t offset,
36 size_t size) = 0;
37
38 // Unmaps the specified region of shared memory from the caller's address
39 // space.
40 virtual void Unmap(span<uint8_t> mapping) = 0;
41};
42
43} // namespace base
44
45#endif // BASE_MEMORY_SHARED_MEMORY_MAPPER_H_