1f9a21cf8SJérôme Duval/*
2f9a21cf8SJérôme Duval * Copyright 2009, Colin G��nther, coling@gmx.de.
3f9a21cf8SJérôme Duval * Copyright 2007, Hugo Santos. All Rights Reserved.
4f9a21cf8SJérôme Duval * Distributed under the terms of the MIT License.
5f9a21cf8SJérôme Duval */
6f9a21cf8SJérôme Duval#ifndef _FBSD_COMPAT_SYS_MALLOC_H_
7f9a21cf8SJérôme Duval#define _FBSD_COMPAT_SYS_MALLOC_H_
8f9a21cf8SJérôme Duval
9f9a21cf8SJérôme Duval
10f9a21cf8SJérôme Duval#include <malloc.h>
11f9a21cf8SJérôme Duval
12f9a21cf8SJérôme Duval#include <vm/vm.h>
13f9a21cf8SJérôme Duval
14f9a21cf8SJérôme Duval#include <sys/param.h>
15f9a21cf8SJérôme Duval#include <sys/queue.h>
16f9a21cf8SJérôme Duval#include <sys/_mutex.h>
17f9a21cf8SJérôme Duval
18f9a21cf8SJérôme Duval
19f9a21cf8SJérôme Duval/*
20f9a21cf8SJérôme Duval * flags to malloc.
21f9a21cf8SJérôme Duval */
22f9a21cf8SJérôme Duval#define M_NOWAIT		0x0001
23f9a21cf8SJérôme Duval#define M_WAITOK		0x0002
24f9a21cf8SJérôme Duval#define M_ZERO			0x0100
25f9a21cf8SJérôme Duval
26f9a21cf8SJérôme Duval#define	M_MAGIC			877983977	/* time when first defined :-) */
27f9a21cf8SJérôme Duval
28d20b9323SAugustin Cavalier#define M_DEVBUF		0
29d20b9323SAugustin Cavalier
30d20b9323SAugustin Cavalier
31d20b9323SAugustin Cavalierstruct malloc_type {
32d20b9323SAugustin Cavalier};
33f9a21cf8SJérôme Duval
34f9a21cf8SJérôme Duval
35f9a21cf8SJérôme Duvalvoid *_kernel_malloc(size_t size, int flags);
36f9a21cf8SJérôme Duvalvoid _kernel_free(void *ptr);
37f9a21cf8SJérôme Duval
38f9a21cf8SJérôme Duvalvoid *_kernel_contigmalloc(const char *file, int line, size_t size, int flags,
39f9a21cf8SJérôme Duval	vm_paddr_t low, vm_paddr_t high, unsigned long alignment,
40f9a21cf8SJérôme Duval	unsigned long boundary);
41f9a21cf8SJérôme Duvalvoid _kernel_contigfree(void *addr, unsigned long size);
42f9a21cf8SJérôme Duval
43f9a21cf8SJérôme Duval#define kernel_malloc(size, base, flags) \
44f9a21cf8SJérôme Duval	_kernel_malloc(size, flags)
45f9a21cf8SJérôme Duval
46f9a21cf8SJérôme Duval#define kernel_free(ptr, base) \
47f9a21cf8SJérôme Duval	_kernel_free(ptr)
48f9a21cf8SJérôme Duval
49f9a21cf8SJérôme Duval#define kernel_contigmalloc(size, type, flags, low, high, alignment, boundary) \
50f9a21cf8SJérôme Duval	_kernel_contigmalloc(__FILE__, __LINE__, size, flags, low, high, \
51f9a21cf8SJérôme Duval		alignment, boundary)
52f9a21cf8SJérôme Duval
53f9a21cf8SJérôme Duval#define kernel_contigfree(addr, size, base) \
54f9a21cf8SJérôme Duval	_kernel_contigfree(addr, size)
55f9a21cf8SJérôme Duval
56f9a21cf8SJérôme Duval#ifdef FBSD_DRIVER
57f9a21cf8SJérôme Duval#	define malloc(size, tag, flags)	kernel_malloc(size, tag, flags)
58f9a21cf8SJérôme Duval#	define free(pointer, tag)		kernel_free(pointer, tag)
59f9a21cf8SJérôme Duval#	define contigmalloc(size, type, flags, low, high, alignment, boundary) \
60f9a21cf8SJérôme Duval		_kernel_contigmalloc(__FILE__, __LINE__, size, flags, low, high, \
61f9a21cf8SJérôme Duval			alignment, boundary)
62f9a21cf8SJérôme Duval#	define contigfree(addr, size, base) \
63f9a21cf8SJérôme Duval		_kernel_contigfree(addr, size)
64f9a21cf8SJérôme Duval#endif
65f9a21cf8SJérôme Duval
66f9a21cf8SJérôme Duval#define	MALLOC_DEFINE(type, shortdesc, longdesc)	int type[1]
67f9a21cf8SJérôme Duval
68f9a21cf8SJérôme Duval#define	MALLOC_DECLARE(type) \
69f9a21cf8SJérôme Duval		extern int type[1]
70f9a21cf8SJérôme Duval
71f9a21cf8SJérôme Duval#endif	/* _FBSD_COMPAT_SYS_MALLOC_H_ */
72