On 08/02/2024 13:07, Beata Michalska wrote:
On Thu, Feb 08, 2024 at 09:29:26AM +0000, Kevin Brodsky wrote:
%#lp results in the address being prefixed with 0x, like %#p, but not if the capability is null-derived. Make sure the prefix is used in all cases.
I think it was done on purpose as (per [1]):
- "In addition, for null-derived capabilities (capabilities where the tag and upper attribute word are all zero), only the address is displayed (the Basic Format)."
[1] is indeed not very clear on the format in that case, but CheriBSD does print 0x for null-derived capabilities too [2] and so does Musl. It would be strange to print it only if the capability is not null-derived.
- Basic Format: ... "This should generally match the existing format used with integer pointers."
- "Linux kernel displays integer pointers as hexadecimal without a 0x prefix), and p should match a platform's existing format."
And I think the reason why "%#p" works is just a coincidence as '#' is being supported by relevant formatting function (number) which is used when printing default integer pointers. It is not by 'design' as such.
I don't have a strong opinion either for or against printing the prefix, but we should definitely be consistent (either always or never print it).
Kevin
[2] https://github.com/CTSRD-CHERI/cheribsd/blob/main/lib/libc/stdio/printfcommo...
[1] https://github.com/CTSRD-CHERI/cheri-c-programming/wiki/Displaying-Capabilit...
BR Beata