From 4a71579b757d3a2eb6902c84391f429838ad4912 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Thu, 30 Jan 2020 12:33:44 -0300 Subject: git subrepo clone https://git.savannah.gnu.org/git/lightning.git deps/lightning subrepo: subdir: "deps/lightning" merged: "b0b8eb5" upstream: origin: "https://git.savannah.gnu.org/git/lightning.git" branch: "master" commit: "b0b8eb5" git-subrepo: version: "0.4.1" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "a04d8c2" --- deps/lightning/check/nodata.c | 106 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 deps/lightning/check/nodata.c (limited to 'deps/lightning/check/nodata.c') diff --git a/deps/lightning/check/nodata.c b/deps/lightning/check/nodata.c new file mode 100644 index 0000000..0e594c3 --- /dev/null +++ b/deps/lightning/check/nodata.c @@ -0,0 +1,106 @@ +/* + * Simple test of using an alternate buffer for the code. + */ + +#include +#include +#include +#include +#if defined(__sgi) +# include +#endif + +#ifndef MAP_ANON +# define MAP_ANON MAP_ANONYMOUS +# ifndef MAP_ANONYMOUS +# define MAP_ANONYMOUS 0 +# endif +#endif + +#if !defined(__sgi) +#define mmap_fd -1 +#endif + +jit_uint8_t *data; +jit_state_t *_jit; +jit_word_t data_length; +jit_word_t note_length; +#if defined(__sgi) +int mmap_fd; +#endif +void (*function)(void); + +void +gencode(jit_word_t flags) +{ + jit_word_t offset; + jit_word_t length; + + _jit = jit_new_state(); + + jit_name("main"); + jit_prolog(); + jit_prepare(); + jit_pushargi((jit_word_t)"%f\n"); + jit_ellipsis(); + jit_pushargi_d(1.5); + jit_finishi(printf); + jit_note("nodata.c", __LINE__); + + /* call to jit_realize() is only required when using an alternate + * code buffer. Note that not using mmap'ed memory may not work + * on several ports and/or operating system versions */ + jit_realize(); + + if (jit_get_data(&data_length, ¬e_length) != NULL) + abort(); + + length = 0; + if (!(flags & JIT_DISABLE_DATA)) + length += data_length; + if (!(flags & JIT_DISABLE_NOTE)) + length += note_length; + + /* check that a too small buffer fails */ + if (flags) + jit_set_data(length ? data : NULL, length, flags); + + /* and calling again with enough space works */ + offset = (length + 7) & -8; + function = jit_emit(); + if (function == NULL) + abort(); + + jit_clear_state(); + (*function)(); + jit_destroy_state(); +} + +int +main(int argc, char *argv[]) +{ +#if defined(__sgi) + mmap_fd = open("/dev/zero", O_RDWR); +#endif + + data = mmap(NULL, 4096, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANON, mmap_fd, 0); + assert(data != MAP_FAILED); +#if defined(__sgi) + close(mmap_fd); +#endif + + init_jit(argv[0]); + + gencode(0); + gencode(JIT_DISABLE_DATA); + gencode(JIT_DISABLE_NOTE); + gencode(JIT_DISABLE_DATA | JIT_DISABLE_NOTE); + + finish_jit(); + + munmap(data, 4096); + + return (0); +} -- cgit v1.2.3