aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCruX <crux@project-insanity.org>2020-11-29 13:46:22 +0100
committerCruX <crux@project-insanity.org>2021-08-24 19:18:02 +0200
commitf5398e488886f111648dd0d69b67ccfab3e225d1 (patch)
tree0ad7beea74db880febfdabea4f37a120336275f9
parentf3b23bccaf6cac71aa3ca25279184d3f48a2e68a (diff)
downloadrspamd-f5398e488886f111648dd0d69b67ccfab3e225d1.tar.gz
rspamd-f5398e488886f111648dd0d69b67ccfab3e225d1.zip
[Fix] Remove aarch64 GC64 workaround
luajit contains full support for lightuserdata on aarch64 in newest 2.1 versions
-rw-r--r--contrib/lua-lpeg/lptree.c19
-rw-r--r--contrib/lua-lpeg/lptypes.h10
-rw-r--r--contrib/lua-lpeg/lpvm.c115
3 files changed, 0 insertions, 144 deletions
diff --git a/contrib/lua-lpeg/lptree.c b/contrib/lua-lpeg/lptree.c
index 4920f8f89..df24e3c9c 100644
--- a/contrib/lua-lpeg/lptree.c
+++ b/contrib/lua-lpeg/lptree.c
@@ -1149,11 +1149,7 @@ static size_t initposition (lua_State *L, size_t len) {
** Main match function
*/
static int lp_match (lua_State *L) {
-#ifdef LPEG_LUD_WORKAROUND
- Capture *capture = lpeg_allocate_mem_low(sizeof(Capture) * INITCAPSIZE);
-#else
Capture capture[INITCAPSIZE];
-#endif
const char *r;
size_t l;
const char *s;
@@ -1167,9 +1163,6 @@ static int lp_match (lua_State *L) {
else if (lua_type (L, SUBJIDX) == LUA_TUSERDATA) {
struct rspamd_lua_text *t = lua_check_text (L, SUBJIDX);
if (!t) {
-#ifdef LPEG_LUD_WORKAROUND
- lpeg_free_mem_low (capture);
-#endif
return luaL_error (L, "invalid argument (not a text)");
}
s = t->start;
@@ -1177,16 +1170,10 @@ static int lp_match (lua_State *L) {
if (s == NULL) {
lua_pushnil(L);
-#ifdef LPEG_LUD_WORKAROUND
- lpeg_free_mem_low (capture);
-#endif
return 1;
}
}
else {
-#ifdef LPEG_LUD_WORKAROUND
- lpeg_free_mem_low (capture);
-#endif
return luaL_error (L, "invalid argument: %s",
lua_typename (L, lua_type (L, SUBJIDX)));
}
@@ -1198,15 +1185,9 @@ static int lp_match (lua_State *L) {
r = match(L, s, s + i, s + l, code, capture, ptop);
if (r == NULL) {
lua_pushnil(L);
-#ifdef LPEG_LUD_WORKAROUND
- lpeg_free_mem_low (capture);
-#endif
return 1;
}
rs = getcaptures(L, s, r, ptop);
-#ifdef LPEG_LUD_WORKAROUND
- lpeg_free_mem_low (capture);
-#endif
return rs;
}
diff --git a/contrib/lua-lpeg/lptypes.h b/contrib/lua-lpeg/lptypes.h
index 5748c8560..f541c7af5 100644
--- a/contrib/lua-lpeg/lptypes.h
+++ b/contrib/lua-lpeg/lptypes.h
@@ -9,15 +9,12 @@
#define lptypes_h
-#include "config.h"
-
#if !defined(LPEG_DEBUG) && !defined(NDEBUG)
#define NDEBUG
#endif
#include <assert.h>
#include <limits.h>
-#include <stdint.h>
#include "lua.h"
@@ -152,13 +149,6 @@ typedef struct Charset {
#define testchar(st,c) (((int)(st)[((c) >> 3)] & (1 << ((c) & 7))))
-/* Special workaround for luajit lightuserdata limitations with GC64 */
-#if defined(WITH_LUAJIT) && INTPTR_MAX == INT64_MAX && \
- !(defined(_X86_) || defined(__x86_64__) || defined(__i386__) || defined(__powerpc__))
-# define LPEG_LUD_WORKAROUND 1
-void * lpeg_allocate_mem_low(size_t sz);
-void lpeg_free_mem_low(void *p);
-#endif
#endif
diff --git a/contrib/lua-lpeg/lpvm.c b/contrib/lua-lpeg/lpvm.c
index 7ee8b695a..0dfca18af 100644
--- a/contrib/lua-lpeg/lpvm.c
+++ b/contrib/lua-lpeg/lpvm.c
@@ -17,111 +17,6 @@
#include "lpvm.h"
#include "lpprint.h"
-#ifdef LPEG_LUD_WORKAROUND
-#include <sys/mman.h>
-
-#define MAX_PIECES (1u << 2u)
-
-/* 64 bytes, 1 cache line */
-struct poor_slab {
- struct slab_piece {
- unsigned char *ptr;
- uint32_t sz;
- uint32_t occupied;
- } pieces[MAX_PIECES];
-};
-
-/* Used to optimize pages allocation */
-RSPAMD_ALIGNED (64) struct poor_slab slabs;
-
-static uint64_t xorshifto_seed[2] = {0xdeadbabe, 0xdeadbeef};
-
-static inline uint64_t
-xoroshiro_rotl (const uint64_t x, int k) {
- return (x << k) | (x >> (64 - k));
-}
-
-void *
-lpeg_allocate_mem_low (size_t sz)
-{
- unsigned char *cp;
- unsigned flags = MAP_PRIVATE | MAP_ANON;
- void *base_addr = NULL;
-
- /* Check slabs */
- for (unsigned i = 0; i < MAX_PIECES; i ++) {
- if (!slabs.pieces[i].occupied && slabs.pieces[i].sz == sz) {
- /* Reuse, short path */
- slabs.pieces[i].occupied = 1;
- return slabs.pieces[i].ptr + sizeof (size_t);
- }
- }
-
-#ifdef MAP_32BIT
- flags |= MAP_32BIT;
-#else
- const uint64_t s0 = xorshifto_seed[0];
- uint64_t s1 = xorshifto_seed[1];
-
- s1 ^= s0;
- xorshifto_seed[0] = xoroshiro_rotl (s0, 55) ^ s1 ^ (s1 << 14);
- xorshifto_seed[1] = xoroshiro_rotl (s1, 36);
- flags |= MAP_FIXED;
- /* Get 46 bits */
- base_addr = (void *)((xorshifto_seed[0] + xorshifto_seed[1]) & 0x7FFFFFFFF000ULL);
-#endif
-
- cp = mmap (base_addr, sz + sizeof (sz), PROT_WRITE | PROT_READ,
- flags, -1, 0);
- assert (cp != MAP_FAILED);
- memcpy (cp, &sz, sizeof (sz));
-
- for (unsigned i = 0; i < MAX_PIECES; i ++) {
- if (slabs.pieces[i].occupied == 0) {
- /* Store piece */
- slabs.pieces[i].sz = sz;
- slabs.pieces[i].ptr = cp;
- slabs.pieces[i].occupied = 1;
-
- return cp + sizeof (sz);
- }
- }
-
- /* Not enough free pieces, pop some */
- unsigned sel = ((uintptr_t)cp) & ((MAX_PIECES * 2) - 1);
- /* Here we free memory in fact */
- munmap (slabs.pieces[sel].ptr, slabs.pieces[sel].sz + sizeof (sz));
- slabs.pieces[sel].sz = sz;
- slabs.pieces[sel].ptr = cp;
- slabs.pieces[sel].occupied = 1;
-
- return cp + sizeof (sz);
-}
-
-void
-lpeg_free_mem_low(void *p)
-{
- unsigned char *cp = (unsigned char *)p;
- size_t sz;
-
- /* Base address */
- cp -= sizeof (sz);
- memcpy (&sz, cp, sizeof (sz));
-
- for (unsigned i = 0; i < MAX_PIECES; i ++) {
- if (slabs.pieces[i].occupied && slabs.pieces[i].ptr == cp) {
- /* Return back */
- slabs.pieces[i].occupied = 0;
-
- return;
- }
- }
-
- /* No match, unmapped by allocation */
-}
-
-#endif
-
/* initial size for call/backtrack stack */
#if !defined(INITBACK)
#define INITBACK MAXBACK
@@ -265,11 +160,7 @@ static int removedyncap (lua_State *L, Capture *capture,
*/
const char *match (lua_State *L, const char *o, const char *s, const char *e,
Instruction *op, Capture *capture, int ptop) {
-#ifdef LPEG_LUD_WORKAROUND
- Stack *stackbase = lpeg_allocate_mem_low(sizeof (Stack) * INITBACK);
-#else
Stack stackbase[INITBACK];
-#endif
Stack *stacklimit = stackbase + INITBACK;
Stack *stack = stackbase; /* point to first empty slot in stack */
int capsize = INITCAPSIZE;
@@ -290,16 +181,10 @@ const char *match (lua_State *L, const char *o, const char *s, const char *e,
assert(stack == getstackbase(L, ptop) + 1);
capture[captop].kind = Cclose;
capture[captop].s = NULL;
-#ifdef LPEG_LUD_WORKAROUND
- lpeg_free_mem_low(stackbase);
-#endif
return s;
}
case IGiveup: {
assert(stack == getstackbase(L, ptop));
-#ifdef LPEG_LUD_WORKAROUND
- lpeg_free_mem_low(stackbase);
-#endif
return NULL;
}
case IRet: {