Fork me on GitHub

root/kernel/syscalls/ioperm.c

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

DEFINITIONS

This source file includes following definitions.
  1. sys_ioperm

   1 /*
   2  * fiwix/kernel/syscalls/ioperm.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/process.h>
   9 #include <fiwix/errno.h>
  10 
  11 #ifdef __DEBUG__
  12 #include <fiwix/stdio.h>
  13 #endif /*__DEBUG__ */
  14 
  15 /*
  16  * This sys_ioperm() implementation, unlike what Linux 2.0 API said, covers all
  17  * the I/O address space. That is, up to 65536 I/O ports can be specified using
  18  * this system call, which makes sys_iopl() not needed anymore.
  19  */
  20 int sys_ioperm(unsigned long int from, unsigned long int num, int turn_on)
  21 {
  22         unsigned int n;
  23 
  24 #ifdef __DEBUG__
  25         printk("(pid %d) sys_ioperm(0x%08x, 0x%08x, 0x%08x)\n", current->pid, from, num, turn_on);
  26 #endif /*__DEBUG__ */
  27 
  28         if(!IS_SUPERUSER) {
  29                 return -EPERM;
  30         }
  31         if(from + num >= (IO_BITMAP_SIZE * 8)) {
  32                 return -EINVAL;
  33         }
  34 
  35         /*
  36          * The Linux 2.0 API states that if 'turn_on' is non-zero the access to
  37          * port must be guaranteed, otherwise the access must be denied.
  38          *
  39          * The Intel specification works in the opposite way. That is, if bit
  40          * is zero the access to port is guaranteed, otherwise is not.
  41          *
  42          * That's the reason why we need to negate the value of 'turn_on' before
  43          * changing the I/O permission bitmap.
  44          */
  45         turn_on = !turn_on;
  46 
  47         for(n = from; n < (from + num); n++) {
  48                 if(!turn_on) {
  49                         current->tss.io_bitmap[n / 8] &= ~(1 << (n % 8));
  50                 } else {
  51                         current->tss.io_bitmap[n / 8] |= ~(1 << (n % 8));
  52                 }
  53         }
  54 
  55         return 0;
  56 }

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