ArchiSys/TP/TP2/rendu/vmap.h

54 lines
1.2 KiB
C
Raw Normal View History

2024-04-19 08:12:31 +02:00
#ifndef DEF_VMAP_H
#define DEF_VMAP_H
2024-04-19 09:57:02 +02:00
#include <pthread.h>
2024-04-19 08:12:31 +02:00
#include "mmap.h"
typedef struct VMap {
MMap* mmap;
linkedList* pages;
2024-04-19 09:57:02 +02:00
pthread_mutex_t lock;
int index; // size already alloc'ed
2024-04-19 08:12:31 +02:00
} VMap;
2024-04-19 09:06:05 +02:00
typedef struct Memory { // List of VMaps
struct Memory* next;
VMap* vmap;
int pid;
} Memory;
2024-04-19 08:12:31 +02:00
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;
2024-04-19 09:06:05 +02:00
/**
* If PID is (-1), a blank VMap is created and will be assigned to the 1st pid requesting it
*/
Memory* memory_init(int pid);
2024-04-19 08:12:31 +02:00
VMap* vmap_init();
/**
* Get page hosting a certain pointer
*/
PageMapInfo* vmap_get_page(VMap* vmap, void* ptr);
/**
* From implemented memory to real memory
*/
2024-04-19 09:06:05 +02:00
void vmap_copy_to_memory(Memory* mem, void *src, void *dst, int size, int pid);
2024-04-19 08:12:31 +02:00
/**
* From real memory to implemented memory
*/
2024-04-19 09:06:05 +02:00
void vmap_copy_from_memory(Memory* mem, void *src, void *dst, int size, int pid);
2024-04-19 08:12:31 +02:00
2024-04-19 09:06:05 +02:00
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);
2024-04-19 08:12:31 +02:00
#endif