Sergej Schumilo cd702b528c Initial Release of Nyx
Co-authored-by: Cornelius Aschermann <cornelius@hexgolems.com>
2021-11-14 22:20:53 +01:00

73 lines
1.8 KiB
C

#pragma once
#include <stdint.h>
#include <sys/types.h>
#include "nyx/khash.h"
#include "qemu/osdep.h"
#include "block/block.h"
#include "nyx/redqueen_trace.h"
//#define DEBUG_COW_LAYER
/* 2GB Cache */
//#define COW_CACHE_SIZE 0x80000000
// 3GB
#define COW_CACHE_SIZE 0xC0000000
// 512MB
//#define COW_CACHE_SECONDARY_SIZE 0x20000000
#define COW_CACHE_SECONDARY_SIZE 0xC0000000
KHASH_MAP_INIT_INT64(COW_CACHE, uint64_t)
typedef struct cow_cache_s{
khash_t(COW_CACHE) *lookup_primary;
khash_t(COW_CACHE) *lookup_secondary;
khash_t(COW_CACHE) *lookup_secondary_tmp;
void* data_primary;
void* data_secondary;
void* data_secondary_tmp;
char* filename;
uint64_t offset_primary;
uint64_t offset_secondary;
uint64_t offset_secondary_tmp;
bool enabled;
bool enabled_fuzz;
bool enabled_fuzz_tmp;
#ifdef DEBUG_COW_LAYER
uint64_t read_calls;
uint64_t write_calls;
uint64_t read_calls_tmp;
uint64_t write_calls_tmp;
#endif
} cow_cache_t;
cow_cache_t* cow_cache_new(const char* filename);
void cow_cache_reset(cow_cache_t* self);
//int coroutine_fn cow_cache_read(cow_cache_t* self, BlockBackend *blk, int64_t offset, unsigned int bytes, QEMUIOVector *qiov, BdrvRequestFlags flags);
//int coroutine_fn cow_cache_write(cow_cache_t* self, BlockBackend *blk, int64_t offset, unsigned int bytes, QEMUIOVector *qiov, BdrvRequestFlags flags);
void switch_to_fuzz_mode(cow_cache_t* self);
void read_primary_buffer(cow_cache_t* self, const char* filename_prefix, bool switch_mode);
void dump_primary_buffer(cow_cache_t* self, const char* filename_prefix);
void cow_cache_read_entry(void* opaque);
void cow_cache_write_entry(void* opaque);
void cow_cache_enable(cow_cache_t* self);
void cow_cache_disable(cow_cache_t* self);
void cow_cache_enable_tmp_mode(cow_cache_t* self);
void cow_cache_disable_tmp_mode(cow_cache_t* self);