1 /* $OpenBSD: kern_compat.h,v 1.12 2021/04/13 08:21:12 claudio 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/rwlock.h> 11 #include <sys/task.h> 12 #include <sys/select.h> 13 #include <arpa/inet.h> 14 15 #include <assert.h> 16 #include <err.h> 17 #include <errno.h> 18 #include <limits.h> 19 #include <stdbool.h> 20 #include <stdio.h> 21 #include <stdlib.h> 22 #include <string.h> 23 24 #include "srp_compat.h" 25 26 #define _KERNEL 27 #define DIAGNOSTIC 28 #define INET 29 #define INET6 30 31 #define KASSERT(x) assert(x) 32 #define KERNEL_ASSERT_LOCKED() /* nothing */ 33 #define KERNEL_LOCK() /* nothing */ 34 #define KERNEL_UNLOCK() /* nothing */ 35 36 #define panic(x...) errx(1, x) 37 38 #define malloc(size, bucket, flag) calloc(1, size) 39 #define mallocarray(nelems, size, bucket, flag) calloc(nelems, size) 40 #define free(x, bucket, size) free(x) 41 42 struct pool { 43 size_t pr_size; 44 }; 45 46 #define pool_init(a, b, c, d, e, f, g) do { (a)->pr_size = (b); } while (0) 47 #define pool_setipl(pp, ipl) /* nothing */ 48 #define pool_get(pp, flags) malloc((pp)->pr_size, 0, 0) 49 #define pool_put(pp, rp) free((rp), 0, 0) 50 51 #define log(lvl, x...) fprintf(stderr, x) 52 53 #define min(a, b) (a < b ? a : b) 54 #define max(a, b) (a < b ? b : a) 55 56 #ifndef nitems 57 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) 58 #endif 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