<commit_before>#ifndef PITH_PAGE_HPP_
#define PITH_PAGE_HPP_

#include <Pith/Config.hpp>
#include <Pith/Address.hpp>
#include <Pith/ArrayBox.hpp>
#include <Pith/Bytes.hpp>
#include <Pith/Result.hpp>
#include <Pith/Span.hpp>
#include <errno.h>
#include <sys/mman.h>

namespace Pith {

namespace {

const constexpr std::size_t PAGE_SIZE = kibibytes(4);
const constexpr std::size_t PAGE_ALIGNMENT = PAGE_SIZE;

}  // namespace

class alignas(PAGE_ALIGNMENT) Page {
public:
	struct Permission {
		static const constexpr int EXECUTE = PROT_EXEC;
		static const constexpr int WRITE = PROT_WRITE;
		static const constexpr int READ = PROT_READ;
		static const constexpr int NONE = PROT_NONE;
	};

	using Permissions = Permission;

	/// Will bring a page into memory, with no permissions.
	static inline auto map(const Span<Page>& pages, int permissions = Page::Permissions::NONE)
		-> Result<Page*, int> {
		Page* p = (Page*)mmap(
			pages.value(), pages.size(), permissions, MAP_ANON | MAP_PRIVATE, 0, 0);

		if (p != nullptr) {
			return ok(p);
		} else {
			return err(errno);  // TODO: Return errno
		}
	}

	/// Unmap a page from memory.
	/// Returns 0 on success.
	static inline auto unmap(const Span<Page>& pages) -> int {
		int e = munmap(pages.value(), pages.size());
		if (e == 0) {
			return 0;
		} else {
			return errno;
		}
	}

	static inline auto setPermissions(const Span<Page>& pages, int permissions) -> int {
		return mprotect(pages.value(), pages.size(), permissions);
	}

	inline constexpr auto bytes() const -> const ByteArrayBox<PAGE_SIZE>& {
		return bytes_;
	}

	inline auto bytes() -> const ByteArrayBox<PAGE_SIZE>& {
		return bytes_;
	}

private:
	ByteArrayBox<PAGE_SIZE> bytes_;
};

static_assert(sizeof(Page) == PAGE_SIZE, "Page size must be correct.");
static_assert(alignof(Page) == PAGE_ALIGNMENT, "Page allignment must be correct.");

}  // namespace Pith<commit_msg>Don't align Page to Pagesize<commit_after>#ifndef PITH_PAGE_HPP_
#define PITH_PAGE_HPP_

#include <Pith/Config.hpp>
#include <Pith/Address.hpp>
#include <Pith/ArrayBox.hpp>
#include <Pith/Bytes.hpp>
#include <Pith/Result.hpp>
#include <Pith/Span.hpp>
#include <errno.h>
#include <sys/mman.h>

namespace Pith {

namespace {

const constexpr std::size_t PAGE_SIZE = kibibytes(4);
const constexpr std::size_t PAGE_ALIGNMENT = PAGE_SIZE;

}  // namespace

class Page {
public:
	struct Permission {
		static const constexpr int EXECUTE = PROT_EXEC;
		static const constexpr int WRITE = PROT_WRITE;
		static const constexpr int READ = PROT_READ;
		static const constexpr int NONE = PROT_NONE;
	};

	using Permissions = Permission;

	/// Will bring a page into memory, with no permissions.
	static inline auto map(const Span<Page>& pages, int permissions = Page::Permissions::NONE)
		-> Result<Page*, int> {
		Page* p = (Page*)mmap(
			pages.value(), pages.size(), permissions, MAP_ANON | MAP_PRIVATE, 0, 0);

		if (p != nullptr) {
			return ok(p);
		} else {
			return err(errno);  // TODO: Return errno
		}
	}

	/// Unmap a page from memory.
	/// Returns 0 on success.
	static inline auto unmap(const Span<Page>& pages) -> int {
		int e = munmap(pages.value(), pages.size());
		if (e == 0) {
			return 0;
		} else {
			return errno;
		}
	}

	static inline auto setPermissions(const Span<Page>& pages, int permissions) -> int {
		return mprotect(pages.value(), pages.size(), permissions);
	}

	inline constexpr auto bytes() const -> const ByteArrayBox<PAGE_SIZE>& {
		return bytes_;
	}

	inline auto bytes() -> const ByteArrayBox<PAGE_SIZE>& {
		return bytes_;
	}

private:
	ByteArrayBox<PAGE_SIZE> bytes_;
};

static_assert(sizeof(Page) == PAGE_SIZE, "Page size must be correct.");

}  // namespace Pith
{'fraction_non_alphanumeric': 0.1306587150989428, 'fraction_numerical': 0.003252914068853348, 'mean_word_length': 4.1037344398340245, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2820753', 'n_tokens_mistral': 1341, 'n_tokens_neox': 1240, 'n_words': 363}