From df63859b9fc18affff236079bb055a3497e3e864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20Ch=C3=A9ramy?= Date: Sat, 24 Jan 2015 13:18:25 +0100 Subject: [PATCH] =?UTF-8?q?D=C3=A9but=20gestion=20mmap=20fichier=20(non=20?= =?UTF-8?q?fonctionnel).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/test.c | 5 +++++ kernel/mmap.c | 30 +++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/applications/test.c b/applications/test.c index 2fbafbe1..a8403b56 100644 --- a/applications/test.c +++ b/applications/test.c @@ -29,6 +29,7 @@ #include #include #include +#include int main() { @@ -40,5 +41,9 @@ int main() t2[20000] = 42; printf("%u %d\n", t2, t2[20000]); + int fd = open("/tacos/README", O_RDONLY); + char* t3 = mmap(NULL, 100, PROT_READ, MAP_PRIVATE | MAP_FILE, fd, 0); + printf("%u %c\n", t3, t3[0]); + return 0; } diff --git a/kernel/mmap.c b/kernel/mmap.c index ef8a8d18..4f51af0f 100644 --- a/kernel/mmap.c +++ b/kernel/mmap.c @@ -30,7 +30,7 @@ static void add_region(process_t *process, vaddr_t addr, struct mmap_data *data) struct mmap_region* aux = process->list_regions; struct mmap_region* prec = NULL; - while (aux && aux->addr < cell->addr) { + while (aux && aux->addr > cell->addr) { prec = aux; aux = aux->next; } @@ -55,15 +55,31 @@ void print_regions(process_t *process) { int is_mmaped(vaddr_t addr) { process_t *process = get_current_process(); struct mmap_region* aux = process->list_regions; - while (aux && aux->addr <= addr) { + while (aux && aux->addr > addr) { + aux = aux->next; + } + + if (aux) { if (aux->addr + aux->length > addr) { - int page_addr = addr & ~(PAGE_SIZE - 1); - // mmap anonyme pour le moment : + vaddr_t page_addr = addr & ~(PAGE_SIZE - 1); + map(memory_reserve_page_frame(), page_addr, 1, (aux->prot & PROT_WRITE) > 0); - memset((void*)page_addr, 0, PAGE_SIZE); - return 1; + if (aux->flags & MAP_ANONYMOUS) { + memset((void*)page_addr, 0, PAGE_SIZE); + return 1; + } else if(aux->fd > -1) { + open_file_descriptor* ofd = process->fd[aux->fd]; + if (ofd) { + // FIXME: l'offset n'est pas correct. + ofd->f_ops->seek(ofd, aux->offset, SEEK_SET); + // FIXME: ne peut pas lire depuis une exception... + ofd->f_ops->read(ofd, (void*) page_addr, PAGE_SIZE); + return 1; + } else { + return 0; + } + } } - aux = aux->next; } return 0;