Closed ghost closed 6 months ago
Doesn't Protection::from_bits_truncate cover your use case?
I realize the above won't work for the current release.
I had always intended for the protection flags to correspond to their UNIX constants, but I discovered today that that has not been the case. Although not problematic, since they've always been explicitly mapped to their native counterparts, it prevented from_bits_*
to works as expected. Fix pushed as 03fd93c.
the patch didn't fix the problem
load_phdrs_iter
.clone()
.filter(|ph| ph.p_memsz > 0)
.for_each(|ph| unsafe {
println!(
"{}, {}, {}",
ph.p_flags,
flags_to_prot(ph.p_flags),
Protection::from_bits_truncate(ph.p_flags.try_into().unwrap())
);
fn flags_to_prot(mut p_flags: u32) -> region::Protection {
[4, 2, 1].iter().fold(Protection::NONE, |mut acc, x| {
if p_flags >= *x {
match x {
4 => acc |= Protection::READ,
2 => acc |= Protection::WRITE,
1 => acc |= Protection::EXECUTE,
_ => acc |= Protection::NONE,
}
p_flags -= x;
}
acc
})
}
I need to protect the content of one segment in memory with its protection flags. So far I managed in this way
...
I was wondering why the library doesn't provide any method to turn u32 value into a region::Protection value