ArchiSys/TP/TP2/rendu/vmap.h
2024-04-19 09:57:02 +02:00

54 lines
1.2 KiB
C

#ifndef DEF_VMAP_H
#define DEF_VMAP_H
#include <pthread.h>
#include "mmap.h"
typedef struct VMap {
MMap* mmap;
linkedList* pages;
pthread_mutex_t lock;
int index; // size already alloc'ed
} VMap;
typedef struct Memory { // List of VMaps
struct Memory* next;
VMap* vmap;
int pid;
} Memory;
typedef struct PageMapInfo {
int start;
int key; // key for mmap
int cursor; // Last allocation end
int nb_allocs; // Free page if 0
bool swapped;
} PageMapInfo;
/**
* If PID is (-1), a blank VMap is created and will be assigned to the 1st pid requesting it
*/
Memory* memory_init(int pid);
VMap* vmap_init();
/**
* Get page hosting a certain pointer
*/
PageMapInfo* vmap_get_page(VMap* vmap, void* ptr);
/**
* From implemented memory to real memory
*/
void vmap_copy_to_memory(Memory* mem, void *src, void *dst, int size, int pid);
/**
* From real memory to implemented memory
*/
void vmap_copy_from_memory(Memory* mem, void *src, void *dst, int size, int pid);
void* my_malloc(Memory* mem, int size, int pid);
void my_free(Memory* mem, void* ptr, int pid);
void my_copy(Memory* mem, void* src, void* dst, int size, int pid);
#endif