summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/NewKit/PageMgr.h
blob: bc8ee7765bc839faba34caff657be59149b348bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// a way to create and find our pages.
// I'm thinking about a separate way of getting a paged area.

/* -------------------------------------------

	Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.

------------------------------------------- */

#pragma once

#include <NewKit/Defines.h>
#include <NewKit/Ref.h>

namespace Kernel
{
	class PageMgr;

	class PTEWrapper final
	{
	public:
		explicit PTEWrapper(Boolean Rw = false, Boolean User = false, Boolean ExecDisable = false, UIntPtr Address = 0);

		~PTEWrapper();

		PTEWrapper& operator=(const PTEWrapper&) = default;
		PTEWrapper(const PTEWrapper&)			 = default;

	public:
		UIntPtr VirtualAddress();

		Void NoExecute(const bool enable = false);
		Bool NoExecute();

		operator bool()
		{
			return fVirtAddr;
		}

		bool Reclaim();
		bool Shareable();
		bool Present();
		bool Access();

	private:
		Boolean fRw;
		Boolean fUser;
		Boolean fExecDisable;
		UIntPtr fVirtAddr;
		Boolean fCache;
		Boolean fShareable;
		Boolean fWt;
		Boolean fPresent;
		Boolean fAccessed;

	private:
		friend class PageMgr;
		friend class Pmm;
	};

	struct PageMgr final
	{
	public:
		PageMgr()  = default;
		~PageMgr() = default;

		PageMgr& operator=(const PageMgr&) = default;
		PageMgr(const PageMgr&)			   = default;

	public:
		PTEWrapper Request(Boolean Rw, Boolean User, Boolean ExecDisable, SizeT Sz, SizeT Pad);
		bool	   Free(Ref<PTEWrapper>& wrapper);

	private:
		void FlushTLB();

	private:
		friend PTEWrapper;
		friend class Pmm;
	};
} // namespace Kernel