Page MenuHomeFreeBSD

sys: Add sys/ckdint.h
ClosedPublic

Authored by markj on Mon, Aug 10, 10:05 PM.
Tags
None
Referenced Files
F166963493: D58773.id.diff
Tue, Aug 18, 5:06 AM
Unknown Object (File)
Mon, Aug 17, 7:51 AM
Unknown Object (File)
Sun, Aug 16, 7:08 AM
Unknown Object (File)
Sat, Aug 15, 1:18 AM
Unknown Object (File)
Fri, Aug 14, 6:43 PM
Unknown Object (File)
Thu, Aug 13, 11:23 AM
Unknown Object (File)
Tue, Aug 11, 7:47 PM
Unknown Object (File)
Tue, Aug 11, 5:48 AM
Subscribers

Details

Summary

We have a C23 stdckdint.h header for userspace, which provides checked
addition, subtraction and multiplication. We lack similar helpers in
the kernel, where they are regularly needed.

Let's just adopt the C23 macros. For bonus points, I added a wrapper to
ensure that ignored an return value is raised as an error by the
compiler. I also converted a couple of places in the kernel to use the
new macros. The netmap change in particular fixes a bug in my commit
319414a926af1515e2572f89f0636e5505e762d5.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

This revision is now accepted and ready to land.Tue, Aug 11, 11:00 AM
emaste added a subscriber: emaste.
emaste added inline comments.
sys/dev/netmap/netmap_mem2.c
2017–2024 ↗(On Diff #183839)

Or even

			if (ckd_mul(&len, ndesc, sizeof(struct netmap_slot)) ||
			    ckd_add(&len, len, sizeof(struct netmap_ring))) {
				error = EINVAL;
				goto cleanup;
			}

To me at least this reads close to ndesc * sizeof(struct netmap_slot) + sizeof(struct netmap_ring) checked for overflow.

markj marked an inline comment as done.

Review feedback

This revision now requires review to proceed.Wed, Aug 12, 1:45 PM
This revision is now accepted and ready to land.Wed, Aug 12, 1:46 PM

I like it. Please land the new header and kernel fixes separately in case reversal is needed.

sys/kern/kern_malloc.c
827 ↗(On Diff #183910)

Should we get rid of the WOULD_OVERFLOW macro entirely?

In D58773#1351426, @fuz wrote:

I like it. Please land the new header and kernel fixes separately in case reversal is needed.

Yep, I will. I put everything together just for demonstration.

sys/kern/kern_malloc.c
827 ↗(On Diff #183910)

Once other consumers are converted, yes.

This revision was automatically updated to reflect the committed changes.