#include "base/memory/shared_memory_switch.h"
#include <optional>
#include <string_view>
#include "base/command_line.h"
#include "base/logging.h"
#include "base/memory/read_only_shared_memory_region.h"
#include "base/memory/unsafe_shared_memory_region.h"
#include "base/process/launch.h"
#include "base/process/process_handle.h"
#include "base/process/process_info.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/types/expected.h"
#include "base/unguessable_token.h"
#if BUILDFLAG(IS_APPLE)
#include "base/mac/mach_port_rendezvous.h"
#endif
#if BUILDFLAG(IS_POSIX)
#include "base/posix/global_descriptors.h"
#endif
#if BUILDFLAG(IS_WIN)
#include <windows.h>
#include "base/win/win_util.h"
#endif
#if BUILDFLAG(IS_FUCHSIA)
#include <lib/zx/vmo.h>
#include <zircon/process.h>
#include "base/fuchsia/fuchsia_logging.h"
#endif
namespace base {
namespace shared_memory {
namespace {
PlatformSharedMemoryRegion;
ScopedPlatformSharedMemoryHandle;
constexpr size_t kMaxSharedMemorySize = …;
ScopedPlatformSharedMemoryHandle GetPlatformHandle(
PlatformSharedMemoryRegion& shmem_region,
[[maybe_unused]] bool make_read_only) { … }
std::string Serialize(PlatformSharedMemoryRegion shmem_region,
bool is_read_only,
#if BUILDFLAG(IS_APPLE)
MachPortsForRendezvous::key_type rendezvous_key,
#elif BUILDFLAG(IS_POSIX)
GlobalDescriptors::Key descriptor_key,
ScopedFD& descriptor_to_share,
#endif
[[maybe_unused]] LaunchOptions* launch_options) { … }
std::optional<UnguessableToken> DeserializeGUID(std::string_view hi_part,
std::string_view lo_part) { … }
expected<PlatformSharedMemoryRegion, SharedMemoryError> Deserialize(
std::string_view switch_value,
PlatformSharedMemoryRegion::Mode mode) { … }
}
void AddToLaunchParameters(std::string_view switch_name,
ReadOnlySharedMemoryRegion read_only_memory_region,
#if BUILDFLAG(IS_APPLE)
MachPortsForRendezvous::key_type rendezvous_key,
#elif BUILDFLAG(IS_POSIX)
GlobalDescriptors::Key descriptor_key,
ScopedFD& out_descriptor_to_share,
#endif
CommandLine* command_line,
LaunchOptions* launch_options) { … }
void AddToLaunchParameters(std::string_view switch_name,
UnsafeSharedMemoryRegion unsafe_memory_region,
#if BUILDFLAG(IS_APPLE)
MachPortsForRendezvous::key_type rendezvous_key,
#elif BUILDFLAG(IS_POSIX)
GlobalDescriptors::Key descriptor_key,
ScopedFD& out_descriptor_to_share,
#endif
CommandLine* command_line,
LaunchOptions* launch_options) { … }
expected<UnsafeSharedMemoryRegion, SharedMemoryError>
UnsafeSharedMemoryRegionFrom(std::string_view switch_value) { … }
expected<ReadOnlySharedMemoryRegion, SharedMemoryError>
ReadOnlySharedMemoryRegionFrom(std::string_view switch_value) { … }
}
}