Page MenuHomeFreeBSD

sys: Add sys/ckdint.h
ClosedPublic

Authored by markj on Mon, Aug 10, 10:05 PM.
Tags
None
Referenced Files
F167301523: D58773.id183839.diff
Thu, Aug 20, 7:08 PM
F167234447: D58773.id183910.diff
Thu, Aug 20, 5:05 AM
F167206418: D58773.id.diff
Wed, Aug 19, 10:51 PM
Unknown Object (File)
Wed, Aug 19, 2:09 PM
Unknown Object (File)
Wed, Aug 19, 6:30 AM
Unknown Object (File)
Wed, Aug 19, 5:20 AM
Unknown Object (File)
Wed, Aug 19, 2:56 AM
Unknown Object (File)
Wed, Aug 19, 12:32 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 Skipped
Unit
Tests Skipped
Build Status
Buildable 75533
Build 72416: arc lint + arc unit

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–2022

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

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

Once other consumers are converted, yes.

This revision was automatically updated to reflect the committed changes.