50 #include <sys/prsystm.h>
51 #include <sys/debug.h>
52 #include <sys/kmem.h>
53 #include <sys/atomic.h>
54 #include <sys/fcntl.h>
55 #include <sys/poll.h>
56 #include <sys/rctl.h>
57 #include <sys/port_impl.h>
58 #include <sys/dtrace.h>
59
60 #include <c2/audit.h>
61 #include <sys/nbmlock.h>
62
63 #ifdef DEBUG
64
65 static uint32_t afd_maxfd; /* # of entries in maximum allocated array */
66 static uint32_t afd_alloc; /* count of kmem_alloc()s */
67 static uint32_t afd_free; /* count of kmem_free()s */
68 static uint32_t afd_wait; /* count of waits on non-zero ref count */
69 #define MAXFD(x) (afd_maxfd = ((afd_maxfd >= (x))? afd_maxfd : (x)))
70 #define COUNT(x) atomic_add_32(&x, 1)
71
72 #else /* DEBUG */
73
74 #define MAXFD(x)
75 #define COUNT(x)
76
77 #endif /* DEBUG */
78
79 kmem_cache_t *file_cache;
80
81 static void port_close_fd(portfd_t *);
82
83 /*
84 * File descriptor allocation.
85 *
86 * fd_find(fip, minfd) finds the first available descriptor >= minfd.
87 * The most common case is open(2), in which minfd = 0, but we must also
88 * support fcntl(fd, F_DUPFD, minfd).
89 *
90 * The algorithm is as follows: we keep all file descriptors in an infix
|
50 #include <sys/prsystm.h>
51 #include <sys/debug.h>
52 #include <sys/kmem.h>
53 #include <sys/atomic.h>
54 #include <sys/fcntl.h>
55 #include <sys/poll.h>
56 #include <sys/rctl.h>
57 #include <sys/port_impl.h>
58 #include <sys/dtrace.h>
59
60 #include <c2/audit.h>
61 #include <sys/nbmlock.h>
62
63 #ifdef DEBUG
64
65 static uint32_t afd_maxfd; /* # of entries in maximum allocated array */
66 static uint32_t afd_alloc; /* count of kmem_alloc()s */
67 static uint32_t afd_free; /* count of kmem_free()s */
68 static uint32_t afd_wait; /* count of waits on non-zero ref count */
69 #define MAXFD(x) (afd_maxfd = ((afd_maxfd >= (x))? afd_maxfd : (x)))
70 #define COUNT(x) atomic_inc_32(&x)
71
72 #else /* DEBUG */
73
74 #define MAXFD(x)
75 #define COUNT(x)
76
77 #endif /* DEBUG */
78
79 kmem_cache_t *file_cache;
80
81 static void port_close_fd(portfd_t *);
82
83 /*
84 * File descriptor allocation.
85 *
86 * fd_find(fip, minfd) finds the first available descriptor >= minfd.
87 * The most common case is open(2), in which minfd = 0, but we must also
88 * support fcntl(fd, F_DUPFD, minfd).
89 *
90 * The algorithm is as follows: we keep all file descriptors in an infix
|