RFR: 8289046: Undefined Behaviour in x86 class Assembler [v5]
Aleksey Shipilev
shade at openjdk.org
Mon Jul 18 09:54:17 UTC 2022
On Tue, 5 Jul 2022 08:12:23 GMT, Andrew Haley <aph at openjdk.org> wrote:
>> All instances of type Register exhibit UB in the form of wild pointer (including null pointer) dereferences. This isn't very hard to fix: we should make Registers pointers to something rather than aliases of small integers.
>>
>> Here's an example of what was happening:
>>
>> ` rax->encoding();`
>>
>> Where rax is defined as `(Register *)0`.
>>
>> This patch things so that rax is now defined as a pointer to the start of a static array of RegisterImpl.
>>
>>
>> typedef const RegisterImpl* Register;
>> extern RegisterImpl all_Registers[RegisterImpl::number_of_declared_registers + 1] ;
>> inline constexpr Register RegisterImpl::first() { return all_Registers + 1; };
>> inline constexpr Register as_Register(int encoding) { return RegisterImpl::first() + encoding; }
>> constexpr Register rax = as_register(0);
>
> Andrew Haley has updated the pull request incrementally with one additional commit since the last revision:
>
> Delete changes to hotspot/shared.
Looks okay to me, with minor nits.
src/hotspot/cpu/x86/register_x86.cpp line 47:
> 45: KRegisterImpl::max_slots_per_register * KRegisterImpl::number_of_registers;
> 46:
> 47: const char * RegisterImpl::name() const {
Suggestion:
const char* RegisterImpl::name() const {
src/hotspot/cpu/x86/register_x86.hpp line 170:
> 168: int raw_encoding() const { return this - first(); }
> 169: int encoding() const { assert(is_valid(), "invalid register"); return raw_encoding(); }
> 170: bool is_valid() const { return 0 <= raw_encoding() && raw_encoding() < number_of_registers; }
Suggestion:
bool is_valid() const { return 0 <= raw_encoding() && raw_encoding() < number_of_registers; }
-------------
Marked as reviewed by shade (Reviewer).
PR: https://git.openjdk.org/jdk/pull/9261
More information about the hotspot-compiler-dev
mailing list