cheribsd icon indicating copy to clipboard operation
cheribsd copied to clipboard

Fix some KTR/CTR casts for CHERI

Open nwf opened this issue 3 years ago • 6 comments

Fixes compilation failures if options KTR is kicked on. Am open to suggestions about the correct type to cast to (ptraddr_t rather than uintptr_t?).

nwf avatar Jun 29 '21 20:06 nwf

uintptr_t with %#lx is definitely wrong, that'll give warnings on 32-bit architectures (though work because unsigned int and unsigned long have the same representation) and be completely wrong for a purecap kernel. Just leave them as u_long and add __cheri_addr or, better, cast to u_long via uintcap_t?

jrtc27 avatar Jun 29 '21 20:06 jrtc27

Can we just use %lp or is that not supported? If not this seems fine to me.

arichardson avatar Jun 30 '21 08:06 arichardson

Oh hah. Yes, that seems to work. How's this look?

nwf avatar Jun 30 '21 10:06 nwf

Continued use of %lx and %p but not %lp is deliberate, the parameters are stored as an array of uintptr_t.

jrtc27 avatar Jun 30 '21 13:06 jrtc27

This is getting a little more broad... I suspect we're going to want to store the parameters as uintcap_t (or perhaps ptraddr_t) so that it's the same size between hybrid and purecap. That may change the format specifiers we use.

nwf avatar Jun 30 '21 17:06 nwf

My feeling is that internally we should store it as uintcap_t so the native ABI sees the right thing, and if you want a hybrid/vanilla process to work with it then you'll need compat code, but AFAIK 32-bit processes don't work with 64-bit dumps. I guess in theory we could also store a tag bitmap for CHERI.

jrtc27 avatar Jun 30 '21 18:06 jrtc27