-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxmalloc.c
64 lines (57 loc) · 1.07 KB
/
xmalloc.c
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
54
55
56
57
58
59
60
61
62
63
64
#include <stdlib.h>
#include <stdio.h>
#include <sys/mman.h>
#include "defs.h"
MTA("mta inline")
void *
xmalloc (size_t size)
{
void * out;
if ( (out = malloc (size)) ) return out;
perror ("malloc failed");
abort ();
return NULL;
}
MTA("mta inline")
void *
xcalloc (size_t nmemb, size_t size)
{
void * out;
if ( (out = calloc (nmemb, size)) ) return out;
perror ("calloc failed");
abort ();
return NULL;
}
MTA("mta inline")
void *
xrealloc (void *ptr, size_t size)
{
void * out;
if ( (out = realloc (ptr, size)) ) return out;
perror ("realloc failed");
abort ();
return NULL;
}
MTA("mta inline")
void *
xmmap (void *addr, size_t len, int64_t prot, int64_t flags, int64_t fd, off_t offset)
{
void * out;
out = mmap (addr, len, prot, flags, fd, offset);
if (MAP_FAILED != out) return out;
perror ("mmap failed");
abort ();
return NULL;
}
void *
xmmap_alloc (size_t sz)
{
//return xmmap (NULL, sz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, 0, 0);
return xmalloc (sz);
}
void
xmunmap (void * p, size_t sz)
{
//munmap (p, sz);
free (p);
}