blob: d590046cf7c76f68273e7301fcd1020ae2a1d0b8 (
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
53
54
|
#include "config.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <orc/orcprogram.h>
#define SIZE 65536
void
orc_program_allocate_codemem (OrcProgram *program)
{
char filename[32] = "/tmp/orcexecXXXXXX";
int fd;
fd = mkstemp (filename);
if (fd == -1) {
/* FIXME oh crap */
printf("failed to create temp file\n");
program->error = TRUE;
return;
}
unlink (filename);
ftruncate (fd, SIZE);
program->code = mmap (NULL, SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (program->code == MAP_FAILED) {
/* FIXME oh crap */
printf("failed to create write map\n");
program->error = TRUE;
return;
}
program->code_exec = mmap (NULL, SIZE, PROT_READ|PROT_EXEC, MAP_SHARED, fd, 0);
if (program->code_exec == MAP_FAILED) {
/* FIXME oh crap */
printf("failed to create exec map\n");
program->error = TRUE;
return;
}
close (fd);
program->code_size = SIZE;
program->codeptr = program->code;
}
|