Unit Number Allocation API

Unit number

API definitions

sys/systm.h

struct unrhdr;
  522 struct unrhdr *new_unrhdr(int low, int high, struct mtx *mutex);
  523 void init_unrhdr(struct unrhdr *uh, int low, int high, struct mtx *mutex);
  524 void delete_unrhdr(struct unrhdr *uh);
  525 void clear_unrhdr(struct unrhdr *uh);
  526 void clean_unrhdr(struct unrhdr *uh);
  527 void clean_unrhdrl(struct unrhdr *uh);
  528 int alloc_unr(struct unrhdr *uh);
  529 int alloc_unr_specific(struct unrhdr *uh, u_int item);
  530 int alloc_unrl(struct unrhdr *uh);
  531 void free_unr(struct unrhdr *uh, u_int item);

sys/_unrhdr.h

// file:
//  sys/sys/_unrhdr.h

struct mtx;

/* Header element for a unr number space. */

struct unrhdr {
	TAILQ_HEAD(unrhd,unr)	head;
	u_int			low;	/* Lowest item */
	u_int			high;	/* Highest item */
	u_int			busy;	/* Count of allocated items */
	u_int			alloc;	/* Count of memory allocations */
	u_int			first;	/* items in allocated from start */
	u_int			last;	/* items free at end */
	struct mtx		*mtx;
	TAILQ_HEAD(unrfr,unr)	ppfree;	/* Items to be freed after mtx
					   lock dropped */
};
Created Aug 28, 2019 // Last Updated Aug 28, 2019

If you could revise
the fundmental principles of
computer system design
to improve security...

... what would you change?