Skip to content

Commit 86213f9

Browse files
Track permissions as bytes
Because we expect certain inputs, we don't need chars. The code also doesn't need to validate exact lengths. This reduces the generated code size slightly.
1 parent e1c49fb commit 86213f9

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

src/symbolize/gimli/parse_running_mmaps_unix.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub(super) struct MapsEntry {
1818
/// x = execute
1919
/// s = shared
2020
/// p = private (copy on write)
21-
perms: [char; 4],
21+
perms: [u8; 4],
2222
/// Offset into the file (or "whatever").
2323
offset: usize,
2424
/// device (major, minor)
@@ -102,14 +102,12 @@ impl FromStr for MapsEntry {
102102
} else {
103103
return Err("Couldn't parse address range");
104104
};
105-
let perms: [char; 4] = {
106-
let mut chars = perms_str.chars();
107-
let mut c = || chars.next().ok_or("insufficient perms");
108-
let perms = [c()?, c()?, c()?, c()?];
109-
if chars.next().is_some() {
110-
return Err("too many perms");
111-
}
112-
perms
105+
let perms = if let &[r, w, x, p, ..] = perms_str.as_bytes() {
106+
// If a system in the future adds a 5th field to the permission list,
107+
// there's no reason to assume previous fields were invalidated.
108+
[r, w, x, p]
109+
} else {
110+
return Err("less than 4 perms");
113111
};
114112
let offset = hex(offset_str)?;
115113
let dev = if let Some((major, minor)) = dev_str.split_once(':') {
@@ -142,7 +140,7 @@ fn check_maps_entry_parsing_64bit() {
142140
.unwrap(),
143141
MapsEntry {
144142
address: (0xffffffffff600000, 0xffffffffff601000),
145-
perms: ['-', '-', 'x', 'p'],
143+
perms: *b"--xp",
146144
offset: 0x00000000,
147145
dev: (0x00, 0x00),
148146
inode: 0x0,
@@ -157,7 +155,7 @@ fn check_maps_entry_parsing_64bit() {
157155
.unwrap(),
158156
MapsEntry {
159157
address: (0x7f5985f46000, 0x7f5985f48000),
160-
perms: ['r', 'w', '-', 'p'],
158+
perms: *b"rw-p",
161159
offset: 0x00039000,
162160
dev: (0x103, 0x06),
163161
inode: 0x76021795,
@@ -170,7 +168,7 @@ fn check_maps_entry_parsing_64bit() {
170168
.unwrap(),
171169
MapsEntry {
172170
address: (0x35b1a21000, 0x35b1a22000),
173-
perms: ['r', 'w', '-', 'p'],
171+
perms: *b"rw-p",
174172
offset: 0x00000000,
175173
dev: (0x00, 0x00),
176174
inode: 0x0,
@@ -194,7 +192,7 @@ fn check_maps_entry_parsing_32bit() {
194192
.unwrap(),
195193
MapsEntry {
196194
address: (0x08056000, 0x08077000),
197-
perms: ['r', 'w', '-', 'p'],
195+
perms: *b"rw-p",
198196
offset: 0x00000000,
199197
dev: (0x00, 0x00),
200198
inode: 0x0,
@@ -209,7 +207,7 @@ fn check_maps_entry_parsing_32bit() {
209207
.unwrap(),
210208
MapsEntry {
211209
address: (0xb7c79000, 0xb7e02000),
212-
perms: ['r', '-', '-', 'p'],
210+
perms: *b"r--p",
213211
offset: 0x00000000,
214212
dev: (0x08, 0x01),
215213
inode: 0x60662705,
@@ -222,7 +220,7 @@ fn check_maps_entry_parsing_32bit() {
222220
.unwrap(),
223221
MapsEntry {
224222
address: (0xb7e02000, 0xb7e03000),
225-
perms: ['r', 'w', '-', 'p'],
223+
perms: *b"rw-p",
226224
offset: 0x00000000,
227225
dev: (0x00, 0x00),
228226
inode: 0x0,

0 commit comments

Comments
 (0)