| 726 | } |
| 727 | |
| 728 | uint64_t |
| 729 | rctl_get_available(struct proc *p, int resource) |
| 730 | { |
| 731 | struct rctl_rule *rule; |
| 732 | struct rctl_rule_link *link; |
| 733 | int64_t available, minavailable, allocated; |
| 734 | |
| 735 | minavailable = INT64_MAX; |
| 736 | |
| 737 | ASSERT_RACCT_ENABLED(); |
| 738 | RACCT_LOCK_ASSERT(); |
| 739 | |
| 740 | /* |
| 741 | * There may be more than one matching rule; go through all of them. |
| 742 | * Denial should be done last, after logging and sending signals. |
| 743 | */ |
| 744 | LIST_FOREACH(link, &p->p_racct->r_rule_links, rrl_next) { |
| 745 | rule = link->rrl_rule; |
| 746 | if (rule->rr_resource != resource) |
| 747 | continue; |
| 748 | if (rule->rr_action != RCTL_ACTION_DENY) |
| 749 | continue; |
| 750 | available = rctl_available_resource(p, rule); |
| 751 | if (available < minavailable) |
| 752 | minavailable = available; |
| 753 | } |
| 754 | |
| 755 | /* |
| 756 | * XXX: Think about this _hard_. |
| 757 | */ |
| 758 | allocated = p->p_racct->r_resources[resource]; |
| 759 | if (minavailable < INT64_MAX - allocated) |
| 760 | minavailable += allocated; |
| 761 | if (minavailable < 0) |
| 762 | minavailable = 0; |
| 763 | |
| 764 | return (minavailable); |
| 765 | } |
| 766 | |
| 767 | static int |
| 768 | rctl_rule_matches(const struct rctl_rule *rule, const struct rctl_rule *filter) |
no test coverage detected