diff options
author | zherczeg <zherczeg@6239d852-aaf2-0410-a92c-79f79f948069> | 2017-01-12 09:32:15 +0000 |
---|---|---|
committer | zherczeg <zherczeg@6239d852-aaf2-0410-a92c-79f79f948069> | 2017-01-12 09:32:15 +0000 |
commit | 2b037a178100bba0581eef40a6f7c54f13eec4c1 (patch) | |
tree | 20af8e4ede64e255a4918ec30beda8e4cec9be02 /src/sljit | |
parent | c44fe1c63529ec70ff9c28a844795063eaef1ec9 (diff) | |
download | pcre2-2b037a178100bba0581eef40a6f7c54f13eec4c1.tar.gz |
JIT compiler update. Patch insipred by Christian Persch.
git-svn-id: svn://vcs.exim.org/pcre2/code/trunk@652 6239d852-aaf2-0410-a92c-79f79f948069
Diffstat (limited to 'src/sljit')
-rw-r--r-- | src/sljit/sljitConfigInternal.h | 8 | ||||
-rw-r--r-- | src/sljit/sljitLir.c | 8 | ||||
-rw-r--r-- | src/sljit/sljitProtExecAllocator.c | 90 |
3 files changed, 88 insertions, 18 deletions
diff --git a/src/sljit/sljitConfigInternal.h b/src/sljit/sljitConfigInternal.h index 6651c1e..5d46101 100644 --- a/src/sljit/sljitConfigInternal.h +++ b/src/sljit/sljitConfigInternal.h @@ -187,14 +187,6 @@ /* External function definitions. */ /**********************************/ -#if !(defined SLJIT_STD_MACROS_DEFINED && SLJIT_STD_MACROS_DEFINED) - -/* These libraries are needed for the macros below. */ -#include <stdlib.h> -#include <string.h> - -#endif /* SLJIT_STD_MACROS_DEFINED */ - /* General macros: Note: SLJIT is designed to be independent from them as possible. diff --git a/src/sljit/sljitLir.c b/src/sljit/sljitLir.c index 6b3f4eb..0b39ec9 100644 --- a/src/sljit/sljitLir.c +++ b/src/sljit/sljitLir.c @@ -26,6 +26,14 @@ #include "sljitLir.h" +#if !(defined SLJIT_STD_MACROS_DEFINED && SLJIT_STD_MACROS_DEFINED) + +/* These libraries are needed for the macros below. */ +#include <stdlib.h> +#include <string.h> + +#endif /* SLJIT_STD_MACROS_DEFINED */ + #define CHECK_ERROR() \ do { \ if (SLJIT_UNLIKELY(compiler->error)) \ diff --git a/src/sljit/sljitProtExecAllocator.c b/src/sljit/sljitProtExecAllocator.c index a9343f1..197dbc7 100644 --- a/src/sljit/sljitProtExecAllocator.c +++ b/src/sljit/sljitProtExecAllocator.c @@ -84,26 +84,96 @@ struct chunk_header { as it only uses local variables */ -#ifndef _XOPEN_SOURCE -#define _XOPEN_SOURCE 500 /* for mkstemp() and truncate() */ +#include <fcntl.h> + +#ifndef O_NOATIME +#define O_NOATIME 0 #endif -static SLJIT_INLINE struct chunk_header* alloc_chunk(sljit_uw size) +#ifdef __O_TMPFILE +#ifndef O_TMPFILE +#define O_TMPFILE (__O_TMPFILE | O_DIRECTORY) +#endif +#endif + +int mkostemp(char *template, int flags); +char *secure_getenv(const char *name); + +static SLJIT_INLINE int create_tempfile(void) { - struct chunk_header *retval; - char template[] = "/tmp/XXXXXX"; int fd; - fd = mkstemp(template); - if (fd == -1) { - return NULL; + char tmp_name[256]; + size_t tmp_name_len; + char *dir; + size_t len; + +#ifdef P_tmpdir + len = (P_tmpdir != NULL) ? strlen(P_tmpdir) : 0; + + if (len > 0 && len < sizeof(tmp_name)) { + strcpy(tmp_name, P_tmpdir); + tmp_name_len = len; + } + else { + strcpy(tmp_name, "/tmp"); + tmp_name_len = 4; } +#else + strcpy(tmp_name, "/tmp"); + tmp_name_len = 4; +#endif - if (unlink(template)) { + dir = secure_getenv("TMPDIR"); + if (dir) { + len = strlen(dir); + if (len > 0 && len < sizeof(tmp_name)) { + strcpy(tmp_name, dir); + tmp_name_len = len; + } + } + + SLJIT_ASSERT(tmp_name_len > 0 && tmp_name_len < sizeof(tmp_name)); + + while (tmp_name_len > 0 && tmp_name[tmp_name_len - 1] == '/') { + tmp_name_len--; + tmp_name[tmp_name_len] = '\0'; + } + +#ifdef O_TMPFILE + fd = open(tmp_name, O_TMPFILE | O_EXCL | O_RDWR | O_NOATIME | O_CLOEXEC, S_IRUSR | S_IWUSR); + if (fd != -1) + return fd; +#endif + + if (tmp_name_len + 7 >= sizeof(tmp_name)) + { + return -1; + } + + strcpy(tmp_name + tmp_name_len, "/XXXXXX"); + fd = mkostemp(tmp_name, O_CLOEXEC | O_NOATIME); + + if (fd == -1) + return fd; + + if (unlink(tmp_name)) { close(fd); - return NULL; + return -1; } + return fd; +} + +static SLJIT_INLINE struct chunk_header* alloc_chunk(sljit_uw size) +{ + struct chunk_header *retval; + int fd; + + fd = create_tempfile(); + if (fd == -1) + return NULL; + if (ftruncate(fd, size)) { close(fd); return NULL; |