Skip to content

Commit

Permalink
Début gestion mmap fichier (non fonctionnel).
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximeCheramy committed Jan 24, 2015
1 parent 34b6756 commit df63859
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
5 changes: 5 additions & 0 deletions applications/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <stdio.h>
#include <signal.h>
#include <sys/mman.h>
#include <fcntl.h>

int main()
{
Expand All @@ -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;
}
30 changes: 23 additions & 7 deletions kernel/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down

0 comments on commit df63859

Please sign in to comment.