#ifndef BASE_MEMORY_SHARED_MEMORY_SWITCH_H_
#define BASE_MEMORY_SHARED_MEMORY_SWITCH_H_
#include <string_view>
#include "base/base_export.h"
#include "base/memory/read_only_shared_memory_region.h"
#include "base/memory/unsafe_shared_memory_region.h"
#include "base/types/expected.h"
#include "build/blink_buildflags.h"
#include "build/build_config.h"
#if !BUILDFLAG(USE_BLINK)
#error "This is only intended for platforms that use blink."
#endif
#if BUILDFLAG(IS_APPLE)
#include "base/apple/mach_port_rendezvous.h"
#endif
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_APPLE)
#include "base/files/platform_file.h"
#include "base/posix/global_descriptors.h"
#endif
namespace base {
class CommandLine;
struct LaunchOptions;
namespace shared_memory {
enum class SharedMemoryError {
kNoError,
kUnexpectedTokensCount,
kParseInt0Failed,
kParseInt4Failed,
kUnexpectedHandleType,
kInvalidHandle,
kGetFDFailed,
kDeserializeGUIDFailed,
kDeserializeFailed,
kCreateTrialsFailed,
kUnexpectedSize,
};
#if BUILDFLAG(IS_APPLE)
#if !BUILDFLAG(IS_IOS_TVOS)
using SharedMemoryMachPortRendezvousKey = MachPortsForRendezvous::key_type;
#else
using SharedMemoryMachPortRendezvousKey = uint32_t;
#endif
#endif
BASE_EXPORT void AddToLaunchParameters(
std::string_view switch_name,
const ReadOnlySharedMemoryRegion& read_only_memory_region,
#if BUILDFLAG(IS_APPLE)
SharedMemoryMachPortRendezvousKey rendezvous_key,
#elif BUILDFLAG(IS_POSIX)
GlobalDescriptors::Key descriptor_key,
ScopedFD& out_descriptor_to_share,
#endif
CommandLine* command_line,
LaunchOptions* launch_options);
BASE_EXPORT void AddToLaunchParameters(
std::string_view switch_name,
const UnsafeSharedMemoryRegion& unsafe_memory_region,
#if BUILDFLAG(IS_APPLE)
SharedMemoryMachPortRendezvousKey rendezvous_key,
#elif BUILDFLAG(IS_POSIX)
GlobalDescriptors::Key descriptor_key,
ScopedFD& out_descriptor_to_share,
#endif
CommandLine* command_line,
LaunchOptions* launch_options);
BASE_EXPORT expected<UnsafeSharedMemoryRegion, SharedMemoryError>
UnsafeSharedMemoryRegionFrom(std::string_view switch_value);
BASE_EXPORT expected<ReadOnlySharedMemoryRegion, SharedMemoryError>
ReadOnlySharedMemoryRegionFrom(std::string_view switch_value);
}
}
#endif