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