-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for QNX Neutrino #507
base: master
Are you sure you want to change the base?
Conversation
…he automated build system is unhappy about naming conventions on 1.42.0
9839937
to
75e65e7
Compare
…gjubilee Add support for QNX Neutrino to standard library This change: - adds standard library support for QNX Neutrino (7.1). - upgrades `libc` to version `0.2.139` which supports QNX Neutrino `@gh-tr`⚠️ Backtraces on QNX require rust-lang/backtrace-rs#507 which is not yet merged! (But everything else works without these changes)⚠️ Tested mainly with a x86_64 virtual machine (see qnx-nto.md) and partially with an aarch64 hardware (some tests fail due to constrained resources).
Add support for QNX Neutrino to standard library This change: - adds standard library support for QNX Neutrino (7.1). - upgrades `libc` to version `0.2.139` which supports QNX Neutrino `@gh-tr`⚠️ Backtraces on QNX require rust-lang/backtrace-rs#507 which is not yet merged! (But everything else works without these changes)⚠️ Tested mainly with a x86_64 virtual machine (see qnx-nto.md) and partially with an aarch64 hardware (some tests fail due to constrained resources).
Add support for QNX Neutrino to standard library This change: - adds standard library support for QNX Neutrino (7.1). - upgrades `libc` to version `0.2.139` which supports QNX Neutrino `@gh-tr`⚠️ Backtraces on QNX require rust-lang/backtrace-rs#507 which is not yet merged! (But everything else works without these changes)⚠️ Tested mainly with a x86_64 virtual machine (see qnx-nto.md) and partially with an aarch64 hardware (some tests fail due to constrained resources).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had half-expected someone else with a bit more experience to come by and review this, so I kept my earlier comments minimal, but it looks like I probably now know the most about QNX Neutrino amongst the libs reviewers, so I might as well sit down with this. Sorry about the holdup.
fn concat_str(a: &str, b: &str) -> String { | ||
let mut e = String::from(a); | ||
e += b; | ||
e | ||
} | ||
|
||
fn read_file(file: &str) -> Result<String, String> { | ||
let mut proc_self_maps = | ||
File::open("/proc/self/maps").map_err(|_| "Couldn't open /proc/self/maps")?; | ||
File::open(file).map_err(|_| concat_str("Couldn't open file: ", file))?; | ||
let mut buf = String::new(); | ||
let _bytes_read = proc_self_maps | ||
.read_to_string(&mut buf) | ||
.map_err(|_| "Couldn't read /proc/self/maps")?; | ||
for line in buf.lines() { | ||
v.push(line.parse()?); | ||
} | ||
.map_err(|_| concat_str("Couldn't read file: ", file))?; | ||
Ok(buf) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This machinery is a reimplementation of fs::read_to_string
. You can import fs
by changing
- use super::mystd::fs::File;
+ use super::mystd::fs::{self, File};
If you must, you can use map_err
for the Err variant.
#[cfg(not(target_os = "nto"))] | ||
pub fn config() -> (&'static str, usize) { | ||
("/proc/self/maps", 0) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This moves to runtime what can be known at compile-time. Please describe a static
and a const
instead, with appropriate names. If you wish, you can put them in a mod config {}
.
parse_maps_lines(&content, skip) | ||
} | ||
|
||
fn parse_maps_lines(content: &str, skip: usize) -> Result<Vec<MapsEntry>, String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is still functionally identical if we simply delete these lines?
parse_maps_lines(&content, skip) | |
} | |
fn parse_maps_lines(content: &str, skip: usize) -> Result<Vec<MapsEntry>, String> { |
@@ -162,7 +243,7 @@ fn check_maps_entry_parsing_64bit() { | |||
|
|||
assert_eq!( | |||
"7f5985f46000-7f5985f48000 rw-p 00039000 103:06 76021795 \ | |||
/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2" | |||
/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason for diffing this line?
#[test] | ||
fn check_maps_entry_parsing_64bit() { | ||
assert_eq!( | ||
"ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 \ | ||
[vsyscall]" | ||
[vsyscall]" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason for diffing this line?
let vaddr_str = parts.next().ok_or("Couldn't find virtual address")?; | ||
let size_str = parts.next().ok_or("Couldn't find size")?; | ||
let _flags_str = parts.next().ok_or("Couldn't find flags")?; | ||
let prot_str = parts.next().ok_or("Couldn't find protection")?; | ||
let _maxprot_str = parts.next().ok_or("Couldn't find maximum protection")?; | ||
let dev_str = parts.next().ok_or("Couldn't find device")?; | ||
let ino_str = parts.next().ok_or("Couldn't find inode")?; | ||
let offset_str = parts.next().ok_or("Couldn't find offset")?; | ||
let _rsv_str = parts.next().ok_or("Couldn't find reserved pages")?; | ||
let _guardsize_str = parts.next().ok_or("Couldn't find guard size")?; | ||
let _refcnt_str = parts.next().ok_or("Couldn't find reference count")?; | ||
let _mapcnt_str = parts.next().ok_or("Couldn't find mapped count")?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be clear, on QNX Neutrino these are all required fields? Is there somewhere this format is documented for Neutrino? It seems to be a superset of the other format described here?
Ok(v) | ||
pub(super) fn parse_maps() -> Result<Vec<MapsEntry>, String> { | ||
let (file, skip) = config(); | ||
let content = read_file(file)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let content = read_file(file)?; | |
let content = fs::read_to_string(file).map_err(|e| e.to_string())?; |
|s: &str| usize::from_str_radix(&s[2..], 16).map_err(|_| "Couldn't parse hex number"); | ||
let address = { (hex(vaddr_str)?, hex(vaddr_str)? + hex(size_str)?) }; | ||
|
||
// TODO: Probably a rust'ier way of doing this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could probably cook something up using array::from_fn
but I'm not going to block this on that. If you decide not to, though, please remove the TODO.
Add support for QNX Neutrino to standard library This change: - adds standard library support for QNX Neutrino (7.1). - upgrades `libc` to version `0.2.139` which supports QNX Neutrino `@gh-tr`⚠️ Backtraces on QNX require rust-lang/backtrace-rs#507 which is not yet merged! (But everything else works without these changes)⚠️ Tested mainly with a x86_64 virtual machine (see qnx-nto.md) and partially with an aarch64 hardware (some tests fail due to constrained resources).
Add support for QNX Neutrino to standard library This change: - adds standard library support for QNX Neutrino (7.1). - upgrades `libc` to version `0.2.139` which supports QNX Neutrino `@gh-tr`⚠️ Backtraces on QNX require rust-lang/backtrace-rs#507 which is not yet merged! (But everything else works without these changes)⚠️ Tested mainly with a x86_64 virtual machine (see qnx-nto.md) and partially with an aarch64 hardware (some tests fail due to constrained resources).
this PR can be closed now that #648 has landed (648 adds support for both QNX 7.0 and 7.1) |
@japaric The QNX |
Add support for QNX Neutrino.
-- Tested on a Neutrino target for both aarch64 and x86_64 running 7.1.
Change Description:
default
) into one module and thento
into another/proc/self/pmap