Search code examples
pointersassemblyx86-64cpu-architecturecanonical-form

Can I disable/turn off general protection exception when an address is not in canonical form?


I found the quote below online. Is it possible to disable a general protection exception when a pointer isn't in canonical address form? I was thinking for my app it would be so nice if I can use the high 4bits of a pointer to hold extra data (for example if a node is red or black in a red-black tree)

Although implementations might not use all 64 bits of the virtual address, they check bits 63 through the most-significant implemented bit to see if those bits are all zeros or all ones. An address that complies with this property is said to be in canonical address form. If a virtual-memory reference is not in canonical form, the implementation causes a general-protection exception or stack fault


Solution

  • I don't believe so. I've never heard of such a feature, and skimming the Intel manuals for matches for "canonical" doesn't turn up anything. I think it's essentially hard-wired.

    Note that the architecture reserves the right for future implementations to use more bits, e.g. Intel's 5-level paging CPUs moved from 48- to 57-bit canonical addresses. So if this were possible, any program that used too many of the high bits would risk being incompatible with those future CPUs. The CPU makers have an interest in ensuring forward compatibility, and therefore they would have a disincentive to provide the feature you want.