xsegbd/xsegdev: Fix xsegbd/xsegdev memory leak
[archipelago] / xseg / sys / util.h
1 #ifndef XSEG_UTIL_H
2 #define XSEG_UTIL_H
3
4 #ifdef __KERNEL__
5
6 #include <linux/kernel.h>
7 #include <linux/types.h>
8 #include <linux/slab.h>
9
10 #else
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <stdint.h>
15 #include <string.h>
16
17 #endif
18
19 void __xseg_log(const char *msg);
20 extern char __xseg_errbuf[4096];
21 extern int (*xseg_snprintf)(char *str, size_t size, const char *format, ...);
22 void *xq_malloc(unsigned long size);
23 void xq_mfree(void *ptr);
24
25 #define FMTARG(fmt, arg, format, ...) fmt format "%s", arg, ## __VA_ARGS__
26 #define LOGMSG(...) xseg_snprintf(__xseg_errbuf, 4096, FMTARG("%s: ", __func__, ## __VA_ARGS__, "")), \
27                     __xseg_errbuf[4095] = 0, __xseg_log(__xseg_errbuf)
28
29 #endif