ladybird/Libraries/LibCore/SharedVersion.h
Timothy Flynn 4ad9543a65 LibCore: Add helpers to share arbitrary versions between processes
This will allow sharing e.g. document cookie versions between the UI and
WebContent processes, and safely accessing those versions.

Core::AnonymousBuffer internally creates a minimum buffer of PAGE_SIZE
bytes. This is much more than the size of a single version, but this
affords us the opportunity to share multiple versions in a single buffer
between processes. With a PAGE_SIZE of 4096, we can share up to 512
versions in a single buffer.
2026-02-05 07:28:07 -05:00

26 lines
712 B
C++

/*
* Copyright (c) 2026, Tim Flynn <trflynn89@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Optional.h>
#include <AK/Types.h>
#include <LibCore/AnonymousBuffer.h>
namespace Core {
using SharedVersion = u64;
using SharedVersionIndex = u32;
constexpr inline SharedVersion INVALID_SHARED_VERSION = 0;
constexpr inline SharedVersion INITIAL_SHARED_VERSION = 1;
[[nodiscard]] AnonymousBuffer create_shared_version_buffer();
[[nodiscard]] bool initialize_shared_version(AnonymousBuffer&, SharedVersionIndex);
void increment_shared_version(AnonymousBuffer&, SharedVersionIndex);
Optional<SharedVersion> get_shared_version(AnonymousBuffer const&, SharedVersionIndex);
}