/**
 * @file SharedMemory.h
 * @author apio (cloudapio.eu)
 * @brief Create and map areas of memory shared between processes.
 *
 * @copyright Copyright (c) 2023, the Luna authors.
 *
 */

#include <luna/Result.h>
#include <luna/StringView.h>

namespace os
{
    namespace SharedMemory
    {
        /**
         * @brief Create a new shared memory region and map it.
         *
         * @param path The shared memory path to use. It must be of the same format as shm_open().
         * @param size The amount of bytes to use for the shared memory region.
         * @return Result<u8*> An error, or a pointer to the shared memory region.
         */
        Result<u8*> create(StringView path, usize size);

        /**
         * @brief Map an existing shared memory region, possibly created by another process.
         *
         * @param path The shared memory path to use. It must be of the same format as shm_open().
         * @param size The amount of bytes to map from the shared memory region.
         * @param delete_fs Whether to delete the region from the file system so no other processes can open it.
         * @return Result<u8*> An error, or a pointer to the shared memory region.
         */
        Result<u8*> adopt(StringView path, usize size, bool delete_fs = true);
    };
}