mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-27 11:23:25 +00:00
Refactor project structure
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
bd878dd1c9
commit
e3c227ae06
81
kernel/aster-nix/src/vm/perms.rs
Normal file
81
kernel/aster-nix/src/vm/perms.rs
Normal file
@ -0,0 +1,81 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use aster_frame::vm::VmPerm;
|
||||
use aster_rights::Rights;
|
||||
use bitflags::bitflags;
|
||||
|
||||
bitflags! {
|
||||
/// The memory access permissions of memory mappings.
|
||||
pub struct VmPerms: u32 {
|
||||
/// Readable.
|
||||
const READ = 1 << 0;
|
||||
/// Writable.
|
||||
const WRITE = 1 << 1;
|
||||
/// Executable.
|
||||
const EXEC = 1 << 2;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Rights> for VmPerms {
|
||||
fn from(rights: Rights) -> VmPerms {
|
||||
let mut vm_perm = VmPerms::empty();
|
||||
if rights.contains(Rights::READ) {
|
||||
vm_perm |= VmPerms::READ;
|
||||
}
|
||||
if rights.contains(Rights::WRITE) {
|
||||
vm_perm |= VmPerms::WRITE;
|
||||
}
|
||||
if rights.contains(Rights::EXEC) {
|
||||
vm_perm |= VmPerms::EXEC;
|
||||
}
|
||||
vm_perm
|
||||
}
|
||||
}
|
||||
|
||||
impl From<VmPerms> for Rights {
|
||||
fn from(vm_perms: VmPerms) -> Rights {
|
||||
let mut rights = Rights::empty();
|
||||
if vm_perms.contains(VmPerms::READ) {
|
||||
rights |= Rights::READ;
|
||||
}
|
||||
if vm_perms.contains(VmPerms::WRITE) {
|
||||
rights |= Rights::WRITE;
|
||||
}
|
||||
if vm_perms.contains(VmPerms::EXEC) {
|
||||
rights |= Rights::EXEC;
|
||||
}
|
||||
rights
|
||||
}
|
||||
}
|
||||
|
||||
impl From<VmPerm> for VmPerms {
|
||||
fn from(perm: VmPerm) -> Self {
|
||||
let mut perms = VmPerms::empty();
|
||||
if perm.contains(VmPerm::R) {
|
||||
perms |= VmPerms::READ;
|
||||
}
|
||||
if perm.contains(VmPerm::W) {
|
||||
perms |= VmPerms::WRITE;
|
||||
}
|
||||
if perm.contains(VmPerm::X) {
|
||||
perms |= VmPerms::EXEC;
|
||||
}
|
||||
perms
|
||||
}
|
||||
}
|
||||
|
||||
impl From<VmPerms> for VmPerm {
|
||||
fn from(perms: VmPerms) -> Self {
|
||||
let mut perm = VmPerm::empty();
|
||||
if perms.contains(VmPerms::READ) {
|
||||
perm |= VmPerm::R;
|
||||
}
|
||||
if perms.contains(VmPerms::WRITE) {
|
||||
perm |= VmPerm::W;
|
||||
}
|
||||
if perms.contains(VmPerms::EXEC) {
|
||||
perm |= VmPerm::X;
|
||||
}
|
||||
perm
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user