#include "io.hpp"

#include "internal/sys.hpp"

#include <fcntl.h>

#include <cstdint>
#include <cstring>
#include <string>

namespace host_tool
{

const std::string DevMemDevice::devMemPath = "/dev/mem";

bool DevMemDevice::read(const std::size_t offset, const std::size_t length,
                        void* const destination)
{
    devMemFd = sys->open(devMemPath.c_str(), O_RDONLY);
    if (devMemFd < 0)
    {
        return false;
    }

    /* Map based on aligned addresses - behind the scenes. */
    const std::size_t alignedDiff = offset % sys->getpagesize();
    const std::size_t alignedOffset = offset - alignedDiff;
    const std::size_t alignedSize = length + alignedDiff;

    // addr, length, prot, flags, fd, offset
    devMemMapped = sys->mmap(0, alignedSize, PROT_READ, MAP_SHARED, devMemFd,
                             alignedOffset);
    if (devMemMapped == MAP_FAILED)
    {
        std::fprintf(stderr, "Failed to mmap at offset: 0x%zx, length: %zu\n",
                     offset, length);
        sys->close(devMemFd);
        return false;
    }

    void* alignedSource =
        static_cast<std::uint8_t*>(devMemMapped) + alignedDiff;

    /* Copy the bytes. */
    std::memcpy(destination, alignedSource, length);

    /* Close the map between reads for now. */
    sys->munmap(devMemMapped, length);
    sys->close(devMemFd);

    return true;
}

bool DevMemDevice::write(const std::size_t offset, const std::size_t length,
                         const void* const source)
{
    devMemFd = sys->open(devMemPath.c_str(), O_RDWR);
    if (devMemFd < 0)
    {
        std::fprintf(stderr, "Failed to open /dev/mem for writing\n");
        return false;
    }

    /* Map based on aligned addresses - behind the scenes. */
    const std::size_t alignedDiff = offset % sys->getpagesize();
    const std::size_t alignedOffset = offset - alignedDiff;
    const std::size_t alignedSize = length + alignedDiff;

    // addr, length, prot, flags, fd, offset
    devMemMapped = sys->mmap(0, alignedSize, PROT_WRITE, MAP_SHARED, devMemFd,
                             alignedOffset);

    if (devMemMapped == MAP_FAILED)
    {
        std::fprintf(stderr, "Failed to mmap at offset: 0x%zx, length: %zu\n",
                     offset, length);
        sys->close(devMemFd);
        return false;
    }

    void* alignedDestination =
        static_cast<std::uint8_t*>(devMemMapped) + alignedDiff;

    /* Copy the bytes. */
    std::memcpy(alignedDestination, source, length);

    /* Close the map between writes for now. */
    sys->munmap(devMemMapped, length);
    sys->close(devMemFd);

    return true;
}

} // namespace host_tool
