Commit ae13829d authored by Doug Moore's avatar Doug Moore
Browse files

vm_addr_ok: add power2 invariant check

With INVARIANTS defined, have vm_addr_align_ok and vm_addr_bound_ok
panic when passed an alignment/boundary parameter that is not a power
of two.

Reviewed by:	alc
Suggested by:	kib, se
Differential Revision:
parent 90bc1cf6
......@@ -140,6 +140,11 @@ u_int vm_wait_count(void);
static inline bool
vm_addr_align_ok(vm_paddr_t pa, u_long alignment)
if (!powerof2(alignment))
panic("%s: alignment is not a power of 2: %#lx",
__func__, alignment);
return ((pa & (alignment - 1)) == 0);
......@@ -150,6 +155,11 @@ vm_addr_align_ok(vm_paddr_t pa, u_long alignment)
static inline bool
vm_addr_bound_ok(vm_paddr_t pa, vm_paddr_t size, vm_paddr_t boundary)
if (!powerof2(boundary))
panic("%s: boundary is not a power of 2: %#jx",
__func__, (uintmax_t)boundary);
return (((pa ^ (pa + size - 1)) & -boundary) == 0);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment