1 /* $OpenBSD: kern_compat.h,v 1.16 2023/11/11 07:34:54 anton Exp $ */ 2 3 #ifndef _KERN_COMPAT_H_ 4 #define _KERN_COMPAT_H_ 5 6 #define _KERNEL 7 #include <sys/refcnt.h> 8 #undef _KERNEL 9 10 #include <sys/socket.h> 11 #include <sys/domain.h> 12 #include <sys/queue.h> 13 #include <sys/mutex.h> 14 #include <sys/rwlock.h> 15 #include <sys/task.h> 16 #include <sys/select.h> 17 #include <arpa/inet.h> 18 19 #include <assert.h> 20 #include <err.h> 21 #include <errno.h> 22 #include <limits.h> 23 #include <stdbool.h> 24 #include <stdio.h> 25 #include <stdlib.h> 26 #include <string.h> 27 28 #include "srp_compat.h" 29 30 #define _KERNEL 31 #define DIAGNOSTIC 32 #define INET 33 #define INET6 34 35 #define KASSERT(x) assert(x) 36 #define KERNEL_ASSERT_LOCKED() /* nothing */ 37 #define KERNEL_LOCK() /* nothing */ 38 #define KERNEL_UNLOCK() /* nothing */ 39 40 #define NET_ASSERT_UNLOCKED() /* nothing */ 41 #define NET_ASSERT_LOCKED() /* nothing */ 42 #define NET_ASSERT_LOCKED_EXCLUSIVE() /* nothing */ 43 44 #define panic(x...) errx(1, x) 45 46 #define malloc(size, bucket, flag) calloc(1, size) 47 #define mallocarray(nelems, size, bucket, flag) calloc(nelems, size) 48 #define free(x, bucket, size) free(x) 49 50 struct pool { 51 size_t pr_size; 52 }; 53 54 #define pool_init(a, b, c, d, e, f, g) do { (a)->pr_size = (b); } while (0) 55 #define pool_setipl(pp, ipl) /* nothing */ 56 #define pool_get(pp, flags) malloc((pp)->pr_size, 0, 0) 57 #define pool_put(pp, rp) free((rp), 0, 0) 58 59 #define log(lvl, x...) fprintf(stderr, x) 60 61 #define min(a, b) (a < b ? a : b) 62 #define max(a, b) (a < b ? b : a) 63 64 #ifndef nitems 65 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) 66 #endif 67 68 #ifndef IPL_NONE 69 #define IPL_NONE 0 70 #endif 71 #define mtx_enter(_mtx) /* nothing */ 72 #define mtx_leave(_mtx) /* nothing */ 73 74 #define task_add(_tq, _t) ((_t)->t_func((_t)->t_arg)) 75 76 extern struct domain *domains[]; 77 78 #define IPL_SOFTNET 0 79 80 #define rw_init(rwl, name) 81 #define rw_enter_write(rwl) 82 #define rw_exit_write(rwl) 83 #define rw_assert_wrlock(rwl) 84 85 #define SET(t, f) ((t) |= (f)) 86 #define CLR(t, f) ((t) &= ~(f)) 87 #define ISSET(t, f) ((t) & (f)) 88 89 struct rtentry; 90 91 int rt_hash(struct rtentry *, const struct sockaddr *, uint32_t *); 92 93 #endif /* _KERN_COMPAT_H_ */ 94