Skip to content

Commit

Permalink
vm: make VM_PROT_ADD_CAP a statement expression (NFC)
Browse files Browse the repository at this point in the history
Refactor VM_PROT_ADD_CAP() macro to use a statement expression and if
statements.  Eliminates multiple expansion of the prot argument and
prepares for future changes allowing explicit capablity permission
selection.
  • Loading branch information
brooksdavis committed Sep 4, 2024
1 parent f04f787 commit 72196e6
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions sys/vm/vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,16 @@ typedef u_char vm_prot_t; /* protection codes */
#define VM_PROT_RW_CAP (VM_PROT_RW|VM_PROT_CAP)
#define VM_PROT_ALL (VM_PROT_RWX|VM_PROT_CAP)

#define VM_PROT_ADD_CAP(prot) \
((prot) | (((prot) & VM_PROT_READ) != 0 ? VM_PROT_READ_CAP : 0) | \
(((prot) & VM_PROT_WRITE) != 0 ? VM_PROT_WRITE_CAP : 0))
#define VM_PROT_ADD_CAP(prot) __extension__ ({ \
vm_prot_t cp, p; \
\
cp = p = (prot); \
if ((p & VM_PROT_READ) != 0) \
cp |= VM_PROT_READ_CAP; \
if ((p & VM_PROT_WRITE) != 0) \
cp |= VM_PROT_WRITE_CAP; \
cp; \
})

#define VM_PROT_EXTRACT(prot) ((prot) & VM_PROT_ALL)

Expand Down

0 comments on commit 72196e6

Please sign in to comment.