aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/9term/malloc.c
blob: 7b590bc4b5971d478a57b5b8598659cf147b0d22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * These are here mainly so that I can link against
 * debugmalloc.c instead and not recompile the world.
 */

#include <u.h>
#define NOPLAN9DEFINES
#include <libc.h>

void*
p9malloc(ulong n)
{
	void *v;

	if(n == 0)
		n++;
	v = malloc(n);
	print("p9malloc %lud => %p; pc %lux\n", n, v, getcallerpc(&n));
	return v;
}

void
p9free(void *v)
{
	if(v == nil)
		return;
	print("p9free %p; pc %lux\n", v, getcallerpc(&v));
	free(v);
}

void*
p9calloc(ulong a, ulong b)
{
	void *v;

	if(a*b == 0)
		a = b = 1;

	v = calloc(a*b, 1);
	print("p9calloc %lud %lud => %p; pc %lux\n", a, b, v, getcallerpc(&a));
	return v;
}

void*
p9realloc(void *v, ulong n)
{
	void *vv;

	vv = realloc(v, n);
	print("p9realloc %p %lud => %p; pc %lux\n", v, n, vv, getcallerpc(&v));
	return vv;
}