Page MenuHomeFreeBSD

linuxkpi: Add hex_dump_to_buffer()
Needs RevisionPublic

Authored by dumbbell on Jul 26 2025, 3:53 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Oct 3, 2:25 PM
Unknown Object (File)
Wed, Oct 1, 10:41 PM
Unknown Object (File)
Wed, Oct 1, 2:42 PM
Unknown Object (File)
Tue, Sep 30, 11:01 PM
Unknown Object (File)
Tue, Sep 30, 8:15 AM
Unknown Object (File)
Tue, Sep 30, 2:18 AM
Unknown Object (File)
Sun, Sep 21, 8:15 AM
Unknown Object (File)
Wed, Sep 17, 6:22 PM
Subscribers

Details

Reviewers
bz
Group Reviewers
linuxkpi
Summary

This function prints a single line of hex dump to the given line buffer.

The implementation relies on lkpi_hex_dump() to format the string. After the formatting, it trims the newline character automatically added by lkpi_hex_dump().

Sponsored by: The FreeBSD Foundation

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

It looks like Linux hex_dump_to_buffer does a hex+printable ASCII a la 48 65 6c 6c 6f 2c 20 77 6f 72 6c 64 Hello, world, although I don't think it's incredibly important for our use cases.

bz requested changes to this revision.Jul 30 2025, 9:16 AM
bz added a subscriber: bz.

It looks like Linux hex_dump_to_buffer does a hex+printable ASCII a la 48 65 6c 6c 6f 2c 20 77 6f 72 6c 64 Hello, world, although I don't think it's incredibly important for our use cases.

Yeah, we do have the ascii flag but it was never implemented (not before my reshuffling either).

sys/compat/linuxkpi/common/src/linux_compat.c
2088

you do not want to return negative I think but 0; otherwise linelen in lkpi_hex_dump may go negative or back to 0; this is likely also a problem with the other callback routines.

2090

this is not correct. written can be > context->linebuflen if the output would have been longer than the buffer size. You need another check here or rather set it accordingly .. hmm also below is wrong to the end of the func.

If I am not mistaken:

if (written <= (context->linebuflen - 1))    /* terminating \0 */
     context->written = written + 1;
else
     context->written = context->linebuflen;

context->linebuf += context->written;
context->linebuflen -= context->written;

return (context->written);

But you should double-check that given vsnprintf returns the length without the trailing \0 and I am not sure if you need to count it or not.

2119

This is not needed, is it? lkpi_hex_dump will only do 8/4/2 or 1 in every other case

2135

should we add another bool to lkpi_hex_dump whether to add the (last) \n or not?

This revision now requires changes to proceed.Jul 30 2025, 9:16 AM
dumbbell added inline comments.
sys/compat/linuxkpi/common/src/linux_compat.c
2088

You are right. I updated D51558 to handle negative return values from the callback.

2090

According to the documentation of hex_dump_to_buffer() on Linux, it has the same behaviour as snprintf(): it returns the number of bytes it would have written if the destination buffer was large enough, excluding the trailing NUL character.

I updated the patch to remove the linebuflen == 0 check at the beginning and added comments to describe that.

Is it clearer or is there still a logic issue?

2119

You are right. I removed that part.

2135

Good idea, I added D51844 to implement that separately.