blob: b8e83cb852ee637760ed9734b210d66b336428c6 (
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
|
/* mem-mmap.c - mmap wrappings for large memory allocation
*
* Copyright (C) 2009 Timo Teräs <timo.teras@iki.fi>
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 or later as
* published by the Free Software Foundation.
*
* See http://www.gnu.org/ for details.
*/
#include <sys/mman.h>
#include <libtf/defines.h>
#include <libtf/memory.h>
void *tf_bmem_alloc(size_t size)
{
void *ptr;
ptr = mmap(NULL, size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
if (ptr == MAP_FAILED)
return NULL;
return ptr;
}
void *tf_bmem_resize(void *oldptr, size_t oldsize, size_t newsize)
{
void *ptr;
ptr = mremap(oldptr, oldsize, newsize, MREMAP_MAYMOVE);
if (ptr == MAP_FAILED)
return NULL;
return ptr;
}
void tf_bmem_free(void *ptr, size_t size)
{
munmap(ptr, size);
}
|