Fork me on GitHub

root/kernel/syscalls/old_mmap.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. old_mmap

   1 /*
   2  * fiwix/kernel/syscalls/old_mmap.c
   3  *
   4  * Copyright 2018-2022, Jordi Sanfeliu. All rights reserved.
   5  * Distributed under the terms of the Fiwix License.
   6  */
   7 
   8 #include <fiwix/fs.h>
   9 #include <fiwix/mman.h>
  10 #include <fiwix/mm.h>
  11 #include <fiwix/fcntl.h>
  12 #include <fiwix/errno.h>
  13 #include <fiwix/string.h>
  14 
  15 #ifdef __DEBUG__
  16 #include <fiwix/stdio.h>
  17 #include <fiwix/process.h>
  18 #endif /*__DEBUG__ */
  19 
  20 int old_mmap(struct mmap *mmap)
  21 {
  22         unsigned int page;
  23         struct inode *i;
  24         char flags;
  25         int errno;
  26 
  27 #ifdef __DEBUG__
  28         printk("(pid %d) old_mmap(0x%08x, %d, 0x%02x, 0x%02x, %d, 0x%08x) -> ", current->pid, mmap->start, mmap->length, mmap->prot, mmap->flags, mmap->fd, mmap->offset);
  29 #endif /*__DEBUG__ */
  30 
  31         if((errno = check_user_area(VERIFY_READ, mmap, sizeof(struct mmap)))) {
  32                 return errno;
  33         }
  34         if(!mmap->length) {
  35                 return -EINVAL;
  36         }
  37 
  38         i = NULL;
  39         flags = 0;
  40         if(!(mmap->flags & MAP_ANONYMOUS)) {
  41                 CHECK_UFD(mmap->fd);
  42                 if(!(i = fd_table[current->fd[mmap->fd]].inode)) {
  43                         return -EBADF;
  44                 }
  45                 flags = fd_table[current->fd[mmap->fd]].flags & O_ACCMODE;
  46         }
  47         page = do_mmap(i, mmap->start, mmap->length, mmap->prot, mmap->flags, mmap->offset, P_MMAP, flags, NULL);
  48 #ifdef __DEBUG__
  49         printk("0x%08x\n", page);
  50 #endif /*__DEBUG__ */
  51         return page;
  52 }

/* [previous][next][first][last][top][bottom][index][help] */