Refactor of scheduler's
This commit is contained in:
parent
84865e8248
commit
ab39b02bb9
|
@ -7,7 +7,7 @@ use {
|
||||||
arch::{init, sloop},
|
arch::{init, sloop},
|
||||||
boot_conf,
|
boot_conf,
|
||||||
boot_conf::BootConfig,
|
boot_conf::BootConfig,
|
||||||
capabilities::FileAccess,
|
capabilities,
|
||||||
experiments::{
|
experiments::{
|
||||||
info::master,
|
info::master,
|
||||||
systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
|
systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
|
||||||
|
@ -43,7 +43,7 @@ pub fn kernel_main() -> ! {
|
||||||
use Priority::*;
|
use Priority::*;
|
||||||
|
|
||||||
let mut process_1 = scheduler.new_process(High);
|
let mut process_1 = scheduler.new_process(High);
|
||||||
process_1.capabilities.files = FileAccess::Some(vec![PathRep {
|
process_1.capabilities.set_file_access(vec![PathRep {
|
||||||
location: FileLocations::Home,
|
location: FileLocations::Home,
|
||||||
file_name: "test".to_string(),
|
file_name: "test".to_string(),
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -1,72 +1,61 @@
|
||||||
|
use core::ops::BitOr;
|
||||||
|
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
|
|
||||||
use crate::file::PathRep;
|
use crate::file::PathRep;
|
||||||
|
|
||||||
|
// TODO: Get Able to document this
|
||||||
|
///
|
||||||
pub type SoundCardID = u8;
|
pub type SoundCardID = u8;
|
||||||
|
// TODO: Get Able to document this
|
||||||
|
///
|
||||||
pub type DeviceID = u8;
|
pub type DeviceID = u8;
|
||||||
|
// TODO: Get Able to document this
|
||||||
|
///
|
||||||
pub type ControllerID = u8;
|
pub type ControllerID = u8;
|
||||||
|
|
||||||
|
#[repr(u8)]
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum FileAccess {
|
/// Enum that specifies which abilities a program can have.
|
||||||
All,
|
pub enum Ability {
|
||||||
Some(Vec<PathRep>),
|
// TODO: Get Able to document this
|
||||||
None,
|
///
|
||||||
|
AllControllers = 0x01,
|
||||||
|
// TODO: Get Able to document this
|
||||||
|
///
|
||||||
|
AllFiles = 0x02,
|
||||||
|
// TODO: Get Able to document this
|
||||||
|
///
|
||||||
|
AllSoundCards = 0x04,
|
||||||
|
// TODO: Get Able to document this
|
||||||
|
///
|
||||||
|
Keyboard = 0x08,
|
||||||
|
// TODO: Get Able to document this
|
||||||
|
///
|
||||||
|
Mouse = 0x10,
|
||||||
|
// TODO: Get Able to document this
|
||||||
|
///
|
||||||
|
Telecomms = 0x20,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
pub enum ControllerAccess {
|
/// Wrapper for bit mask of Ability.
|
||||||
All,
|
pub struct Permissions(u8);
|
||||||
Some(Vec<ControllerID>),
|
|
||||||
None,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
/// The capabilities of a program. This must only be handled by kernel code.
|
||||||
pub enum SoundCardAccess {
|
/// Capabilities should never be set by user code, either directly or indirectly.
|
||||||
All,
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
Some(Vec<SoundCardID>),
|
|
||||||
None,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
|
||||||
pub enum MouseAccess {
|
|
||||||
Yes,
|
|
||||||
No,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
|
||||||
pub enum KeyboardAccess {
|
|
||||||
Yes,
|
|
||||||
No,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
|
||||||
pub enum NetworkAccess {
|
|
||||||
Yes,
|
|
||||||
No,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A set of capabilities that a process has
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
|
||||||
pub struct Capabilities {
|
pub struct Capabilities {
|
||||||
// TODO: Add more capabilities
|
perms: Permissions,
|
||||||
pub files: FileAccess,
|
files: Vec<PathRep>,
|
||||||
pub mouse: MouseAccess,
|
controllers: Vec<ControllerID>,
|
||||||
pub keyboard: KeyboardAccess,
|
soundcards: Vec<SoundCardID>,
|
||||||
pub controllers: ControllerAccess,
|
|
||||||
pub sound_cards: SoundCardAccess,
|
|
||||||
pub network_access: NetworkAccess,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Capabilities {
|
impl Capabilities {
|
||||||
/// Generate a set of empty capabilities
|
/// Generate a set of empty capabilities
|
||||||
pub fn empty() -> Self {
|
pub fn empty() -> Self {
|
||||||
Self {
|
Self::default()
|
||||||
files: FileAccess::None,
|
|
||||||
mouse: MouseAccess::No,
|
|
||||||
keyboard: KeyboardAccess::No,
|
|
||||||
controllers: ControllerAccess::None,
|
|
||||||
sound_cards: SoundCardAccess::None,
|
|
||||||
network_access: NetworkAccess::No,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generate a set of capabilities that allows all access
|
/// Generate a set of capabilities that allows all access
|
||||||
|
@ -77,12 +66,64 @@ impl Capabilities {
|
||||||
/// unless you know what you are doing
|
/// unless you know what you are doing
|
||||||
pub unsafe fn all() -> Self {
|
pub unsafe fn all() -> Self {
|
||||||
Self {
|
Self {
|
||||||
files: FileAccess::All,
|
perms: Permissions::all(),
|
||||||
mouse: MouseAccess::Yes,
|
..Default::default()
|
||||||
keyboard: KeyboardAccess::Yes,
|
|
||||||
controllers: ControllerAccess::All,
|
|
||||||
sound_cards: SoundCardAccess::All,
|
|
||||||
network_access: NetworkAccess::Yes,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// Checks if capabilities has this ability.
|
||||||
|
pub fn has_ability(&self, ability: Ability) -> bool {
|
||||||
|
self.perms.has_ability(ability)
|
||||||
|
}
|
||||||
|
/// Sets which individual files this capabilities grants access to.
|
||||||
|
pub fn set_file_access(&mut self, files: Vec<PathRep>) {
|
||||||
|
self.files = files;
|
||||||
|
}
|
||||||
|
/// Sets which individual controllers this capabilities grants access to.
|
||||||
|
pub fn set_controller_access(&mut self, controllers: Vec<ControllerID>) {
|
||||||
|
self.controllers = controllers;
|
||||||
|
}
|
||||||
|
/// Sets which individual soundcards this capabilities grants access to.
|
||||||
|
pub fn set_soundcard_access(&mut self, soundcards: Vec<SoundCardID>) {
|
||||||
|
self.soundcards = soundcards;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Ability {
|
||||||
|
/// Returns a bit mask with all abilities enabled.
|
||||||
|
pub fn all() -> u8 {
|
||||||
|
use Ability::*;
|
||||||
|
AllControllers | AllFiles | AllSoundCards | Keyboard | Mouse | Telecomms
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BitOr for Ability {
|
||||||
|
type Output = u8;
|
||||||
|
fn bitor(self, rhs: Self) -> u8 {
|
||||||
|
self as u8 | rhs as u8
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BitOr<u8> for Ability {
|
||||||
|
type Output = u8;
|
||||||
|
fn bitor(self, rhs: u8) -> u8 {
|
||||||
|
self as u8 | rhs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BitOr<Ability> for u8 {
|
||||||
|
type Output = u8;
|
||||||
|
fn bitor(self, rhs: Ability) -> u8 {
|
||||||
|
self | rhs as u8
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Permissions {
|
||||||
|
/// Returns self with all abilities enabled.
|
||||||
|
pub fn all() -> Self {
|
||||||
|
Self(Ability::all())
|
||||||
|
}
|
||||||
|
/// Checks if permissions has ability.
|
||||||
|
pub fn has_ability(&self, ability: Ability) -> bool {
|
||||||
|
self.0 & ability.clone() as u8 == ability as u8
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -19,7 +19,7 @@ mod tests;
|
||||||
|
|
||||||
use crate::file::PathRep;
|
use crate::file::PathRep;
|
||||||
|
|
||||||
use self::capabilities::Capabilities;
|
use capabilities::Capabilities;
|
||||||
|
|
||||||
lazy_static::lazy_static!(
|
lazy_static::lazy_static!(
|
||||||
/// The standard implementation for ableOS
|
/// The standard implementation for ableOS
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use crate::scheduler::{
|
use crate::{scheduler::{proc::PID, Priority::*, Scheduler}, capabilities::Ability};
|
||||||
capabilities::{ControllerAccess, FileAccess, KeyboardAccess, MouseAccess, SoundCardAccess},
|
|
||||||
proc::PID,
|
|
||||||
Priority::*,
|
|
||||||
Scheduler,
|
|
||||||
};
|
|
||||||
|
|
||||||
// #[test]
|
// #[test]
|
||||||
fn test_new_process() {
|
fn test_new_process() {
|
||||||
|
@ -41,9 +36,10 @@ fn test_bump_exec() {
|
||||||
// #[test]
|
// #[test]
|
||||||
fn test_capabilities() {
|
fn test_capabilities() {
|
||||||
let caps = Capabilities::empty();
|
let caps = Capabilities::empty();
|
||||||
assert_eq!(caps.files, FileAccess::None);
|
assert!(!caps.has_ability(Ability::AllControllers));
|
||||||
assert_eq!(caps.mouse, MouseAccess::No);
|
assert!(!caps.has_ability(Ability::AllFiles));
|
||||||
assert_eq!(caps.keyboard, KeyboardAccess::No);
|
assert!(!caps.has_ability(Ability::AllSoundCards));
|
||||||
assert_eq!(caps.controllers, ControllerAccess::None);
|
assert!(!caps.has_ability(Ability::Keyboard));
|
||||||
assert_eq!(caps.sound_cards, SoundCardAccess::None);
|
assert!(!caps.has_ability(Ability::Mouse));
|
||||||
|
assert!(!caps.has_ability(Ability::Telecomms));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue