forked from simonster/binica
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemap.c
executable file
·51 lines (40 loc) · 1.58 KB
/
memap.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
/******************************************************************************/
/* For all support and information please contact: */
/* */
/* Sigurd Enghoff */
/* The Salk Institute, CNL */
/* [email protected] */
/* */
/* Additional ICA software: */
/* http://www.cnl.salk.edu/~enghoff/ */
/* */
/******************************************************************************/
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stddef.h>
#include <stdio.h>
#ifndef ALPHA
void *mapmalloc(int size) {
int fd, i;
caddr_t base;
char dummy = 0;
/*fd = open(tmpnam(NULL),O_RDWR|O_CREAT|O_EXCL);
for (i=0 ; i<size ; i++) write(fd,&dummy,1);
lseek(fd,SEEK_SET,0);*/
fd = open("/dev/zero",O_RDWR);
base = mmap(NULL,(size_t)(size),PROT_READ|PROT_WRITE,MAP_PRIVATE,fd,0);
close(fd);
return (void*)base;
}
#else
void *mapmalloc(int size) {
caddr_t base;
base = mmap(NULL,(size_t)(size),PROT_READ|PROT_WRITE,MAP_ANONYMOUS|MAP_VARIABLE,-1,0);
return (void*)base;
}
#endif
void mapfree(void *addr, int size) {
munmap((caddr_t)addr,size);
}