2 * Simple test of using an alternate buffer for the code.
14 # define MAP_ANON MAP_ANONYMOUS
15 # ifndef MAP_ANONYMOUS
16 # define MAP_ANONYMOUS 0
25 main(int argc, char *argv[])
33 void (*function)(void);
36 mmap_fd = open("/dev/zero", O_RDWR);
39 ptr = mmap(NULL, 1024 * 1024,
40 PROT_EXEC | PROT_READ | PROT_WRITE,
41 MAP_PRIVATE | MAP_ANON, mmap_fd, 0);
42 assert(ptr != MAP_FAILED);
48 _jit = jit_new_state();
52 jit_pushargi((jit_word_t)"%s\n");
54 jit_pushargi((jit_word_t)"ok");
57 /* call to jit_realize() is only required when using an alternate
58 * code buffer. Note that not using mmap'ed memory may not work
59 * on several ports and/or operating system versions */
63 if (jit_get_code(&length) != NULL)
69 /* check that a too small buffer fails */
71 function = jit_emit();
75 /* and calling again with enough space works */
76 jit_set_code(ptr, 1024 * 1024);
77 function = jit_emit();
86 munmap(ptr, 1024 * 1024);