From 619a33cc77f508b75e713bd4e12e58c16ca1267b Mon Sep 17 00:00:00 2001 From: edef Date: Sun, 31 Jul 2022 20:17:19 +0000 Subject: ripple/minitrace/maps_file: represent protection bits with ProtFlags Change-Id: Ia9dbddcd13da3fcb0c0ef30082d6f6750e4014da --- ripple/minitrace/src/maps_file.rs | 40 ++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'ripple/minitrace') diff --git a/ripple/minitrace/src/maps_file.rs b/ripple/minitrace/src/maps_file.rs index 7a48147..86e118a 100644 --- a/ripple/minitrace/src/maps_file.rs +++ b/ripple/minitrace/src/maps_file.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: OSL-3.0 use { - crate::syscall_abi::Device, + crate::syscall_abi::{Device, ProtFlags}, anyhow::bail, nom::{ branch::alt, @@ -107,14 +107,26 @@ fn mapping(input: &str) -> IResult<&str, Mapping> { _ => unreachable!(), }; + let mut prot = ProtFlags::empty(); + + if perm_read { + prot |= ProtFlags::READ; + } + + if perm_write { + prot |= ProtFlags::WRITE; + } + + if perm_exec { + prot |= ProtFlags::EXEC; + } + Ok(( input, Mapping { start, end, - perm_read, - perm_write, - perm_exec, + prot, shared, offset, inode, @@ -135,9 +147,7 @@ pub(crate) fn parse_mapping_line(line: &str) -> anyhow::Result { pub(crate) struct Mapping { pub(crate) start: u64, pub(crate) end: u64, - pub(crate) perm_read: bool, - pub(crate) perm_write: bool, - pub(crate) perm_exec: bool, + pub(crate) prot: ProtFlags, pub(crate) shared: bool, pub(crate) offset: u64, pub(crate) inode: Option, @@ -157,9 +167,7 @@ impl Debug for Mapping { let Mapping { start, end, - perm_read, - perm_write, - perm_exec, + prot, shared, offset, inode, @@ -172,8 +180,12 @@ impl Debug for Mapping { write!(f, "{start:016x}-{end:016x} ")?; - for (c, p) in [('r', perm_read), ('w', perm_write), ('x', perm_exec)] { - f.write_char(if p { c } else { '-' })?; + for (c, p) in [ + ('r', ProtFlags::READ), + ('w', ProtFlags::WRITE), + ('x', ProtFlags::EXEC), + ] { + f.write_char(if prot.contains(p) { c } else { '-' })?; } f.write_char(if shared { 's' } else { 'p' })?; f.write_char(' ')?; @@ -193,9 +205,7 @@ fn golden_mapping() { let golden = Mapping { start: 0x00400000, end: 0x00407000, - perm_read: true, - perm_write: false, - perm_exec: false, + prot: ProtFlags::READ, shared: false, offset: 0, inode: Some(Inode { -- cgit 1.4.1