Is signal catching appropriate when we implement macro `std::is_xxx_feature_detected`?

If we want to detect user level processor features under Unix-like platforms, we would use auxvec where some features can be judged from which bit of returned bitset is set. But there are some features that can't be detected this way. It would either be a RISC-V ISA modules (like Zfh or Zks, other than F, K etc), or some ARM features (ARM7 tick, ref at OpenSSL).

Some libraries under C world (OpenSSL etc.) uses signal catching as a method to detect such features. It registers a signal handler, execute instructions as if it exists, and catch probable illegal instruction signal if that instruction does not exist. It would provide more accurate instruction set information, but none of the is_xxx_feature_detected! in current Rust standard library uses this way. This method could be of significant use under RISC-V architecture, where furtherly bare metal Rust can detect instruction sets under trap vector handling (ref: zihai hypervisor).

Will it be appropriate to implement is_xxx_feature_detected! under signal catching in Linux? If current Rust does not write standard library macro in this way, what could be the reason? Thanks! :slight_smile:

Definitely not. Signal handling is not safe to use within a library, among other reasons.

The is_*_feature_detected functions are meant for the case where you can detect CPU features in advance, whether via a cpuid-like instruction, or via OS features such as the auxiliary vector.

2 Likes

Based on SIGILL in _armv7_tick on ARM when using openssl 1.1.1k · Issue #17465 · openssl/openssl · GitHub it seems like the issue is that it is detected as available on a big core and then fails to execute on a little code. OpenSSL wraps the actual invocation of the instruction in a SIGILL handler, not the detection of this instruction.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.