HomeFreeBSD

vm_extern: use standard address checkers everywhere

Description

vm_extern: use standard address checkers everywhere

Define simple functions for alignment and boundary checks and use them
everywhere instead of having slightly different implementations
scattered about. Define them in vm_extern.h and use them where
possible where vm_extern.h is included.

Reviewed by: kib, markj
Differential Revision: https://reviews.freebsd.org/D33685

Details

Provenance
dougmAuthored on Dec 31 2021, 4:09 AM
Reviewer
kib
Differential Revision
D33685: Define and use standard functions for alignment checking
Parents
rGc09981f1422e: mips: Remove sys/mips
Branches
Unknown
Tags
Unknown

Event Timeline

Now that there is only one set of vm_addr check functions, how about adding a parameter check for INVARIANTS builds?
Calling with parameters that are not a power of 2 will call spurious results, which might cause hard to debug issues ...

/sys/vm/vm_extern.h
136

Add a test macro:

#define IS_POW2(n) (((n) & (-n)) == (n))
142
#ifdef INVARIANTS
    if (!IS_POW2(alignment))
        panic("vm_addr_align_ok: alignment is not a power of 2: 0x%lx", alignment);
#endif
152
#ifdef INVARIANTS
    if (!IS_POW2(boundary))
        panic("vm_addr_bound_ok: boundary is not a power of 2: 0x%lx", boundary);
#endif