#ifndef EPT_FAULT_H
#define EPT_FAULT_H

#define PAGE_SIZE 4096
#define MAX_GUEST_PAGES 1572864ULL
#define MAX_GUEST_MEM PAGE_SIZE*MAX_GUEST_PAGES
#define PTES_PER_TABLE 512
#define PFN_CACHE_SIZE (4*1024) //(128) // (2048*1024)
#define PFN_CACHE_MAP_SIZE (PFN_CACHE_SIZE*2)
#define MAX_MEMSLOTS 128
// #define DEF_EPTE_FLAGS 0x600000000000B77ULL
#define RW_EPTE_FLAGS 0x600000000000B77ULL
#define RO_EPTE_FLAGS 0x600000000000B75ULL
#define RW_PTE_FLAGS 0x8000000000000867
#define RO_PTE_FLAGS 0x8000000000000025 // SW_3 off, dirty off, writable off
#define N_BLANKS 1000
// #define MAX_ALLOCS 0x2a4cULL
#define MAX_ALLOCS 0x1000000ULL
#define REMAP_HISTORY_LEN 4
#define MAPPING_TABLE_SIZE MAX_GUEST_PAGES
#define MAPPING_HISTORY_TABLE_SIZE (MAPPING_TABLE_SIZE*REMAP_HISTORY_LEN)
#define MAX_HOST_PAGES ((32*1024*1024*1024ULL)/4096)
#define KVM_MEM_READONLY	(1UL << 1)
#define NO_MAP_MAP_SIZE 1024
#define REMAP_RING_SIZE 2048
#define GET_PAGE_ADDR(x) (x & 0xFFFFFFFFFFFF000ULL)
#define PTE_PRESENT_BIT (1ULL << 0)

enum counter_type {
    BYPASS_ALLOCS_INDEX = 0,
    BYPASS_ALLOC_ATTEMPS,
    BYPASS_ALLOC_SUCCESS,
    BYPASS_REMAP_SUCCESS,
    BYPASS_ALLOC_FAILED_CACHE_EMPTY,
    BYPASS_ALLOC_FAILED_CACHE_DIRTY_FULL,
    BYPASS_ALLOC_FAILED_NO_MEMSLOT,
    BYPASS_ALLOC_FAILED_CANT_REMAP_FAULT_READ,
    BYPASS_ALLOC_FAILED_CANT_REMAP_GUEST_FLAGS,
    BYPASS_ALLOC_FAILED_CANT_REMAP_NO_MAP_LIST,
    BYPASS_ALLOC_FAILED_REACHED_MAX_ALLOCS,
    BYPASS_ALLOC_FAILED_HYPERUPCALL_BUSY,
    REMAP_UPDATE_SUCCESS0,
    REMAP_UPDATE_SUCCESS1,
    REMAP_UPDATE_SUCCESS2,
    REMAP_UPDATE_SUCCESS3,
    REMAP_UPDATE_SUCCESS4,
    NO_MAP_HEAD,
    NO_MAP_TAIL,
    REMAP_MAP_HEAD,
    REMAP_MAP_TAIL,
    BYPASS_ALLOC_ENABLE,
    QEMU_CR3,
    PFN_CACHE_SIZE_KEY,
    LOCK_FLAG1, // the hyperupcall's flag
    LOCK_FLAG2,
    LOCK_TURN,
    N_COUNTERS
};

enum remap_retval {
    REMAP_SUCCESS = 0,
    REMAP_FAIL,
    REMAP_EXIT
};

#endif // EPT_FAULT_H