summaryrefslogtreecommitdiffstats
path: root/contrib/restricted/wavm/Include/WAVM/Platform/VectorOverMMap.h
blob: 7a43b502ac56471b3e8d7660e069c8c5fc10e780 (plain) (blame)
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
#include <sys/mman.h>
#include <cstddef>

namespace WAVM { namespace Runtime {

	class VectorOverMMap
	{
	public:
		VectorOverMMap();
		~VectorOverMMap();

		VectorOverMMap(const VectorOverMMap& other) = delete;
		VectorOverMMap& operator=(const VectorOverMMap& other) = delete;

		void grow(size_t morePages);

		static constexpr size_t getNumGuardBytes() { return guardPageCount * pageSize; }

		size_t getNumReservedBytes() const;

		void* getData() const;

	private:
		void resizeWithDoubling(size_t morePages);

		static void* allocateAndProtect(size_t committedPageCount, size_t capacityPageCount);

		static void checkForOOM(const char* message);

		static constexpr size_t pageSize = 65536;
		static constexpr size_t guardPageCount = 2;

		size_t committedPageCount = 0;
		size_t capacityPageCount = 0;
		void* data = nullptr;
	};

}}