Skip to content

Commit

Permalink
Merge pull request #3 from 915604903T/main
Browse files Browse the repository at this point in the history
  • Loading branch information
equation314 authored Aug 5, 2024
2 parents 91fcf12 + 867ddd4 commit 986e257
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
3 changes: 3 additions & 0 deletions page_table_entry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ repository.workspace = true
keywords.workspace = true
categories.workspace = true

[features]
arm-el2 = []

[dependencies]
bitflags = "2.6"
memory_addr = "0.2"
Expand Down
40 changes: 29 additions & 11 deletions page_table_entry/src/arch/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,22 @@ impl From<DescriptorAttr> for MappingFlags {
if !attr.contains(DescriptorAttr::AP_RO) {
flags |= Self::WRITE;
}
if attr.contains(DescriptorAttr::AP_EL0) {
flags |= Self::USER;
if !attr.contains(DescriptorAttr::UXN) {
#[cfg(not(feature = "arm-el2"))]
{
if attr.contains(DescriptorAttr::AP_EL0) {
flags |= Self::USER;
if !attr.contains(DescriptorAttr::UXN) {
flags |= Self::EXECUTE;
}
} else if !attr.intersects(DescriptorAttr::PXN) {
flags |= Self::EXECUTE;
}
}
#[cfg(feature = "arm-el2")]
{
if !attr.intersects(DescriptorAttr::UXN) {
flags |= Self::EXECUTE;
}
} else if !attr.intersects(DescriptorAttr::PXN) {
flags |= Self::EXECUTE;
}
match attr.mem_attr() {
Some(MemAttr::Device) => flags |= Self::DEVICE,
Expand Down Expand Up @@ -155,15 +164,24 @@ impl From<MappingFlags> for DescriptorAttr {
if !flags.contains(MappingFlags::WRITE) {
attr |= Self::AP_RO;
}
if flags.contains(MappingFlags::USER) {
attr |= Self::AP_EL0 | Self::PXN;
if !flags.contains(MappingFlags::EXECUTE) {
#[cfg(not(feature = "arm-el2"))]
{
if flags.contains(MappingFlags::USER) {
attr |= Self::AP_EL0 | Self::PXN;
if !flags.contains(MappingFlags::EXECUTE) {
attr |= Self::UXN;
}
} else {
attr |= Self::UXN;
if !flags.contains(MappingFlags::EXECUTE) {
attr |= Self::PXN;
}
}
} else {
attr |= Self::UXN;
}
#[cfg(feature = "arm-el2")]
{
if !flags.contains(MappingFlags::EXECUTE) {
attr |= Self::PXN;
attr |= Self::UXN;
}
}
attr
Expand Down

0 comments on commit 986e257

Please sign in to comment.