std::process: fix UEFI ExitStatus::code() silent truncation of error …#153973
std::process: fix UEFI ExitStatus::code() silent truncation of error …#153973devnexen wants to merge 2 commits intorust-lang:mainfrom
Conversation
…codes UEFI status codes are usize-wide with the high bit set for errors (e.g. DEVICE_ERROR is 0x8000000000000007 on 64-bit). the previous `as i32` cast silently dropped the upper bits, losing all error information. stripping the error high bit to extract the error number and negating it, so errors (negative) are distinguishable from success/warning codes (non-negative).
|
r? @joboet rustbot has assigned @joboet. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Wouldn't it make more sense to convert the error to the equivalent UEFI error on 32-bit platforms (by re-setting the highest bit) instead of negating? |
|
Looks fine to me, though the |
| // (e.g. DEVICE_ERROR is 0x8000000000000007 on 64-bit). | ||
| // Strip the platform-width high bit and re-set bit 31 to | ||
| // produce the equivalent 32-bit UEFI error representation. | ||
| let err_num = code & !(0x80usize << (usize::BITS - 8)); |
There was a problem hiding this comment.
| let err_num = code & !(0x80usize << (usize::BITS - 8)); | |
| let err_num = code & !(1usize << (usize::BITS - 1)); |
| if self.0.is_error() { | ||
| // same as ExitStatus::code(), stripping the platform-width | ||
| // high bit and re-setting bit 31 for the 32-bit equivalent. | ||
| let err_num = code & !(0x80usize << (usize::BITS - 8)); |
There was a problem hiding this comment.
| let err_num = code & !(0x80usize << (usize::BITS - 8)); | |
| let err_num = code & !(1usize << (usize::BITS - 1)); |
|
We talked about this in today's @rust-lang/libs-api meeting. This seems like a reasonable change to make the truncated value somewhat more accurate. This may help make portable programs slightly more capable. However, in a separate PR, we'd love to see an extension trait for |
…codes
UEFI status codes are usize-wide with the high bit set for errors (e.g. DEVICE_ERROR is 0x8000000000000007 on 64-bit). the previous
as i32cast silently dropped the upper bits, losing all error information. stripping the error high bit to extract the error number and negating it, so errors (negative) are distinguishable from success/warning codes (non-negative).