memory.c
1.25 KB
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
53
/*
* Copyright (C) 1998 by the Board of Trustees
* of Leland Stanford Junior University.
* Copyright (C) 1998 Digital Equipment Corporation
*
* This file is part of the SimOS distribution.
* See LICENSE file for terms of the license.
*
*/
/* Memory allocation routines */
#include <stdio.h>
#include <malloc.h>
#include <sys/types.h>
#include <sys/mman.h>
void
print_mallinfo()
{
struct mallinfo malloc_info;
malloc_info = mallinfo();
printf("arena= %d\n ", malloc_info.arena);
printf("ordblks= %d\n ", malloc_info.ordblks);
printf("smblks= %d\n ", malloc_info.smblks);
printf("hblks= %d\n ", malloc_info.hblks);
printf("hblkhd= %d\n ", malloc_info.hblkhd);
printf("usmblks= %d\n ", malloc_info.usmblks);
printf("fsmblks= %d\n ", malloc_info.fsmblks);
printf("uordblks= %d\n ", malloc_info.uordblks);
printf("fordblks= %d\n ", malloc_info.fordblks);
printf("keepcost= %d\n ", malloc_info.keepcost);
}
void *
aint_malloc(size_t size)
{
caddr_t pointer;
if ( (pointer = mmap ((caddr_t) NULL, size,
PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_VARIABLE | MAP_PRIVATE,
-1, 0)) == (caddr_t) -1) {
perror("mmap");
fatal("aint_malloc - out of memory");
}
return pointer;
}