Fork me on GitHub

root/kernel/syscalls/mprotect.c

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

DEFINITIONS

This source file includes following definitions.
  1. sys_mprotect

   1 /*
   2  * fiwix/kernel/syscalls/mprotect.c
   3  *
   4  * Copyright 2018, Jordi Sanfeliu. All rights reserved.
   5  * Distributed under the terms of the Fiwix License.
   6  */
   7 
   8 #include <fiwix/types.h>
   9 #include <fiwix/mman.h>
  10 #include <fiwix/mm.h>
  11 #include <fiwix/fcntl.h>
  12 #include <fiwix/errno.h>
  13 
  14 #ifdef __DEBUG__
  15 #include <fiwix/stdio.h>
  16 #include <fiwix/process.h>
  17 #endif /*__DEBUG__ */
  18 
  19 int sys_mprotect(unsigned int addr, __size_t length, int prot)
  20 {
  21         struct vma *vma;
  22 
  23 #ifdef __DEBUG__
  24         printk("(pid %d) sys_mprotect(0x%08x, %d, %d)\n", current->pid, addr, length, prot);
  25 #endif /*__DEBUG__ */
  26 
  27         if((addr & ~PAGE_MASK) || length < 0) {
  28                 return -EINVAL;
  29         }
  30         if(prot > (PROT_READ | PROT_WRITE | PROT_EXEC)) {
  31                 return -EINVAL;
  32         }
  33         if(!(vma = find_vma_region(addr))) {
  34                 return -ENOMEM;
  35         }
  36         length = PAGE_ALIGN(length);
  37         if((addr + length) > vma->end) {
  38                 return -ENOMEM;
  39         }
  40         if(vma->inode && (vma->flags & MAP_SHARED)) {
  41                 if(prot & PROT_WRITE) {
  42                         if(!(vma->o_mode & (O_WRONLY | O_RDWR))) {
  43                                 return -EACCES;
  44                         }
  45                 }
  46         }
  47 
  48         return do_mprotect(vma, addr, length, prot);
  49 }

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