1
0
mirror of https://github.com/sgmarz/osblog.git synced 2024-11-24 02:16:19 +04:00

Check and use permission bits in ELF for user pages.

This commit is contained in:
Stephen Marz 2020-04-26 08:40:43 -04:00
parent fa1a728bd9
commit 42c14bf930
2 changed files with 16 additions and 4 deletions

View File

@ -47,9 +47,9 @@ pub struct ProgramHeader {
pub const TYPE_EXEC: u16 = 2;
pub const PROG_READ: u8 = 4;
pub const PROG_WRITE: u8 = 2;
pub const PROG_EXECUTE: u8 = 1;
pub const PROG_READ: u32 = 4;
pub const PROG_WRITE: u32 = 2;
pub const PROG_EXECUTE: u32 = 1;
pub const MACHINE_RISCV: u16 = 0xf3;
pub const PH_SEG_TYPE_NULL: u32 = 0;

View File

@ -222,6 +222,18 @@ pub fn test_elf() {
}
memcpy(ptr.add(ph.off), buffer.get().add(ph.off), ph.memsz);
let pages = ph.memsz / PAGE_SIZE + 1;
let mut bits = EntryBits::User.val();
// This sucks, but we check each bit in the flags to see if
// we need to add it to the PH permissions.
if ph.flags & elf::PROG_EXECUTE != 0 {
bits |= EntryBits::Execute.val();
}
if ph.flags & elf::PROG_READ != 0 {
bits |= EntryBits::Read.val();
}
if ph.flags & elf::PROG_WRITE != 0 {
bits |= EntryBits::Write.val();
}
for i in 0..pages {
let vaddr = ph.vaddr + i * PAGE_SIZE;
let paddr = ptr as usize + i * PAGE_SIZE;
@ -229,7 +241,7 @@ pub fn test_elf() {
table,
vaddr,
paddr,
EntryBits::UserReadExecute.val(),
bits,
0,
);
}