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
26 jit_word_t data_length;
27 jit_word_t note_length;
31 void (*function)(void);
34 gencode(jit_word_t flags)
39 _jit = jit_new_state();
44 jit_pushargi((jit_word_t)"%f\n");
48 jit_note("nodata.c", __LINE__);
50 /* call to jit_realize() is only required when using an alternate
51 * code buffer. Note that not using mmap'ed memory may not work
52 * on several ports and/or operating system versions */
55 if (jit_get_data(&data_length, ¬e_length) != NULL)
59 if (!(flags & JIT_DISABLE_DATA))
60 length += data_length;
61 if (!(flags & JIT_DISABLE_NOTE))
62 length += note_length;
64 /* check that a too small buffer fails */
66 jit_set_data(length ? data : NULL, length, flags);
68 /* and calling again with enough space works */
69 offset = (length + 7) & -8;
70 function = jit_emit();
80 main(int argc, char *argv[])
83 mmap_fd = open("/dev/zero", O_RDWR);
86 data = mmap(NULL, 4096,
87 PROT_READ | PROT_WRITE,
88 MAP_PRIVATE | MAP_ANON, mmap_fd, 0);
89 assert(data != MAP_FAILED);
97 gencode(JIT_DISABLE_DATA);
98 gencode(JIT_DISABLE_NOTE);
99 gencode(JIT_DISABLE_DATA | JIT_DISABLE_NOTE);